Low KV Cache Hit Rate: Prove There Is Reusable Prefix Before Tuning the Cache
"prefix caching is on, so why will the hit rate not move" is a common misdiagnosis in production. Most of the time the switch is fine - the problem is that requests share no reusable prefix, or the cache is spread across replicas or evicted.
This article works through four branches: broken prefix / replica spread / eviction / configuration squeeze. Metrics follow the vLLM official source - note that V1 replaced the old hit-rate gauge with counters.
Set the standard: which metrics to read now
Older articles tell you to query vllm:gpu_prefix_cache_hit_rate, but vLLM V1 deprecated that
metric. What it currently exposes on /metrics are two counters:
vllm:prefix_cache_queries # queried prefix-cache tokens
vllm:prefix_cache_hits # hit prefix-cache tokens
hit rate = hits / queries
The logs still print "Prefix cache hit rate: xx.x%", but that is a log line, not a Prometheus metric. Check the counters exist before anything else:
curl -s http://localhost:8000/metrics | grep -E "prefix_cache_queries|prefix_cache_hits|gpu_cache_usage_perc"
If prefix_cache_queries is missing altogether, check the version and metrics pipeline first - this is not
"a hit rate of zero", it is a missing metric.
Classification: four branches
Symptom -> check -> conclusion -> action
Hit rate ~0 and request prefixes differ
|-- compare system prompt / template prefix tokens across requests
`-- broken prefix -> fix template, drop timestamps / random IDs / unstable doc order
Hit rate far lower with several replicas than with one
|-- check gateway routing policy (round-robin across replicas?)
`-- replica spread -> sticky routing by stable prefix or a shared KV layer
Hit rate drops as concurrency rises and preemptions grow
|-- check gpu_cache_usage_perc + preemptions
`-- eviction -> lower concurrency / allocate more memory to cache
Hit rate drops after raising max-model-len
|-- check reserved KV cache per request
`-- configuration squeeze -> tighten max-model-len moderately
Branch One: A Broken Prefix
The cache matches prefixes by token block; anything that makes each request prefix different drives the hit rate to zero. The usual three culprits: a date or timestamp embedded in the template, a random request id on every call, or unstable ordering of retrieved documents in RAG. To diagnose, take two real requests and compare their prefixes token by token to find the first divergence. The fix is to make the stable part truly stable: move the timestamp to the end of the user message, keep random IDs out of the cached prefix, and sort retrieved results deterministically.
Branch Two: Replica Spread
The vLLM prefix cache is instance-level: each replica only caches prefixes it has handled. With three replicas, a request routed to B cannot reuse a block cached on A. First check whether the gateway round-robins; if so, hash on a stable prefix (system prompt or business key) so requests with the same prefix stick to one replica, or introduce a shared KV cache layer. Fix routing before adding replicas - more replicas only spread the cache thinner.
Branch Three: Eviction
One boundary before tuning anything: a low hit rate is not a fault by itself, it deserves a fix only when TTFT rises or costs look abnormal. If prefixes are genuinely varied (open-ended chat), a low hit rate is normal and cache tuning is wasted effort - accept it and invest elsewhere. If your workload has clearly repeated system prompts, fixed document sets, or templated tasks, a poor hit rate means the cache path really is broken. That decision determines whether the following work is worth doing.
The KV cache pool is finite; as new requests arrive, LRU evicts old blocks. Watch two signals:
- gpu_cache_usage_perc persistently near 1: the cache pool is full and old prefix blocks are evicted, so the hit rate falls as concurrency rises.
- Rising preemptions: sequences are swapped out and recomputed, which also hurts cache locality.
Actions: leave room for the cache - lower concurrency (--max-num-seqs), reallocate memory, or switch the KV cache to fp8 to reduce per-token memory.
Branch Four: Configuration Squeeze
Counterintuitively, the larger --max-model-len is, the more KV cache each request reserves and the fewer
historical requests fit in the same memory - so the hit rate actually drops. If the workload only needs
8k of context, do not set 32k; choose an upper bound from the real P99 input length and the cache
capacity becomes much roomier. After the change, replay the same real traffic and compare hits/queries and
TTFT, and confirm no long requests are truncated before rolling out.
Three Failure Cases (Built from Typical Production Scenarios)
Case 1: a template change with a date dropped the hit rate from 80% to 10% overnight. A Q&A service added "Today is {date}" to its system prompt; the hit rate collapsed. The root cause was the daily date changing every request prefix and invalidating the cache. The fix moved the date to the end of the user message. Lesson: compare request prefixes before suspecting the cache.
Case 2: the hit rate fell from 85% to 30% after scaling to three replicas. A team added two replicas to handle load and the gateway round-robined traffic; the hit rate slid. The root cause was instance-level cache spread across three replicas. The fix was sticky routing hashed on the system prompt so requests with the same prefix always landed on the same replica, the hit rate returned to the 80% range. Lesson: check the routing policy before adding replicas; instance-level caches hate round-robin.
Case 3: max-model-len set to 32768 kept the hit rate low. One service set the maximum length to 32768 "to leave headroom" and the hit rate stayed poor. The root cause was excessive reserved KV cache per request. Tightening to 8192 based on the actual input distribution raised the hit rate markedly. Lesson: more context is not always better - the more you reserve, the less you can cache.
Quick Reference
| Symptom | Check first | Likely cause | Action |
|---|---|---|---|
| Hit rate ~0 | compare request prefix tokens | timestamp / random ID in template | make the stable prefix stable |
| Hit rate drops with replicas | gateway routing policy | instance-level cache spread | sticky routing / shared KV layer |
| Hit rate drops as concurrency rises | gpu_cache_usage_perc + preemptions | LRU eviction | lower concurrency / more memory / fp8 |
| Worse after larger max-model-len | reserved cache per request | configuration squeeze | tighten by P99 input length |
| counters absent from /metrics | grep prefix_cache | version or metrics pipeline issue | fix version/pipeline first, not a zero hit rate |
Related
- Prompt caching in practice: the full ledger of cache hits and cost.
- Throughput vs latency trade-offs and vLLM production tuning: instance-side parameters.
- Cold starts and scaling jitter in LLM serving: how replica spread relates to scaling.
- LLM observability and tracing: where metrics come from and how to dashboard them.
Originality statement: All decision frameworks, commands and cases in this article were assembled by the author from the vLLM official source and hands-on production troubleshooting; the three cases are built from typical production scenarios and are not records of any specific customer site. The V1 metric claims were verified against the official vLLM metrics source.