Unit 11 of 11 · about 5 hours · measure
Prefix reuse, memory pressure and fairness measured against outcomes
A cache-hit counter measures avoided work, not user success. Retaining prefixes or favoring hot requests can improve that counter while reducing admission headroom or delaying other tenants.
You'll be able to
- Compare reuse off/on under fixed arrivals, token streams, memory budgets and output contracts.
- Explain TTFT and goodput changes using skipped prefill, lookup, queueing, pressure and eviction traces.
- Retain a benefit region and a high-hit-rate region with no better outcome, including per-tenant fairness evidence.
Covers
Read
In this order, only the parts listed
0 of 2 done
- RadixAttention: scheduling, outcomes and ablationsSGLang: Efficient Execution of Structured Language Model Programs
arXiv:2312.07104v2, Section 3, Cache-aware scheduling and starvation caveat; Sections 6.1 to 6.3, metrics, short/long multi-turn chat and Figure 8 ablations
Read the cache experiments, not constrained decoding or API speculation. The offline hit-rate theorem is not an online fairness or goodput guarantee; the paper's older baselines are not your current-engine comparison.
- Hands-On LLM Serving and Optimization: cold versus retained prefixesHands-On LLM Serving and Optimization - Prefix Caching and Advanced KV Caching
Chapter 6, Prefix Caching, Use Cases and Best Practices, printed pp. 226 to 228; Chapter 7, Hands-on LMCache, Run benchmarks and Performance analysis, printed pp. 264 to 266
Use the cold/warm and pressure comparisons as experiment designs. Do not adopt the Chapter 6 claim of almost no drawback as a guarantee, or change prompt order merely to raise hits without rechecking quality.
Focus on
- Define hit rate as reused prompt tokens divided by eligible prompt tokens and state the denominator. Separate active shared pages from retained evictable pages, and keep cold and warmed trials distinct.
- Use the earlier validated load generator. Define client TTFT as arrival/submission to first nonempty generated output, including queueing; define goodput as quality-accepted requests meeting the declared latency targets per measurement time.
- Reused prefix KV skips its repeated forward computation. New suffix queries and decode steps still attend to valid prefix state, so a token-hit fraction is not a proportional latency reduction.
- Keep cache policy and scheduler order separate in ablations. Record per-request and per-tenant waiting, admission, rejection, eviction and preemption alongside latency tails and memory; longest-prefix-first can starve cold traffic.
Common mistakes · 3
- Using a high hit rate as the optimization target. Long decode, lookup cost or a hot replica's queue can dominate the saved prefill.
- Comparing warm reuse with a cold baseline while also changing arrival rate or output length. Name the cache-state treatment and change only the intended mechanism.
- Hiding cold-tenant rejection or cancellation in aggregate throughput. Count unsuccessful work and report per-tenant outcomes, not only completed hot requests.
Try it yourself
Closed-book, before checking anything
servelab manifest with reuse off/on, first using a labeled deterministic CPU model with explicit prefill, decode, lookup and transfer costs. Vary reuse and output length separately, then add pressure and two-tenant skew; retain one benefit region and one high-hit region where lookup, queueing or memory policy prevents better goodput. On your GPU, repeat one bounded pair using a fitting model and the earlier endpoint harness; otherwise retain the simulation and label its timing assumptions. Keep arrivals, prompts, output limits, sampling, quality/SLO rules and pool budget fixed within each pair, with raw request and page traces.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why can 90 percent prompt-token reuse fail to give a tenfold TTFT improvement?Answer
TTFT also includes queueing, tokenization, lookup, remaining attention, sampling and streaming. The remaining suffix still attends to the prefix, and cost need not scale linearly with newly computed tokens.
2.Can retained prefix data reduce capacity without changing physical pool size?Answer
Yes, if the policy pins it or reserves too much space for retention. Immediately evictable pages need not reduce hard admission capacity, but reclaiming them still has policy and management costs.
3.What evidence separates reuse benefit from cache-aware scheduling benefit?Answer
Hold scheduler order fixed while toggling reuse, then hold reuse fixed while changing order. Preserve the same arrivals and outputs and compare raw waiting and execution traces.
4.When is a high-hit negative result valid evidence?Answer
When outputs and workload controls pass, the hit denominator is clear, and traces identify the overhead or remaining bottleneck that prevents better latency or goodput. Simulation must be labeled, not presented as device measurement.
You're done when
You can explain a controlled benefit and a high-hit non-improvement from request/page traces, reconcile memory with the allocator ledger and report cold-tenant outcomes without overstating simulated evidence.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 12 more in the section
- SGLang: Efficient Execution of Structured Language Model ProgramsSGLang Project · required
Study RadixAttention, longest-prefix matching, eviction and cache-aware scheduling. Compare its sequence-level radix index with vLLM's block-level paging instead of treating them as competing names for one mechanism.
- Hands-On LLM Serving and Optimization - Prefix Caching and Advanced KV CachingChi Wang and Peiheng Hu (O'Reilly) · required
Read "Prefix Caching" in Chapter 6 (RadixAttention, use cases, best practices, scaling the prefix cache) and "Advanced KV Caching" in Chapter 7 (long context, cost and latency, LMCache). Separate exact-reuse mechanisms from capacity extensions such as offload.
Also in this section
- Efficient Memory Management for Large Language Model Serving with PagedAttentionvLLM Project · primary
Read the memory-waste motivation, block-table design, sharing and copy-on-write sections, then reproduce the logical-to-physical translation on paper. Separate the paper's reported workloads from results on your engine and hardware.
- AI Systems Performance Engineering - Chapter 18, tuning KV-cache utilizationChris Fregly (O'Reilly) · support
Read "Tuning KV Cache Utilization and Management" in Chapter 18 and "Prefix Caching" in Chapter 16. Leave the disaggregated pool and transfer sections for INF-7.
- Nano-vLLM - Block Manager and Sequence LifecycleGeeeekExplorer · required
Trace nanovllm/engine/block_manager.py, sequence.py, scheduler.py and attention.py. Draw allocate, append, share, preempt and free transitions, then implement randomized allocator tests in your own project before touching production-engine code.
- Mini-SGLang - Radix Cache and Cache TestsSGLang Project · required
Read docs/structures.md, the cache allocation code and tests/core/test_cache_allocate.py. Compare exact prefix identity and lifecycle with Nano-vLLM, then add tenant and version fields to your own prefix index.
- vLLM Automatic Prefix Caching DesignvLLM Project · required
Check block hashing, extra hash keys (multimodal inputs, LoRA, cache salt), isolation and eviction against v0.31.0, the version pinned here; cache-key fields change between releases.
- SGLang documentation - Radix cache eviction and HiCacheSGLang Project · support
Use the radix eviction policy and session radix cache pages to compare eviction choices with vLLM, and the HiCache design page for a GPU, host and storage hierarchy.
- AI Performance Engineering - KV Cache SystemsWafer · reference
A curated index. Use Section 4 only to find a primary KV-cache source the other entries lack.
- 100 Days of LLM Inference - Days 5, 9, 10 and 16Elizabeth Thomas · support
Use the four notebooks for KV arithmetic, paged allocation, radix reuse and prompt-layout experiments. Re-run conclusions against your own property tests and workload because these notebooks are a supplementary learning journal.
- TensorTonic Language Modeling from Scratch - Find Reusable Prefixes in a KV TrieTensorTonic · support
Solve after the prefix-index unit and add the cases its public tests leave out to your own property tests.
- LLM Inference: From scratch, one token at a time - Modules 02 and 06Tushar Amrit · support
Use The KV Cache for fragmentation and reuse and Memory Optimization for paging, prefix sharing and KV compression. Work the checkpoints before the matching units.
- LLM Inference Systems Laboratory - KV StateRoadmap-Final · support
Implement the paged allocator and prefix index with differential, randomized, cancellation, collision, fork and pressure tests. Retain one reuse workload that improves hit rate but not goodput.
- vLLM 0.31.0 - cache specifications and connector lifecyclevLLM Project · reference
Read the per-layer attention, MLA and Mamba specifications for hybrid state contracts; read the V1 connector metadata, load synchronization and deferred-free methods for transfer ownership. These fill the pool's hybrid-state and connector-contract gaps, without requiring distributed execution.