feat: run FastAPI under gunicorn with uvicorn ASGI workers
Production entrypoint switch:
- pyproject.toml: add gunicorn>=23.0 dep
- gunicorn.conf.py: env-var-driven config (bind, workers, threads,
timeout, graceful_timeout, keepalive, log level, access-log format)
- Dockerfile: CMD gunicorn main:app (auto-loads gunicorn.conf.py from
WORKDIR /app)
- docker-compose.yml: forward GUNICORN_WORKERS / GUNICORN_TIMEOUT /
GUNICORN_BIND
- .env.example: document the new tunables
Why gunicorn over standalone uvicorn for production:
- Process supervision: master restarts crashed workers, restarts on
memory leaks
- Graceful shutdown: SIGTERM drains workers in-flight
- Multi-worker: concurrent requests actually run in parallel
- Standard ops: k8s readiness probes, log aggregators, etc. all know
gunicorn
Why uvicorn workers (not sync workers): gunicorn can't natively serve
ASGI; uvicorn.workers.UvicornWorker is the canonical way to run an
ASGI app under gunicorn.
Defaults:
- 2 workers (small MCP service; raise for high concurrency)
- 1 thread per worker (no blocking I/O)
- 120s timeout (yarn logs can be slow; uvicorn's 30s default is too
tight)
Verified: gunicorn boots, lifespan runs (14 tools logged), MCP
initialize + tools/list + tools/call all work, /openapi.json = 200,
multiple gunicorn worker processes visible in ps.
uv sync picked up gunicorn 26.0.0. Tests still 116/116.
This commit is contained in:
@@ -13,3 +13,11 @@ YARN_RESOURCE_MANAGER_URL=
|
||||
# Optional: JVM flags forwarded to spark-submit. Useful for proxies, custom
|
||||
# truststores, or driver memory caps.
|
||||
# SPARK_SUBMIT_OPTS=-Dhttps.proxyHost=proxy.corp -Dhttps.proxyPort=3128
|
||||
|
||||
# Gunicorn process model (see gunicorn.conf.py). Defaults shown.
|
||||
# GUNICORN_WORKERS=2
|
||||
# GUNICORN_THREADS=1
|
||||
# GUNICORN_TIMEOUT=120 # generous; yarn logs can be slow
|
||||
# GUNICORN_GRACEFUL_TIMEOUT=30
|
||||
# GUNICORN_KEEPALIVE=5
|
||||
# GUNICORN_BIND=0.0.0.0:8000
|
||||
|
||||
Reference in New Issue
Block a user