Try
↑ ↓ move↵ openesc close
In this lesson · topic 3 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 3

Move the hot keys under four policies

7 min read

Compare the policies

The lab below runs all four policies on the same request stream. The chart shows hit rate over the last 400 requests. The keyspace strip shows which keys each cache holds and where the current hot set is. At request 6000 the popular keys are replaced by keys that were cold.

Predict before you press play

After the hot keys move, which policy do you expect to be slowest to recover?

hit rate = hits / requests= 151 / 400 = 37.8%hot keys have not moved yet

Replaces the popular keys with keys that were cold.
Hit rate over the last 400 requests
Hit rate over the last 400 requests. Text version available below the chart.0%25%50%75%100%50250400requestshit rate

Keyspace, 0 to 999

The shaded band is the current hot set. Tall orange marks are cached hot keys. Short grey marks are cached keys that went cold.

FIFO37.8% recent · 34.0% of cache is hot
LRU41.5% recent · 34.0% of cache is hot
LFU44.8% recent · 54.0% of cache is hot
TinyLFU + SLRU46.8% recent · 64.0% of cache is hot
requests
400
hit rate
37.8%
recent hit rate
37.8%
cache still hot
34.0%

Full-page version with guided experiments: Cache eviction lab.

Break the cache on purpose

  1. Watch the share of each cache that is still hot after request 6000. For LFU it stays low.
  2. Press Move the hot keys now a few times with TinyLFU selected. It recovers because its counters are halved regularly.
  3. Set skew to 0. No policy beats cache size over keyspace.
  4. Shrink the cache to 10 keys and widen the keyspace. Everything drops.

The full-page lab has guided experiments for each of these.

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