Add multiple Uvicorn processes to prevent backend freezing.
Build and Push CodeReview / build (push) Waiting to run Details

This commit is contained in:
vinland100 2026-01-08 17:00:13 +08:00
parent 5166027e2f
commit 044cd11ad4
4 changed files with 27 additions and 5 deletions

View File

@ -48,6 +48,13 @@ echo "📦 执行数据库迁移..."
echo "✅ 数据库迁移完成" echo "✅ 数据库迁移完成"
# 启动 uvicorn # 启动 gunicorn (多工作进程模式)
echo "🌐 启动 API 服务..." # 默认开启 4 个 worker显著提高并发处理能力
exec .venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000 echo "🌐 启动 API 服务 (Gunicorn + 4 Workers)..."
exec .venv/bin/gunicorn app.main:app \
--workers 4 \
--worker-class uvicorn.workers.UvicornWorker \
--bind 0.0.0.0:8000 \
--timeout 120 \
--access-logfile - \
--error-logfile -

View File

@ -14,6 +14,7 @@ dependencies = [
# ============ Web Framework ============ # ============ Web Framework ============
"fastapi>=0.100.0", "fastapi>=0.100.0",
"uvicorn[standard]>=0.23.0", "uvicorn[standard]>=0.23.0",
"gunicorn>=21.2.0",
"sse-starlette>=1.8.2", "sse-starlette>=1.8.2",
# ============ Database ============ # ============ Database ============

View File

@ -1023,6 +1023,7 @@ dependencies = [
{ name = "esprima" }, { name = "esprima" },
{ name = "fastapi" }, { name = "fastapi" },
{ name = "greenlet" }, { name = "greenlet" },
{ name = "gunicorn" },
{ name = "httpx" }, { name = "httpx" },
{ name = "jinja2" }, { name = "jinja2" },
{ name = "jsbeautifier" }, { name = "jsbeautifier" },
@ -1102,6 +1103,7 @@ requires-dist = [
{ name = "esprima", specifier = ">=4.0.1" }, { name = "esprima", specifier = ">=4.0.1" },
{ name = "fastapi", specifier = ">=0.100.0" }, { name = "fastapi", specifier = ">=0.100.0" },
{ name = "greenlet", specifier = ">=3.0.0" }, { name = "greenlet", specifier = ">=3.0.0" },
{ name = "gunicorn", specifier = ">=21.2.0" },
{ name = "httpx", specifier = ">=0.25.0" }, { name = "httpx", specifier = ">=0.25.0" },
{ name = "jinja2", specifier = ">=3.1.6" }, { name = "jinja2", specifier = ">=3.1.6" },
{ name = "jsbeautifier", specifier = ">=1.14.0" }, { name = "jsbeautifier", specifier = ">=1.14.0" },
@ -1748,6 +1750,18 @@ wheels = [
{ url = "https://mirrors.ustc.edu.cn/pypi/packages/19/41/0b430b01a2eb38ee887f88c1f07644a1df8e289353b78e82b37ef988fb64/grpcio-1.76.0-cp314-cp314-win_amd64.whl", hash = "sha256:922fa70ba549fce362d2e2871ab542082d66e2aaf0c19480ea453905b01f384e", size = 4834462, upload-time = "2025-10-21T16:22:39.772Z" }, { url = "https://mirrors.ustc.edu.cn/pypi/packages/19/41/0b430b01a2eb38ee887f88c1f07644a1df8e289353b78e82b37ef988fb64/grpcio-1.76.0-cp314-cp314-win_amd64.whl", hash = "sha256:922fa70ba549fce362d2e2871ab542082d66e2aaf0c19480ea453905b01f384e", size = 4834462, upload-time = "2025-10-21T16:22:39.772Z" },
] ]
[[package]]
name = "gunicorn"
version = "23.0.0"
source = { registry = "https://mirrors.ustc.edu.cn/pypi/simple" }
dependencies = [
{ name = "packaging" },
]
sdist = { url = "https://mirrors.ustc.edu.cn/pypi/packages/34/72/9614c465dc206155d93eff0ca20d42e1e35afc533971379482de953521a4/gunicorn-23.0.0.tar.gz", hash = "sha256:f014447a0101dc57e294f6c18ca6b40227a4c90e9bdb586042628030cba004ec", size = 375031, upload-time = "2024-08-10T20:25:27.378Z" }
wheels = [
{ url = "https://mirrors.ustc.edu.cn/pypi/packages/cb/7d/6dac2a6e1eba33ee43f318edbed4ff29151a49b5d37f080aad1e6469bca4/gunicorn-23.0.0-py3-none-any.whl", hash = "sha256:ec400d38950de4dfd418cff8328b2c8faed0edb0d517d3394e457c317908ca4d", size = 85029, upload-time = "2024-08-10T20:25:24.996Z" },
]
[[package]] [[package]]
name = "h11" name = "h11"
version = "0.16.0" version = "0.16.0"

View File

@ -67,8 +67,8 @@ services:
condition: service_healthy condition: service_healthy
redis: redis:
condition: service_healthy condition: service_healthy
# 开发模式下,可以启用 --reload 热重载 # 使用启动脚本自动执行数据库迁移并启动 Gunicorn
command: sh -c ".venv/bin/alembic upgrade head && .venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8000" command: ["/app/docker-entrypoint.sh"]
networks: networks:
- deepaudit-network - deepaudit-network