Container & RAM Tuning
Tuning Dify Flask/Gunicorn API Workers for SSE Chatflows
Balance SERVER_WORKER_AMOUNT against available RAM so 50-200 concurrent SSE streaming users never exhaust memory.
~310 MB / Gunicorn Worker · gevent SSE Multiplexing
Gevent Greenlets vs Process Forking
Each Gunicorn worker process consumes ~310 to 400 MB baseline. Using SERVER_WORKER_CLASS=gevent lets a single worker sustain dozens of idle-waiting LLM upstream HTTP streams concurrently rather than scaling worker processes 1:1 with users.
Matching Workers to vCPU Count
Keep SERVER_WORKER_AMOUNT between 1x and 1.5x physical vCPU count on KVM nodes to avoid context-switch overhead while Celery ingestion is also active.
Measured Thresholds & Container Limits
| Concurrent Chatflows | SERVER_WORKER_AMOUNT | api Container Limit |
|---|---|---|
| 5 - 25 runs | 2 gevent workers | 1,280M |
| 30 - 80 runs | 4 - 6 gevent workers | 2,560M |
| 100 - 200 runs | 8 - 10 gevent workers | 4,608M |