Phase 03/Measuring engines/Benchmarking inference engines
PHASE 03 · Measuring engines

Benchmarking inference engines

0%
8 h6 subtopics3 lessons · 1 required
In plain English

Saying one kitchen is "faster" than another means nothing until you say what you measured. For a language model server there are three stopwatch readings that matter. Time to first token is how long the customer waits before the first word appears. Inter-token latency is the gap between words once they start flowing. Throughput is how many words the whole kitchen produces per second for everyone combined. These pull against each other, like a restaurant that can serve more diners per hour only by making each one wait a bit longer. Benchmarking is the discipline of sending realistic, concurrent orders, measuring all three honestly, and reporting percentiles rather than averages so the slowest customers are not hidden.

Why it matters

Every optimization in Phases 4 and 5 is justified by a benchmark, and Project 1 in this roadmap is a benchmarking platform. Engineers who can produce a trustworthy TTFT/ITL/throughput report with a load generator and explain the trade-off curve are the ones trusted to choose engines and hardware.

Hiring signal

Skills this topic builds, with the number of the 46 analysed job postings that ask for each. Companies asking: Anthropic, Anyscale, Baseten, Cerebras, Cohere, CoreWeave, Crusoe, Databricks, ElevenLabs, Fireworks, Hugging Face, Liquid AI, Modal, nvidia, OpenAI, Perplexity, Thinking Machines, Together AI, xAI.See all skills →

Learning objectives

  • Define TTFT, ITL, TPOT, end-to-end latency, request throughput and output token throughput precisely.
  • Write an asyncio load generator that drives an OpenAI-compatible server at a fixed request rate and records per-token timestamps.
  • Report p50, p90 and p99 percentiles and plot the throughput-latency curve across concurrency levels.
  • Use vllm bench serve and compare its numbers with your own client.
  • Identify common benchmarking mistakes such as warm-up omission, unrealistic lengths and measuring on the server only.

Key concepts

TTFT
Time to first token; from request send to first streamed content chunk; dominated by queueing plus prefill.
ITL
Inter-token latency; time between consecutive streamed tokens for one request; dominated by decode step time.
TPOT
Time per output token; (end-to-end minus TTFT) divided by output tokens; the per-request mean of ITL.
Output token throughput
Total generated tokens per second across all concurrent requests; the GPU-level productivity number.
Request rate versus concurrency
Open-loop load fixes arrivals per second regardless of responses; closed-loop fixes in-flight requests; they measure different things.
Percentiles
p50, p90, p99 of a latency distribution; averages hide tail behaviour that users feel.
Warm-up
Discarded initial requests that trigger CUDA graph capture, cache fills and JIT so steady state is measured.
Saturation
The load at which throughput stops rising and latency grows without bound; the knee to report.

Subtopics

  1. 1. Metric definitions

    Precise client-side definitions of TTFT, ITL, TPOT, E2E, request and token throughput, and how streaming makes them measurable.

  2. 2. Load generation

    Open-loop Poisson arrivals versus closed-loop concurrency, realistic prompt and output length distributions (ShareGPT, sonnet), and warm-up.

  3. 3. Collecting and summarising

    Per-token timestamps, percentiles, throughput-latency curves, and plotting the knee.

  4. 4. Standard tools

    vllm bench serve, SGLang bench_serving, GenAI-Perf, and llmperf; what each reports and their defaults.

  5. 5. Fair comparisons and common mistakes

    Same model, dtype, max lengths and sampling; same hardware; tokenizing output to count tokens; reporting versions and flags.

  6. 6. Writing the report

    Setup table, metric table per concurrency, plots, interpretation, limitations; the format Project 1 will use.

Resources

documentation
repo
article

Hands-on lessons

L1

Write a TTFT/ITL/throughput client and benchmark vLLM

Colab T4 · freescript180 minrequired

Goal · bench.py, your own asyncio load generator, producing a percentile table and a throughput-latency curve for a vLLM server at five concurrency levels.

  1. 1Start vllm serve Qwen/Qwen2.5-0.5B-Instruct --dtype half --max-model-len 2048 on the T4 (or reuse p3-vllm-l1).
  2. 2Write bench.py using httpx or the openai AsyncOpenAI client with stream=True; for each request record send time, time of first content chunk and time of every subsequent chunk.
  3. 3Build a prompt set of 200 requests with prompt lengths sampled 64-512 tokens and max_tokens sampled 32-256, fixed seed, temperature 0.
  4. 4Implement closed-loop mode with a semaphore for concurrency C and open-loop mode with Poisson arrivals at rate R; run 20 warm-up requests first and discard them.
  5. 5For each run compute TTFT p50/p90/p99, ITL p50/p99, TPOT mean, E2E p99, request throughput and output token throughput (count tokens by re-tokenizing the output text).
  6. 6Sweep C in 1, 4, 16, 32, 64 and write a CSV row per run; plot output tokens per second versus TTFT p99 and ITL p99.
  7. 7Run vllm bench serve --backend openai-chat with matching settings at C 16 and compare its TTFT and throughput with yours; explain any gap above 10 percent.
  8. 8Write a one-page report with setup table, results table, two plots, the saturation point and limitations.
Deliverable
bench.py, results.csv, two PNG plots and report.md.
Check
Output token throughput at C 32 is at least 4x that at C 1; your TTFT p50 at C 16 is within 15 percent of vllm bench serve; all tokens-per-second numbers use re-tokenized counts.
Fallback
Point bench.py at the CPU toy server from p3-llm-serving-architecture-l1 or vLLM's CPU backend; the absolute numbers will be small but the client, percentiles and curve shape are the same.
L2

Head-to-head vLLM versus SGLang on the same T4

Colab T4 · freeexperiment90 minoptional

Goal · A fair comparison table of vLLM and SGLang on identical model, lengths, sampling and concurrency, with a documented verdict.

  1. 1Launch vLLM, run bench.py at C 16 on the unique-prompt set and on a shared-600-token-prefix set; save results; stop the server.
  2. 2Launch SGLang with the same model, dtype and context length; repeat both runs with the same seed.
  3. 3Confirm fairness by listing model, dtype, max length, sampling params, version strings and GPU in a setup table.
  4. 4Write a short verdict stating which engine wins on each workload and by how much, with p99 numbers.
Deliverable
comparison.md with the setup table, results and verdict.
Check
Both engines are within 2x of each other on the unique set, and SGLang's TTFT gain on the shared-prefix set is reported with a percentage.
L3

Spot the benchmarking mistakes

CPU · your Macreading-code45 minoptional

Goal · A checklist of at least eight benchmarking pitfalls derived from reading two public load generators and one vendor benchmark post.

  1. 1Read vLLM's vllm/benchmarks/serve.py (the `vllm bench serve` implementation) and note how it handles warm-up, token counting and ITL from chunks.
  2. 2Read SGLang's bench_serving.py and list every place its definitions differ from vLLM's.
  3. 3Pick any engine vendor's performance blog post and check it against your definitions; mark what is unspecified.
  4. 4Write a checklist you will apply to every future benchmark and to Project 1.
Deliverable
benchmark_checklist.md with at least eight items, each with a one-line reason.
Check
The checklist includes warm-up, tokenizer-based counting, percentiles, open versus closed loop, version pinning and identical sampling settings.

Build your own

Build your own LLM load generator

PythonCPU · your Mac~7 h

An asyncio load generator in the mould of vllm bench serve, with closed and open loop modes, Poisson arrivals, TTFT, ITL and goodput, and throughput-latency sweeps you can run against any OpenAI-compatible server.

The real thing: github.com/vllm-project/vllm/blob/main/vllm/benchmarks/serve.py ↗

How you know a stage passes

Develop on CPU against the OpenAI-compatible server you built in this phase, then point the same tool at vLLM on Colab. Write tests/test_bench.py first with a fake SSE server fixture (aiohttp or FastAPI) that emits tokens at scripted delays, so TTFT and ITL have known answers; each stage adds assertions against those known values. The CLI is bench.py with subcommands run and sweep. Run `pytest -q`.

Stages, in order. Each one leaves you with something that runs.0/6
  1. 01a closed-loop streaming client
    bench.py run --concurrency N keeps N requests in flight with httpx streaming and records TTFT, every ITL and end-to-end time per request.
    test · Against the fake server scripted to emit 10 tokens 50 ms apart after a 200 ms delay, measured TTFT is 200 ms within 10 ms and every ITL is 50 ms within 5 ms; against your own server, e2e equals TTFT plus the sum of ITLs within 1 percent.
  2. 02datasets and token accounting
    Load a ShareGPT-style JSONL or generate fixed-length synthetic prompts, and count prompt and output tokens with the server's tokenizer rather than trusting chunk counts.
    test · For 10 non-streaming requests your tokenizer count of the output equals usage.completion_tokens exactly, and a synthetic dataset of 100 prompts at 512 tokens has every prompt within 2 tokens of 512.
  3. 03open-loop Poisson arrivals
    bench.py run --request-rate R sends requests with exponential inter-arrival gaps regardless of completion, with a cap on in-flight requests and a log of any dropped sends.
    test · Over 500 requests the achieved arrival rate is within 5 percent of R, and a Kolmogorov-Smirnov test of inter-arrival gaps against the exponential distribution gives p above 0.01.
  4. 04the summary
    Print p50, p90 and p99 for TTFT, ITL, TPOT and e2e, request and token throughput, and goodput under a TTFT and ITL SLO.
    test · On the same vLLM run on Colab, your request throughput is within 5 percent and TTFT p50 within 10 percent of vllm bench serve with identical arguments, and goodput never exceeds throughput.
  5. 05warm-up, repeats and reproducible result files
    Each run does a warm-up pass, repeats K times, and writes results.json with all metrics plus the engine version, model, server args and dataset hash.
    test · results.json validates against your JSON schema, and two back-to-back repeats on an idle machine differ in throughput by under 5 percent.
  6. 06sweeps and curves
    bench.py sweep runs a list of request rates or concurrencies and writes a CSV plus a plot of throughput against p99 TTFT and p99 ITL.
    test · curve.png and table.md are produced; the curve shows throughput flattening while p99 TTFT rises at least 3x past the knee, and the knee rate is printed.

Knowledge check

QWhy should TTFT and ITL be measured on the client rather than from server logs?

Users experience network, HTTP and queueing time; server-side timers miss queueing before the engine and the streaming path, so they understate real latency.

QWhat is the difference between closed-loop and open-loop load, and when does each mislead?

Closed-loop holds concurrency fixed so arrivals slow when the server slows, hiding overload; open-loop fixes arrival rate and reveals queue growth but can blow up past saturation.

QWhy count output tokens by re-tokenizing instead of counting stream chunks?

Engines may emit chunks that contain zero, one or several tokens, so chunk count is not token count and throughput would be wrong.

QA report shows average latency only. What question do you ask?

What are the p90 and p99; averages hide the tail that a meaningful fraction of users experience, especially under continuous batching where some requests are preempted.

QThroughput stops rising at concurrency 32 while p99 ITL keeps climbing. What is happening?

The GPU is saturated (decode has become compute-bound or KV memory is full and requests queue or preempt), so added load only adds waiting.

Completion

  • All 6 subtopics marked done
  • All 1 required lessons done
  • All subtopics marked completed.
  • Lesson l1 bench.py, results.csv, plots and report.md are saved and the check passes.
  • Can define TTFT, ITL, TPOT and token throughput precisely and explain the throughput-latency curve.
Topic progress is derived; it reaches 100% when both checks above pass.Next recommended topic →