Agent Wranglers

SCL-14Required

Cap the cache server's memory and choose its eviction

Set a memory limit and an eviction policy on every cache server. Keep data that must not be evicted, such as job queues, in a separate instance that never evicts.

How to do it

Redis and Valkey set no memory limit by default on 64-bit systems, so a cache grows until the machine runs out. Set maxmemory below the instance's memory, and leave room for replication buffers. For a pure cache, the Redis docs call allkeys-lru a good default. A queue needs noeviction, which makes writes fail instead of dropping jobs. So a queue and a cache cannot share one policy, and both projects advise two instances. Alert on memory as Warn before resources run out says.

Examples

Plain text example

# cache.conf for a 2 GB cache instance
maxmemory 1600mb
maxmemory-policy allkeys-lru

# queue.conf for the job queue instance
maxmemory 1600mb
maxmemory-policy noeviction

How to check

CONFIG GET maxmemory returns a value above 0 on every instance. Cache instances use an allkeys- policy, and queue instances use noeviction. No instance holds both caches and queues.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/scaling/caching/cache-memory-and-eviction">Agent Wranglers scaling playbook</a>. In code you write, add a comment next to it with the same link.