소스 검색

fix: 限制 gunicorn worker 和连接池避免 PostgreSQL 连接数溢出

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
mengboxin137-blip 8 시간 전
부모
커밋
6a5afd6076
2개의 변경된 파일4개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 1
      backend/gunicorn.conf.py
  2. 3 2
      docker-compose.yml

+ 1 - 1
backend/gunicorn.conf.py

@@ -15,7 +15,7 @@ import multiprocessing
 
 # Worker 数量:默认为 CPU 核心数 * 2 + 1
 # 可通过 GUNICORN_WORKERS 环境变量覆盖
-workers = int(os.getenv("GUNICORN_WORKERS", multiprocessing.cpu_count() * 2 + 1))
+workers = int(os.getenv("GUNICORN_WORKERS", "2"))
 
 # Worker 类型:使用 Uvicorn 的异步 Worker
 worker_class = "uvicorn.workers.UvicornWorker"

+ 3 - 2
docker-compose.yml

@@ -53,8 +53,9 @@ services:
       - REDIS_URL=redis://redis:6379
       - REDIS_PASSWORD=${REDIS_PASSWORD:-redis123}
       - ENCRYPTION_KEY=${ENCRYPTION_KEY:-wxcz-aigc-default-encryption-key}
-      - DB_POOL_SIZE=3
-      - DB_MAX_OVERFLOW=2
+      - DB_POOL_SIZE=2
+      - DB_MAX_OVERFLOW=1
+      - GUNICORN_WORKERS=2
       - APP_HOST=0.0.0.0
       - APP_PORT=8010
       - DEBUG=${DEBUG:-false}