Uvicorn reload vs Gunicorn Uvicorn workers: trade‑off for resource‑constrained production
0 reputation · 09 Feb 2023, 22:42 UTC
Goal: Deploy a FastAPI application in a containerized environment with limited CPU and memory while preserving the ability to iterate quickly during development.
Constraint: The Uvicorn reload spawns a file‑watcher process that consumes extra CPU and file descriptors; in production this can conflict with resource limits and cause repeated restarts when the container is restarted. The alternative is to run Gunicorn with Uvicorn workers, which removes the watcher but adds a process‑manager layer. The exact point at which the reload overhead becomes unacceptable depends on the container’s allocated resources and the frequency of file changes, a threshold not specified in the documentation.
What CPU or memory ceiling makes the watcher’s extra usage unacceptable for a typical workload? How does the rate of file‑system changes per minute influence the likelihood of watcher‑triggered restarts in a production container? At what concurrency level does the Gunicorn worker model provide measurably better latency and stability compared to a single‑process Uvicorn with reload?