Skip to content

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.

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.
  1. Step time and the roofline: Identify whether compute, memory traffic, communication, or overhead limits a workload.
  2. Memory budget and serving SLOs: Derive cache capacity and distinguish admitted concurrency from stable throughput.
  3. Parallelism and disaggregation: Choose a serving layout using memory needs and interconnect costs.
  4. Engine controls and speculation: Map a performance symptom to a measurable scheduling or execution control.
  5. Adapters and elastic capacity: Account for cold starts and adapter working sets when planning replicas.
  6. Load tests and the deployment runbook: Measure goodput with an open-loop load and explain a deployment decision.