Cache hit rate estimator
How big does a cache need to be? It depends less on the data size than on how skewed the requests are. When a few keys take most of the traffic, a cache holding 1% of the keys can answer most requests. When traffic is flat, it cannot.
A cache holding 1% of the keys serves 58.5% of requests with LRU, so the origin sees 2,074/s instead of 5,000/s.
Your traffic and cache
Everything a request could ask for: users, products, pages.
0 is uniform. Around 1 is typical for web traffic. Higher means a few keys take most requests.
A size above the key count is treated as the key count.
Ideal against LRU
| Measure | Ideal | LRU |
|---|---|---|
| Hit rate | 68% | 58.51% |
| Miss rate | 32% | 41.49% |
| Mean latency | 13.3 ms | 17.1 ms |
| Origin requests | 1,600/s | 2,074/s |
The cache holds 10,000 of 1,000,000 keys (1%). The most popular 1% of keys receive 68% of requests. LRU gives up 9.5 points of hit rate to the ideal cache because it keeps recently used keys, not the most popular ones. Mean latency is the cache lookup plus the miss rate times the origin latency, since every request pays for the lookup.
Requests are treated as independent draws with fixed popularity. Real traffic has bursts and trends that favour LRU, and scans and one-off keys that hurt it. Items are the same size, nothing expires, and writes do not invalidate entries. Use the numbers to compare options, then measure.
What it shows
A cache works when a few keys take most of the traffic. Then a cache holding 1% of the keys can answer most requests. When traffic is flat, it cannot.
Set the number of keys, how skewed the requests are and the cache size. The tool gives the hit rate of an ideal cache and of an LRU cache, then the mean latency and the load left on the origin. It is a model, not a measurement.
How to read it
- Skew s is the Zipf exponent. 0 means every key is equally likely. Larger values put more traffic on the top keys.
- Ideal hit rate is the share of requests that go to the top k keys, for a cache of k keys. It always holds the most popular keys.
- LRU hit rate uses Che’s approximation. It is the share of requests that find their key among those used most recently.
- Mean latency is the cache lookup time plus the miss rate times the origin time. Origin requests per second are the miss rate times the request rate.
- On the chart, the solid line is the ideal cache and the dashed line is LRU. The marker is your cache size. The curve flattens as the cache grows.
Questions
Why is LRU below the ideal hit rate?
LRU keeps what was used recently, not what is used most. A key that was requested once a moment ago pushes out a popular key that was idle for a while. Frequency-aware policies close part of that gap.
Is Che’s approximation exact?
No. It is an approximation that works well for independent requests, and the tool’s tests check it against a simulated LRU cache. Real traffic with bursts or scans can land above or below it.
What value of s should I use?
Fit it to your own request counts if you can. Breslau et al. showed that web request counts follow a Zipf-like curve, but the exponent differs between traces and products. Try 0.8, 1 and 1.2 and see how much the answer moves.
Why does a bigger cache help less and less?
Each extra key is less popular than the last one added, so it answers fewer requests. Past the point where the curve flattens, more memory buys little.
Does this include cache misses from expiry and invalidation?
No. It assumes fixed popularity, equal-sized items, no TTL and no writes. Expiry and invalidation only lower the real hit rate, so treat the figure as an upper estimate for the traffic shape.
Learn it properly
Sources
- Breslau, L., Cao, P., Fan, L., Phillips, G. and Shenker, S. (1999). Web caching and Zipf-like distributions: evidence and implications. IEEE INFOCOM.
- Che, H., Tung, Y. and Wang, Z. (2002). Hierarchical Web caching systems: modeling, design and experimental results. IEEE Journal on Selected Areas in Communications 20(7).
Explore further
- Caffeine simulatorReplays real cache traces through LRU, LFU and newer eviction policies to compare hit rates.
Last updated
More tools
All tools- estimatorBack-of-envelope estimatorTurn daily users into requests per second, storage and bandwidth, with the working shown.Open tool
- simulatorConsistent hashing simulatorA hash ring with virtual nodes: key spread per node, and how many keys move when the cluster changes.Open tool
- estimatorQueue latency estimatorWhy latency explodes as servers get busy: utilisation, waiting time and Little’s law.Open tool