Container & RAM Tuning
Bounding Dify Redis Memory With maxmemory & allkeys-lru
Configure Redis memory limits cleanly so Celery task queues and SSE pub/sub channels stay fast without unbounded key growth.
256-1,024 MB Cap · allkeys-lru · Persistence Safety
Dual Role of Redis in Dify
Redis serves simultaneously as the Celery task broker, result backend, rate-limiter store, and real-time workflow event pub/sub bus. Setting maxmemory with allkeys-lru prevents stale cached objects from crowding out Postgres HNSW pages.
Avoiding Swap Spikes During BGSAVE
Keep at least 2x Redis maxmemory free in host RAM if RDB snapshots are enabled, because Redis fork() duplicates dirty pages identically to Postgres checkpoints.
Measured Thresholds & Container Limits
| Workload Profile | Redis maxmemory | Eviction Policy |
|---|---|---|
| 1k - 35k chunks (KVM 2) | 256mb | allkeys-lru |
| 35k - 140k chunks (KVM 4) | 512mb | allkeys-lru |
| 150k - 250k chunks (KVM 8) | 1024mb | allkeys-lru |