Dify Stack Presets
High-Concurrency SSE Chatflow API & Nginx Streaming Preset
Tune Gunicorn gevent workers, Nginx proxy buffering, and Redis pub/sub for 100-200 simultaneous streaming chatflow users.
200 Concurrent SSE · 8-10 Gunicorn Gevent · Redis LRU
Memory Cost of Open SSE Connections
Sync Gunicorn workers block an entire 350 MB Python process for every streaming LLM response. Using SERVER_WORKER_CLASS=gevent lets each worker multiplex dozens of open SSE sockets while keeping api memory predictable.
Redis Pub/Sub Headroom
Ensure Redis maxmemory is explicitly capped (for example 512 MB to 1 GB) with allkeys-lru so stale chat state never leaks into host swap.
Measured Thresholds & Container Limits
| Container / Variable | Tuned Value | Purpose |
|---|---|---|
| SERVER_WORKER_CLASS | gevent | Non-blocking greenlets for long-lived SSE |
| SERVER_WORKER_AMOUNT | 8 - 10 workers | Handles 150-200 concurrent token streams |
| NGINX proxy_buffering | off (SSE) | Immediate first-token delivery to browser |
| Redis maxmemory-policy | allkeys-lru | Bounds session cache growth under traffic spikes |