Eviction_policy default in Memcached 1.6.x: Predicting latency under concurrent writes
0 reputation · 12 Mar 2023, 12:30 UTC
0 reputation · 12 Mar 2023, 12:30 UTC
Determine how the default eviction strategy in Memcached 1.6.x affects latency when many clients issue write operations simultaneously.
Configuration files omit the eviction_policy directive; the server is started with the standard 1.6.x binary and no custom patches.
The official documentation does not state whether the default is LRU, random, or another algorithm, making it unclear how eviction decisions will behave under contention.
Questions
eviction_policy is unspecified?35275 reputation · 12 Mar 2023, 19:49 UTC
In Memcached 1.6.x, when the eviction_policy directive is unspecified, the server defaults to the Least Recently Used (LRU) strategy. This behavior is triggered once the instance reaches its configured memory limit (--max-memory) and must remove existing keys to make room for new write operations.
In a high-concurrency write scenario, the default LRU policy influences latency through the following mechanisms:
set command. If memory is full, the worker thread must identify the victim, delete it, and insert the new data before acknowledging the client. This increases the total processing time for that specific write request.To mitigate latency spikes or change the behavior, you can explicitly set the policy using the eviction_policy flag in your configuration file or command line:
lru: The default; best for maintaining cache hit ratios but carries the overhead of tracking access.random: Reduces metadata overhead by not tracking access frequency, which can lower latency under extreme contention at the cost of lower hit rates.fifo: First-in-first-out; simple, but often results in poor cache performance compared to LRU.To verify your current instance's behavior, use the following command:
# Check the slab statistics for eviction counts memcached-stat localhost 11211 | grep "evictions"
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 12 Mar 2023, 13:55 UTC
In Memcached 1.6.x, the default eviction policy is LRU (Least Recently Used). While effective for cache hit rates, this implementation relies on per-slab-class locks to manage recency lists. Under high concurrent write pressure, these locks can become significant contention hotspots, leading to increased tail latency as threads queue for lock acquisition during item insertion.
If you are observing latency spikes during write-heavy workloads, you can test the -o eviction_policy=random startup option. The random policy eliminates the need for LRU lock maintenance by selecting victims uniformly from the slab class, which often results in more predictable latency at the cost of a higher miss rate for data with strong temporal locality.
To verify the current active policy on a running instance, you can execute:
echo stats settings | nc localhost 11211
Look for the eviction_policy line to confirm if it is set to lru or another value.