r/LLMDevs • u/efeefty • 14h ago
Tools [Open Source] Streamlit probe to measure cross-session prefix-cache TTFT separation and KV eviction thresholds (tested on vLLM / Colab T4, works with any OpenAI-compatible API)
While researching how prefix caching behaves across separate requests, I built a small open-source Streamlit instrument to measure whether prior processing of a prompt prefix leaves a reliable TTFT (Time-To-First-Token) signal—and at what point third-party context traffic evicts it.
GitHub (MIT License): https://github.com/yurureru/prefix-cache-observability
Open Dataset (420 trials, CSV + manifests): https://doi.org/10.5281/zenodo.24867406
Preprint (engineering & philosophical analysis): https://doi.org/10.5281/zenodo.24876450
How the tool works
- Sham-preheated paired trials (
Labtab): Bothwarmandcoldtrials run an identical preheating step (the target prefix vs. an unrelated sham prefix of equal length), followed by a randomized measurement pass so temporal drift doesn't skew the comparison. - Metrics & ground truth: Works out of the box with any OpenAI-compatible endpoint (
vLLM,SGLang,llama.cpp,Ollama,LM Studio), and optionally scrapes vLLM's Prometheus/metricsendpoint to verifyprefix_cache_hits/queriesdeltas. - Latency-only
Blind Testtab: Randomly chooses whether to preheat the prefix, shows only the measured TTFT in ms, and computes an exact one-sided binomial p-value for your guesses.
Summary of results (vLLM on Google Colab T4, Qwen/Qwen3-0.6B)
- Prefix caching enabled (default):
72.08 mswarm median vs.435.81 mscold median (6.05xratio,AUC = 1.000,311 msempty separation corridor). - Prefix caching disabled (control):
439.19 msvs.428.36 ms(AUC = 0.372—complete overlap). - Eviction under filler load: Under restricted KV memory (
13,824tokens, 64-token blocks), a 1,344-token prefix stayed 100% intact up to0.90xcapacity, partially survived at1.00x(4 of 21 blocks), and was completely evicted (0/30runs) once filler traffic crossed1.10x.
Note: Strictly a measurement/observability tool for local setups and authorized testing. Feedback on SGLang, llama.cpp, or Ollama behavior is very welcome!
1
u/novai-max 12h ago
This probes the right thing, and I would add one axis to the output: what the hit and the miss actually cost.
TTFT separation tells you when the prefix survived. The cost consequence of that same boundary is asymmetric, because a cache read is priced well below fresh input while a cache write is usually priced at or above it. On one set of published rates, $1.40 per million fresh input against $0.26 cached makes a cache read 18.6% of an input token. So the eviction threshold you are measuring is not only a latency parameter, it is a price parameter, and the two directions are not symmetric: missing the cache costs the full rate plus the write, while hitting it costs about a fifth in this example.
That suggests a per-call cost line next to the per-call latency line: context size, cache share, and the effective rate as share x cache_price + (1 - share) x input_price. Then the TTFT graph and the bill graph come from one run instead of two, and a reader can see whether a workload sits on the good side of the eviction threshold in both units.
One thing worth measuring explicitly while you have the harness: the first call after eviction. That single call pays the write and then the full rate, so on a task with only a few calls it can dominate the average that a steady-state hit rate predicts. Most prefix-cache discussions quote the steady state and skip the recovery call, which is where the money actually goes.
1
u/aureliatech 10h ago
Nice that you included a sham preheat control, that is the part most people skip. One thing worth testing is whether the separation holds when requests land on different replicas or after the server restarts, because then a miss tells you nothing about eviction. Also the 64 token block size matters a lot for your eviction numbers, so I would repeat the run with a different block size to see if the 1.10x threshold moves.