Container & RAM Tuning
Fixing Dify Celery Worker RAM Spikes & OOM Kills
Control CELERY_WORKER_AMOUNT and gevent concurrency so batch PDF/DOCX extraction never multiplies RSS past host RAM.
420-650 MB / Worker · gevent Pool · Safe Autoscale Caps
Why Default Celery Unbounded Forks Crash 8 GB VPS Nodes
Each Dify Celery worker loads Python NLP tokenizers, Unstructured/PDF parsers, and embedding client libraries into resident memory (~420-650 MB per process). Spawning 8+ workers during bulk knowledge-base uploads instantly triggers the Linux OOM killer on 8 GB hosts.
Autoscale Bounds in .env
Set CELERY_AUTO_SCALE=true alongside explicit CELERY_MIN_WORKERS and CELERY_MAX_WORKERS matching your VPS tier, and wrap the worker service in a Docker deploy.resources.limits.memory cap.
Measured Thresholds & Container Limits
| Host VPS RAM | Safe CELERY_WORKER_AMOUNT | Worker Container Limit |
|---|---|---|
| 8 GB (KVM 2) | 2 workers | 1,536M - 2,048M |
| 16 GB (KVM 4) | 4 - 6 workers | 3,072M - 4,096M |
| 32 GB (KVM 8) | 8 - 12 workers | 6,144M - 8,192M |