20.4 Serving, Capacity & Load Testing: Math to Code
The chapter so far has explained how inference works: prefill and decode, the KV cache, batching, quantization, and parallelism. This section turns that understanding into a professional skill: sizing, configuring, benchmarking, and explaining a real LLM deployment. Picture the engineer who inherits a customer deployment at an inference cloud from an ML or performance engineer and must defend every number in it, both to a researcher who asks why and to a buyer who asks how much. Everything here is organized as math first, then the code and engine flags that implement it.
Concepts from other sections (11)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- KV cache: the stored keys and values of all processed tokens, per layer, that let each new token attend without recomputation. Read more: Chapter 20: Inference Engines and GPU Deployment
- time to first token (TTFT): the time until the first body byte of an answer is ready to send to the client. Read more: 25.3 The SSE streaming proxy
- roofline: the bound on a loop’s speed from peak compute , memory bandwidth , and arithmetic intensity . Read more: 22.3 Cache-blocked, packed, batch-invariant matmul in C
- Service Level Objective (SLO): a target for a defined measure of service behavior over a specified window. Read more: Chapter 13: Engineering Acronyms in Software Engineering
- speculative decoding: drafting several tokens cheaply and verifying them in one target-model pass, preserving the output distribution. Read more: Chapter 20: Inference Engines and GPU Deployment
- multi-LoRA serving: one base model serving many adapters in the same batch with a batched low-rank kernel. Read more: 20.8 From Training Run to Shared Model: Packaging, Publishing, and Use Cases
- Poisson process: events with independent exponential gaps; the count in a window of length is Poisson with mean . Read more: 13.2 Categorical sampling: inverse CDF, Gumbel-max, alias method in Mathematics
- TTFT, TPOT, ITL: time to first token, mean time per output token, and each individual inter-token gap. Read more: 20.4.6 Load tests and the deployment runbook
- Little’s law: , mean in-flight requests equal arrival rate times mean time in system. Read more: 20.4.6 Load tests and the deployment runbook
- open-loop load test: a benchmark that sends requests at a fixed arrival rate regardless of responses, exposing queueing. Read more: 20.4.6 Load tests and the deployment runbook
- cold start: the time from scheduling a replica to serving its first request, dominated by fetching and reading weight bytes and then by engine initialization. Read more: 20.3.4 Portability and load triage
The thread that ties it together is a single equation for the time of one engine step. Once you can write it down, every metric a customer cares about, time to first token, time per output token, throughput, and cost, becomes a function of it, and every engine knob becomes a way of changing one of its terms. We derive the roofline that separates prefill from decode, build a memory budget that decides concurrency, define the metrics and SLOs that form the contract, and then work through parallelism, engine knobs, speculative decoding, multi-LoRA serving, and load-testing methodology. The section ends with a runbook that takes a customer’s SLO to a deployment config.
This section builds on the chapter opening, LLM Systems & Inference (prefill, decode, and the KV cache), and on Quantization: Math to Code for what FP8 and INT4 buy. The queueing and percentile math uses Poisson processes from Probability and Statistics in Mathematics, and the metrics side connects to Observability in Systems Engineering. Runnable, stdlib-only tools live in code/: a capacity calculator and an open-loop load generator with an offline mock engine. Engine flags were reviewed against the vLLM and SGLang documentation in October 2026.
Learning objectives
- Write the step-time equation for a serving engine and use the roofline to explain why prefill is compute-bound and decode is bandwidth-bound.
- Build a GPU memory budget and derive maximum concurrency from the KV-cache size per token.
- Define TTFT, TPOT, ITL, throughput, and goodput, and use Little’s law and queueing intuition to size for a target load.
- Choose a parallelism strategy and engine flags for a workload, and map a failing SLO to the knob that fixes it.
- Design an open-loop load test, find the goodput knee, and present cost per million tokens to both a technical and a business audience.
In this chapter
Section titled “In this chapter”- Step time and the roofline: Identify whether compute, memory traffic, communication, or overhead limits a workload.
- Memory budget and serving SLOs: Derive cache capacity and distinguish admitted concurrency from stable throughput.
- Parallelism and disaggregation: Choose a serving layout using memory needs and interconnect costs.
- Engine controls and speculation: Map a performance symptom to a measurable scheduling or execution control.
- Adapters and elastic capacity: Account for cold starts and adapter working sets when planning replicas.
- Load tests and the deployment runbook: Measure goodput with an open-loop load and explain a deployment decision.