﻿# Read vLLM prefix hit ratios as token-weighted cache observations

Interpret vLLM prefix counters in tokens, preserve cache-tier scope, and aggregate matched counter rates before forming a fleet ratio.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/guide-perf-prefix-token-ratio/
Language: en

A vLLM dashboard labels its prefix-cache ratio as the percentage of requests served from cache. The current engine counters count queried and cached tokens instead. A few long shared prompts can dominate that ratio while many short requests miss. Preserve units, cache tier and engine scope before using the value to explain latency or cache effectiveness.

## Read the metric units

The current logger defines prefix_cache_queries in queried tokens and prefix_cache_hits in cached tokens. Confirm the exported counter names and labels for the installed engine. These observations do not directly count complete requests, full-response cache hits or returned answers. A partial prefix can contribute hit tokens even when the rest of the prompt still requires computation.

## Keep local and external tiers separate

The implementation distinguishes local prefix counters from external connector prefix counters and other cache populations. Do not place a numerator from one tier over an unrelated denominator from another. Record whether a displayed measure covers device-local reuse, external KV reuse or an explicitly defined combined population. A shared word such as hit does not make item counts and token counts interchangeable.

## Compute a matched interval ratio

Use reset-aware counter changes or rates over the same interval and matching labels. Prometheus documents taking rates before aggregation so individual counter resets remain detectable. For a fleet token-weighted ratio, aggregate the appropriate token numerators and denominators before division. Averaging engine percentages equally changes the weighting when engines receive different amounts or lengths of traffic.

## Preserve absence and workload shape

A window with no eligible queried tokens does not establish a successful or failed cache. Represent that missing denominator explicitly. Keep prompt-length and prefix-sharing distributions with the interval, including worker replacements and warmup. The ratio can change because traffic changed while cache behavior remained consistent. A cumulative lifetime ratio can also conceal a recent cold period after a rollout.

## Connect hits to useful work

Compare the token reuse observation with completed-request prefill latency and the remaining uncached work. Prefix caching reuses a shared computation; it is not a complete answer cache or a guarantee that decode becomes faster. Acceptance gives an accurately scoped token-ratio interpretation. It does not infer request hit probability, saved wall time or a financial saving directly from one dashboard percentage.

## Primary references

[vLLM Engine Metric Counters](https://docs.vllm.ai/en/latest/api/vllm/v1/metrics/loggers/).

[Prometheus Counter Query Functions](https://prometheus.io/docs/prometheus/latest/querying/functions/).

[vLLM Automatic Prefix Caching](https://docs.vllm.ai/en/latest/features/automatic_prefix_caching/).

Related reading: [Prefix caching: when repeated context helps a GPU pool](/journal/prefix-caching/); [Persistent KV cache invalidation: when a prefix stops being reusable](/journal/persistent-kv-cache-invalidation/).
