提高内存进程使用

This commit is contained in:
lhx
2025-11-29 16:02:57 +08:00
parent ae476256a9
commit dd73a4518b
2 changed files with 25 additions and 3 deletions

View File

@@ -29,5 +29,8 @@ RUN mkdir -p /app/logs && chmod 755 /app/logs
# 暴露端口
EXPOSE 8000
# 启动命令,启用详细日志
CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--access-log", "--log-level", "info"]
# 安装gunicorn
RUN pip install --no-cache-dir gunicorn==21.2.0
# 启动命令使用gunicorn4个workers
CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--timeout", "120", "--keepalive", "5"]

View File

@@ -15,3 +15,22 @@ services:
# 配置文件映射
- ./.env:/app/.env:ro
restart: unless-stopped
# 资源限制
deploy:
resources:
limits:
# 内存限制8GB充分利用94GB内存
memory: 10G
# CPU限制12个CPU核心32核心服务器使用约1/3
cpus: '12.0'
reservations:
# 预留内存2GB
memory: 2G
# 预留CPU4个核心
cpus: '4.0'
# 环境变量
environment:
# 生产模式
- APP_DEBUG=false