Warming and prefetch are two mechanisms, not one
When does a prefetch pay, and how fast can a cold cache be ramped without overwhelming the origin?
They are often grouped together. They share only the direction of the data movement.
Prefetch: speculation on the read path
Prefetch means fetching an item before anyone asks, hoping it will be asked for. Its economics include a cost people leave out. The value of a prefetch, and the accuracy P(hit) it needs to pay, are
- what a hit on the prefetched entry saves
- cost of the speculative fetch
- value lost from the entry it displaces
where S is the saving if it hits, C_fetch is the cost of fetching, and C_evict is the cost of the entry it pushed out.
A wrong prefetch costs twice: the bandwidth, and the useful entry that it displaced. C_evict is the marginal value of the displaced entry. That is the slope of the miss-ratio curve from What makes data cacheable (the curve of miss rate against cache size). So the prefetch accuracy threshold is set by the gradient of your miss-ratio curve:
- On a plateau (a flat part), eviction costs almost nothing, so aggressive prefetch is nearly free.
- Just past a cliff (a steep drop), which is where a well-sized cache should sit, a wrong prefetch is expensive.
This leads to a result that is surprising and correct: a well-sized cache should prefetch less aggressively than a badly sized one. It explains why real prefetchers limit themselves to patterns with near-certain continuation (detecting sequential reads, fixed strides) and not anything speculative. Only near-certainty clears the threshold once C_evict is counted. A second reason for caution: prefetch uses the same bandwidth that real (demand) misses need. Aggressive prefetch can cause incast, a pile-up of many responses arriving at one receiver at once, on your own system.
Warming: survivability, not latency
Warming means filling a cache in bulk when no request is waiting. Its purpose is not lower latency. It is survivability. It exists to prevent the cold-cache collapse that the leverage ratio predicts: at h = 0.95 the origin is sized for one twentieth of the load, so sending full traffic to an empty cache gives the origin 20 times its capacity.
That makes the ramp a control problem with a set-point you can calculate. Admit traffic at a rate λ(t) such that
- the hit rate at time t, read from the miss-ratio curve as the cache fills
Data table
| Hit rate as the cache fills | Traffic you may admit (per second) |
|---|---|
| 0 | 1.5K |
| 0.012 | 1.52K |
| 0.025 | 1.54K |
| 0.037 | 1.56K |
| 0.049 | 1.58K |
| 0.061 | 1.6K |
| 0.074 | 1.62K |
| 0.086 | 1.64K |
| 0.098 | 1.66K |
| 0.11 | 1.69K |
| 0.123 | 1.71K |
| 0.135 | 1.73K |
| 0.147 | 1.76K |
| 0.159 | 1.78K |
| 0.171 | 1.81K |
| 0.184 | 1.84K |
| 0.196 | 1.87K |
| 0.208 | 1.89K |
| 0.221 | 1.92K |
| 0.233 | 1.96K |
| 0.245 | 1.99K |
| 0.257 | 2.02K |
| 0.269 | 2.05K |
| 0.282 | 2.09K |
| 0.294 | 2.12K |
| 0.306 | 2.16K |
| 0.319 | 2.2K |
| 0.331 | 2.24K |
| 0.343 | 2.28K |
| 0.355 | 2.33K |
| 0.367 | 2.37K |
| 0.38 | 2.42K |
| 0.392 | 2.47K |
| 0.404 | 2.52K |
| 0.416 | 2.57K |
| 0.429 | 2.63K |
| 0.441 | 2.68K |
| 0.453 | 2.74K |
| 0.466 | 2.81K |
| 0.478 | 2.87K |
| 0.49 | 2.94K |
| 0.502 | 3.01K |
| 0.514 | 3.09K |
| 0.527 | 3.17K |
| 0.539 | 3.25K |
| 0.551 | 3.34K |
| 0.564 | 3.44K |
| 0.576 | 3.54K |
| 0.588 | 3.64K |
| 0.6 | 3.75K |
| 0.613 | 3.87K |
| 0.625 | 4K |
| 0.637 | 4.13K |
| 0.649 | 4.28K |
| 0.661 | 4.43K |
| 0.674 | 4.6K |
| 0.686 | 4.78K |
| 0.698 | 4.97K |
| 0.71 | 5.18K |
| 0.723 | 5.41K |
| 0.735 | 5.66K |
| 0.747 | 5.93K |
| 0.759 | 6.24K |
| 0.772 | 6.57K |
| 0.784 | 6.94K |
| 0.796 | 7.36K |
| 0.808 | 7.83K |
| 0.821 | 8.37K |
| 0.833 | 8.98K |
| 0.845 | 9.69K |
| 0.857 | 10.5K |
| 0.87 | 11.5K |
| 0.882 | 12.7K |
| 0.894 | 14.2K |
| 0.906 | 16K |
| 0.919 | 18.5K |
| 0.931 | 21.7K |
| 0.943 | 26.4K |
| 0.956 | 33.7K |
| 0.968 | 46.5K |
| 0.98 | 75K |
where h(t) is the hit rate at time t, read from the miss-ratio curve as the cache fills.
The ramp rate follows from the origin's spare capacity and the curve. It does not follow from a fixed timer, which is how ramps are almost always built, and why warm-ups either take far too long or protect nothing.
There are four warming mechanisms, and they are not equivalent:
| Mechanism | How it works | Weakness |
|---|---|---|
| Top-K replay from the access log | replay the most popular keys | fills with yesterday's popularity; wrong when popularity drifts |
| Snapshot and restore of cache contents | save the cache before a restart, reload after | best choice when the substrate allows it: it keeps the real working set |
| Shadow traffic | copy live traffic to the new cache | accurate, but doubles origin load at the worst moment |
| Gradual traffic ramp | send a growing share of real traffic | the only self-tuning one: it fills the cache with exactly the distribution about to be requested |
Notice a coupling back to What makes data cacheable: every warming strategy except the ramp needs measured popularity. You cannot warm well without the instrumentation of What makes data cacheable, so the measurement work is a prerequisite for warming too, not only for sizing.
Compression: Prefetch is speculation priced against the slope of the miss-ratio curve, so a well-sized cache prefetches less. Warming is a survivability controller whose ramp rate is set by origin spare capacity. Only the traffic ramp is self-tuning.