Try
↑ ↓ move↵ openesc close
In this lesson · topic 4 of 7
  1. 1. Why a small cache works at all
  2. 2. FIFO, LRU, LFU, and TinyLFU
  3. 3. Move the hot keys under four policies
  4. 4. Why plain LFU stays stuck after a shift
  5. 5. How big a cache do you need
  6. 6. When a hot key expires
  7. 7. Check the eviction rules

Topic 4

Why plain LFU stays stuck after a shift

5 min read

These numbers are simulator output with a fixed seed, and a test pins each one. Hover a value to see its setup. The cache holds 50 keys out of 1000, with Zipf skew 1.0.

A stable workload

Overall hit rate after 15000 requests, no workload shift:

Policy Hit rate
FIFO 41%measured
LRU 46%measured
LFU 57%measured
TinyLFU + SLRU 57%measured

FIFO is last, which is what you would expect from a policy that ignores hits. LRU does better. When popularity is stable, frequency-based policies lead, because counts identify the genuinely popular keys.

The workload moves

The same cache, but the hot keys are replaced by keys that were cold, at request 8000. Hit rate over a window of 400 requests, just before the move and 2000 requests after it:

Policy Just before 2000 requests after
LRU 48%measured 54%measured
LFU 58%measured 19%measured
TinyLFU + SLRU 60%measured 65%measured

LRU has not just recovered, it sits a little above where it started, because the new hot set is easy to hold once it has been seen. LFU is stuck far below its starting point. Its cache is full of keys that were popular, whose counts are high, and the keys that are popular now cannot get a foothold. This is the staleness weakness of plain LFU: it is excellent when the past predicts the future and poor when it does not.

TinyLFU recovers because its counters age. Halving them regularly lets new popularity overtake old.

Other ways it breaks

A cache can only help if the hot set fits. If the cache is far smaller than the set of keys that are hot, every policy misses a lot, and the choice of policy matters little. Adjusting the cache size and the skew in the lab shows this directly.

Scans are another classic failure that the lab does not simulate. A single pass over many rarely used keys fills an LRU cache with keys that will not be requested again. Admission policies and segmented designs exist largely to resist this.

Finally, the numbers above are for one workload shape. A policy is only better for the traffic you actually have, so measure on a trace from your own system when you can.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms