Inference Engineering

Lesson 14: Measuring a serving system · Workbook

Measuring a serving system: the workbook

The full working behind lesson 14. Every metric a serving benchmark prints, why percentiles and not means, Little's law, open-loop and closed-loop load, the latency-throughput curve, two definitions of goodput, how to run vLLM's benchmark honestly, and seven exercises to check yourself.

A chatbot user notices two things: how long they wait before text starts appearing, and how fast it streams once it does. A serving team cares about a third: how many users one GPU can carry. Every serving benchmark is an attempt to measure these together, and the hard part is not computing the numbers. It is generating load the way real users do, so the numbers describe production rather than the test.

This workbook defines the metrics, then runs a simulated server through the same kind of benchmark you would run against vLLM. The simulator is the course’s running example: Llama 3.1 8B in BF16 on one H100, with each batching iteration costed at its roofline floor from lesson 1. Its absolute latencies are therefore optimistic, since a real server adds scheduling and kernel overhead, but the shapes it produces are the ones you will see in real measurements.

What gets measured

A request moves through a server in three stages. It waits in a queue until the scheduler admits it. Then the server runs prefill, one forward pass over the whole prompt, which produces the first output token. Then it runs decode, one token per iteration, until the output is complete (lesson 3 covers why these two phases behave so differently). With continuous batching, each iteration serves every request that is currently decoding, plus any newly admitted prompts.

From the timestamps of each output token, a benchmark derives four latencies per request:

TPOT=end-to-end latency−TTFToutput tokens−1\text{TPOT} = \frac{\text{end-to-end latency} - \text{TTFT}}{\text{output tokens} - 1}

so each request contributes one TPOT sample. It sets the streaming speed a user sees.

Below is one request taken from the simulator at 70 requests per second. Note that its token gaps are not equal. Most iterations only decode, but when other requests are admitted, their prefills run in the same iteration and every decoding request waits for them. ITL shows that stall; TPOT averages it away.

One request, timed

longest gap 18.0 msarrivesfirst tokenlast tokenTTFT 15.6 ms14 more tokens: TPOT 10.8 msend-to-end latency 166.1 mslongest gap 18.0 msarrivesfirst tokenlast tokenTTFT 15.6 ms14 more tokens: TPOT 10.8 msend-to-end latency 166.1 ms

waiting in linereading the prompt (prefill)writing the reply, one tick per token

One request from the simulated server under 70 requests/s of Poisson traffic. Every tick is one output token, emitted at the end of a batching iteration. The longest gap is an iteration in which other requests' prompts were prefilled alongside this request's decode step.

Across every request in that run, the median ITL is 9.7 ms and the p99 ITL is 25.1 ms, while the p99 of TPOT is only 12.0 ms. If users complain about stutter rather than slowness, look at ITL. The simulator prefills each prompt whole; chunked prefill (lesson 12) caps how much prefill joins one iteration and shrinks these stalls.

Two throughput numbers sit beside these. Request throughput is completed requests per second. Output token throughput is generated tokens per second, summed over all requests. Token throughput is the one that relates to hardware cost, since a GPU-hour buys a number of tokens; request throughput is easier to compare with the arrival rate you expect.

Why percentiles and not means

Latency distributions in serving have long right tails. Output lengths vary by orders of magnitude, so end-to-end latency does too. Queueing adds a second tail: when a burst of requests arrives together, the last ones in the burst wait for the first ones.

The simulator’s workload draws prompt and output lengths from a lognormal distribution whose means match the ShareGPT figures the vLLM paper reports (161.31 input and 337.99 output tokens); after clipping at 2,048 tokens, the 8,000 sampled requests average 165 and 324. At 40 requests per second, end-to-end latency has a mean of 2.11 s, a median (p50) of 1.36 s and a 99th percentile (p99) of 12.88 s. The mean describes no actual user: most finish faster, and the slowest 1% wait over 6 times longer.

The mean also misleads about the typical request. At 70 requests per second, just under what this server can sustain, mean TTFT is 112 ms, but the median is 23.3 ms: most requests are admitted at once, while a queue builds during random bursts of arrivals and drains between them, and the requests caught in it wait long enough to drag the mean up. The p99 is 703 ms.

So report percentiles. The pN latency is the value that N% of requests come in under; p50 is the typical experience and p99 is the experience of one request in a hundred, which at scale is many users every minute. vLLM’s benchmark computes them with numpy’s default linear interpolation and prints the mean, median and p99 unless you ask for other percentiles with --metric-percentiles.

Little’s law ties the three numbers together

Concurrency, throughput and latency are not independent. Little’s law says that for any system in a steady state, the average number of items inside it equals their arrival rate times the average time each spends inside:

L=λWL = \lambda W

Little proved it in 1961 under very general conditions: it does not depend on the arrival pattern, the service order or the distribution of service times. For a serving system, LL is the number of requests in flight, λ\lambda is the request rate and WW is mean end-to-end latency.

It is a quick check on any benchmark report. At 40 requests per second with a mean latency of 2.11 s, the server holds about 85 requests at once. At 70 requests per second latency rises to 3.67 s and that becomes about 257; at 75, about 445. The simulated server admits at most 256 sequences per iteration, so somewhere in this range, random bursts start to push it past the limit and requests begin to queue. Little’s law points at the knee before we plot it.

Over a whole run that starts and ends empty, the law holds exactly for any system, which makes it a good sanity check on a report but not a test of the server. Over the steady window of the simulated run at 40 requests per second, the time-averaged number of requests in the system is 84.0, and the offered rate times the mean latency of those requests is 84.6.

Two ways to generate load

A load generator decides when to send each request, and the choice changes what you measure.

Open loop sends requests on a schedule that does not depend on the server: for example a Poisson process at a fixed rate, where the gaps between requests are random with a fixed mean. That is how independent users behave. They do not wait for each other, so when the server slows down, requests keep arriving and the queue grows. The vLLM paper generates its arrival times this way.

Closed loop runs a fixed number of clients, each sending its next request only when the previous reply finishes. The concurrency is fixed by construction, L=CL = C, and Little’s law then fixes the throughput: λ=C/W\lambda = C / W. When the server slows down, the clients slow down with it. A queue can only form if there are more clients than the server will batch.

That self-regulation is the problem. In closed loop, the load generator stops sending exactly when the server is struggling, so the slow periods produce fewer samples. Gil Tene calls this effect coordinated omission: the omitted requests are precisely the ones that would have seen the worst latency.

The simulator shows the size of the effect. With 256 closed-loop clients, the server completes 70.0 requests per second with a p99 TTFT of 32.0 ms. Open-loop Poisson arrivals at 70 requests per second give about the same throughput, 69.2, but a p99 TTFT of 703 ms. Both modes top out at the same capacity; the difference is that closed loop never shows the queueing that random bursts cause near it. The closed-loop run would lead you to promise a latency that real traffic does not get at that throughput. Add more clients than the batch limit and closed loop does finally show queueing (at 320 clients, p50 TTFT is 920 ms), but by then the number you set is the queue length, not a property of the server.

Closed loop is still useful when it models the real client, such as a batch job with a fixed worker pool. For anything serving independent users, test open loop.

The latency–throughput curve

One run at one rate tells you little. The useful result is a sweep: run the benchmark at a series of arrival rates, and for each one plot latency percentiles against the throughput achieved. The vLLM paper describes the shape it found: as the request rate rises, latency first grows slowly and then suddenly explodes, because past the system’s capacity the queue grows without bound.

The point where the curve turns upward is the knee. There is no standard definition; in the figure we mark it at the last tested load before p99 TTFT first exceeds three times its light-load value. For the simulated server in open loop that is 65 requests per second; in closed loop it is 256 clients.

Below the knee, adding load buys throughput for a modest latency cost, mostly in TPOT, because every extra sequence in the batch makes each iteration a little longer. Past it, extra load buys a little throughput at a steep price in queueing: from 65 to 100 requests per second offered, completed throughput rises from 64.7 to 70.1 while p99 TTFT goes from 38.1 ms to 25,442 ms.

Run the load test yourself

Llama 3.1 8B on one H100, simulated in your browser

The simulation runs when this figure scrolls into view.

How the load generator sends requests
Throughput
TTFT p50 / p99
TPOT p50 / p99
Meet both SLOs
Request goodput (this run)
Little's law

Each point is one simulated benchmark run of 8,000 requests through Llama 3.1 8B on an H100, with iteration cost at the roofline floor. Thick lines are p99, thin lines p50; the dotted line is the other load mode's p99 for comparison. The shaded band covers loads where at least 90% of requests meet both SLOs (service-level objectives: latency limits a request must meet; goodput, defined in the next section, counts only requests that meet them). Switch to closed loop and compare how far right the curve gets before TTFT turns up.

Goodput: throughput that meets the targets

Throughput counts every completed request, including those that took too long to be useful. Service-level objectives (SLOs) state what useful means, typically as a TTFT limit and a TPOT limit. Goodput counts only requests that meet them.

There are two definitions in use, and they answer different questions:

The difference matters because TPOT is shared fate. Every request in the same batch sees the same iteration times, so as load rises TPOT moves for everyone at once. With the latency–throughput figure’s default SLOs (100 ms TTFT, 8.0 ms TPOT), 96% of requests meet both at 50 requests per second, 71% at 55 and 9% at 60. At 55 the median and p99 TPOT are 7.8 ms and 8.9 ms, so once the median nears the limit most requests miss it together. A single run’s goodput depends on which side of that cliff you happened to test; DistServe’s definition finds the cliff. At 55 requests per second, vLLM’s request goodput is 32.1 requests per second, against a whole-run request throughput of 45.4. The DistServe goodput is 50 requests per second: the server’s real capacity under those SLOs, set by the TPOT limit well before the queue explodes at the knee. Move the TPOT slider and watch the shaded band.

DistServe’s argument is that prefill and decode should be placed on separate GPUs and sized to maximize goodput rather than raw throughput. Lesson 12 covers how.

Running a benchmark honestly

The simulated runs follow a few rules, and so should real ones.

Warm up, and measure a steady window. The first requests hit an empty server and see no queue; the last ones run while arrivals have stopped. An empty server needs about as long as its longest request takes before the number in flight levels off, and a short run at an overload rate can look healthy because it ends before the queue forms. The simulator sends 8,000 requests and measures neither the first 3,000 nor the last 1,000; at 70 requests per second the warmup alone lasts 43 s, while the longest measured request at that rate takes 23 s. vLLM’s --num-warmups sends that many copies of the first request before the measured run and leaves them out of the results.

Run long enough. Under overload the queue grows for as long as the test runs, so measured tail latency depends on the test length, not just the server. vLLM’s request throughput also divides by a duration that includes the drain at the end, when the last long outputs finish with few arrivals left. At 40 requests per second, the simulator’s whole-run figure is 35.5 requests per second against 39.9 in the steady window. Send many more requests than the rate times your longest latency.

Use realistic lengths. Prefill cost grows with prompt length and decode time with output length, and both distributions have long tails. A test where every request has the same lengths hides that. Use a dataset like ShareGPT, or your own production logs, which are better.

Sweep the rate, and report offered and achieved together. Past capacity, an open-loop run achieves less throughput than it offers. At an offered 100 requests per second, the simulator completes 70.1.

Check the floor first. If a latency target is below what one request on an idle server takes, no load passes it. Here an idle server’s decode step takes 4.5 ms, so a TPOT limit below that yields zero goodput at any rate.

With vLLM

The benchmark client ships with vLLM as vllm bench serve (the older benchmarks/benchmark_serving.py script now only prints a message pointing to it). Start the server, then in another shell:

vllm serve meta-llama/Llama-3.1-8B-Instruct

# ShareGPT_V3_unfiltered_cleaned_split.json is linked from vLLM's benchmark docs
vllm bench serve \
  --model meta-llama/Llama-3.1-8B-Instruct \
  --dataset-name sharegpt \
  --dataset-path ShareGPT_V3_unfiltered_cleaned_split.json \
  --num-prompts 2000 \
  --request-rate 20 --burstiness 1.0 \
  --num-warmups 50 \
  --percentile-metrics ttft,tpot,itl,e2el \
  --metric-percentiles 50,90,99 \
  --goodput ttft:500 tpot:50

Repeat with different --request-rate values to trace the curve. Three defaults deserve attention. --request-rate defaults to inf, which sends every request at time zero: a burst test, not a rate. --burstiness 1.0 gives Poisson arrivals; lower values make traffic burstier. And --max-concurrency caps requests in flight, which turns the test partly closed-loop. The docs also warn that repeating a run against the same server can reuse its prefix cache and inflate throughput (see lesson 8).

The output fields map onto this lesson:

FieldMeaning
Benchmark duration (s)Wall time from the first request sent to the last reply, including the drain
Request throughput (req/s)Completed requests ÷ duration
Request goodput (req/s)Requests meeting every --goodput limit ÷ duration; printed only with --goodput
Output token throughput (tok/s)Generated tokens ÷ duration
Total token throughput (tok/s)Prompt plus generated tokens ÷ duration
Mean, Median, P99 TTFT (ms)Time to first streamed output, per request
Mean, Median, P99 TPOT (ms)(E2E − TTFT) ÷ (output tokens − 1), per request
Mean, Median, P99 ITL (ms)Gaps between streamed outputs, pooled over all requests
Mean, Median, P99 E2EL (ms)End-to-end latency, per request

ITL and TPOT differ in one more way than the request-timeline figure showed. vLLM measures ITL between streamed outputs, and with speculative decoding one output can carry several tokens. ITL then counts one gap for the bundle while TPOT spreads the time over every token. Its docs note that metric names are not standardized across tools, so compare the formulas, not the labels.

Check yourself

Exercise 1. A closed-loop benchmark runs 64 clients with no pause between requests and reports a mean end-to-end latency of 1.95 s. Without looking at the throughput line, what request throughput should it report?

requests/s
Show the worked answer

About 32.9 requests per second, from Little’s law: with 64 requests always in flight, λ=L/W\lambda = L / W. The simulator’s steady-window measurement for this run is 33.0, a match. A large gap would mean the run was not in steady state, or the report is wrong.

Exercise 2. A run at 70 requests/s reports mean TTFT 112 ms and median TTFT 23.3 ms. What does the gap tell you, and which number belongs in an SLO?

Show the answer

Most requests start almost at once, but a minority waits far longer: a queue forms during bursts of arrivals and drains between them. Mean TTFT sits well above the median because a few large values pull it up. The p99 is 703 ms. SLOs are written on percentiles, such as p90 or p99, because they bound what a share of users actually experience.

Exercise 3. You run an open-loop benchmark at 100 requests/s, past this server's capacity. With 4,000 requests, p99 TTFT comes out at 10,318 ms. You rerun with 8,000 requests. What do you expect?

Show the answer

Much worse: 25,442 ms. Past capacity the queue grows for as long as requests keep coming, so tail latency depends on how long you test. A single overloaded run has no meaningful latency; the useful facts are that this rate is past the knee, and where the knee is.

Exercise 4. With SLOs of 100 ms TTFT and 8.0 ms TPOT, a run at 55 requests/s takes 88.03 s from first to last measured request, completes 4,000 measured requests, and 71% of them meet both. What request goodput does vLLM print, and what is the DistServe goodput for this server? Enter the vLLM figure.

requests/s
Show the worked answer

vLLM’s request goodput is the requests meeting both SLOs divided by the duration: about 32.1 requests/s. DistServe’s goodput is the highest tested rate with at least 90% meeting both: 50 requests/s. Operating at 55 gives more throughput, but much less of it is useful.

Exercise 5. A product team asks for a TPOT target of 4 ms on this server (Llama 3.1 8B in BF16 on one H100). How much load can it carry under that target?

Show the answer

None. One decode step on an idle server takes at least 4.5 ms, because it must read all Llama 3.1 8B weights from memory every step (lesson 1). No batching or scheduling gets under that floor. The options are fewer bytes per step, such as quantized weights, more bandwidth, or speculative decoding, which produces several tokens per weight read.

Exercise 6. From lesson 1: one user talks to Llama 3.1 8B in BF16 on an otherwise idle H100, with a 1,024-token conversation. At the roofline floor, what is the most tokens per second that user can get?

tokens/s
Show the worked answer

About 221 tokens per second: each decode step must read every weight from memory, and the floor for the step is 4.5 ms. That floor, almost all of it the weight read, is also about the lowest TPOT this server can ever promise, which is why Exercise 5’s target fails at any load. Batching does not lower it; it only shares each read of the weights across more users.

Exercise 7. From lesson 4: the simulated server has one 80 GB H100, holds back 10% of it, and keeps every running request's KV cache next to the BF16 weights. How many tokens of KV cache fit?

tokens
Show the worked answer

About 426,784 tokens: the memory left after the reserve and the weights, divided by the bytes of keys and values each token needs. In this simulation each request books its prompt plus its full output up front, about 499 tokens on average, so memory has room for over 800 of them at once, more than the 256-request batch limit. In this simulation the batch limit, not memory, is what caps the number in flight, which is why closed loop starts queueing only past 256 clients.

Sources

  1. Zhong, Liu, Chen, Hu, Zhu, Liu, Jin, Zhang (2024). DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving. OSDI 2024. arXiv:2401.09670. Defines goodput as the highest request rate at which a target share of requests (90% in its evaluation) meets both TTFT and TPOT objectives
  2. Little, J. D. C. (1961). A Proof for the Queuing Formula: L = λW. Operations Research 9(3), 383–387
  3. Kwon, Li, Zhuang, Sheng, Zheng, Yu, Gonzalez, Zhang, Stoica (2023). Efficient Memory Management for Large Language Model Serving with PagedAttention. SOSP 2023. arXiv:2309.06180. Section 6.1: ShareGPT and Alpaca workloads, Poisson arrivals; Fig. 11 gives ShareGPT mean lengths of 161.31 input and 337.99 output tokens
  4. vLLM documentation: Benchmark CLI, online benchmark and latency metric definitions
  5. vLLM documentation: vllm bench serve reference
  6. vLLM source: vllm/benchmarks/serve.py. How each printed field is computed: TPOT, ITL, request goodput, percentiles via numpy
  7. Gil Tene (2015). How NOT to Measure Latency. QCon San Francisco, slides. Coordinated omission: how load generators that wait for replies hide latency

Back to lesson 14: Measuring a serving system