Latency metrics: TTFT, TPOT, throughput
Split LLM latency into TTFT (wait for the first token: queueing + prefill) and TPOT (gap between later tokens: decode), track p95/p99, and size capacity by goodput, the throughput that still meets both SLOs.
Analogy: A restaurant: TTFT is how long until the first dish arrives, TPOT is the gap between courses, and goodput is how many tables per hour get their whole meal on time, not how many plates leave the kitchen.
How it works
- Output length usually dominates E2E latency: 500 tokens at 30 ms each take 15 s.
- Report percentiles, not means: a mean hides the 1-in-20 user who waits 8 s.
- Bigger batches raise tokens/s per GPU, but each user's TPOT grows and new prompts queue, raising TTFT.
- Raw throughput flatters you: set an attainment target (e.g. 90% within both SLOs) and cap replicas there.
- In chat, TTFT rules perceived speed; in agent steps and batch jobs, E2E and throughput matter.
Check yourself
Answer to mark it learned; your answers aren't scored.
A vendor quotes 150 ms TTFT for an engine, measured with one of your typical prompts on an idle server. On the same model and GPU under production traffic, your p95 TTFT is 2 s. Most likely cause?
Go deeper
Full explanation
An LLM response streams, so one latency number hides what users feel. Track four:
- TTFT (time to first token): request sent → first token received. Queueing + network + prefill of the whole prompt (Prefill vs decode). Grows with prompt length and load.
- TPOT / ITL (time per output token / inter-token latency): the gap between later tokens, set by decode. Per-user speed is 1/TPOT: 25 ms ≈ 40 tokens/s.
- E2E latency ≈ TTFT + TPOT × (output tokens − 1). Output length usually dominates: 500 tokens at 30 ms is 15 s, whatever the TTFT.
- Throughput: total output tokens/s (or requests/s) across all users.
Report p50/p95/p99, never means: a mean hides the 1-in-20 user waiting 8 s.
The core trade-off is batch size. Bigger batches share each weight read across more sequences, so tokens/s per GPU rise; but each sequence's TPOT grows and new prompts queue, so TTFT rises too. Raw throughput flatters you. What you sell is goodput: the highest load at which, say, 90% of requests still meet both the TTFT and TPOT targets.
The product decides which metric matters. People read ~4–7 tokens/s, so ~10+ tokens/s already outpaces reading: in chat, TTFT dominates perceived speed. In agent steps and batch jobs nobody watches the stream, so E2E and throughput matter.
Code Measure TTFT, TPOT and E2E from a stream
import time
import numpy as np
from openai import OpenAI
client = OpenAI() # or base_url=... for vLLM, SGLang, TGI (OpenAI-compatible)
MODEL = "gpt-4.1-mini" # any chat model
def measure(prompt: str) -> dict:
t0 = time.perf_counter()
first = last = usage = None
chunks = 0
stream = client.chat.completions.create(
model=MODEL, messages=[{"role": "user", "content": prompt}], stream=True,
stream_options={"include_usage": True}, # last chunk carries token counts
)
for chunk in stream:
if chunk.usage:
usage = chunk.usage
if chunk.choices and chunk.choices[0].delta.content:
last = time.perf_counter()
first = first or last # first visible token = what the user feels
chunks += 1
n_out = usage.completion_tokens if usage else chunks # a chunk can hold >1 token
ttft, e2e = first - t0, last - t0
tpot = (e2e - ttft) / max(n_out - 1, 1)
return {"ttft_s": ttft, "tpot_ms": tpot * 1e3, "e2e_s": e2e}
# Sequential = concurrency 1. For real load use vllm bench serve or NVIDIA AIPerf.
runs = [measure(p) for p in sample_prompts] # sample from production traffic
for key in ("ttft_s", "tpot_ms", "e2e_s"):
vals = [r[key] for r in runs]
print(key, {f"p{q}": round(float(np.percentile(vals, q)), 3) for q in (50, 95, 99)})Real example
Your chat SLO is p95 TTFT < 1 s and p95 TPOT < 50 ms. You load-test an 8B model on one GPU with vLLM. At 32 concurrent users: ~1,600 output tokens/s, p95 TTFT 0.4 s, TPOT 20 ms, every request within SLO. At 128 users: ~3,800 tokens/s, but long prompts queue, p95 TTFT climbs to 2.5 s and only ~70% of requests meet both targets. Throughput rose 2.4×, yet that load is past your goodput point (90% attainment, here ~64 users). You cap each replica at 64 and scale out.
Trade-offs +3 · −3
+ You gain
- Splits latency by cause: TTFT points at queueing and prefill, TPOT at decode, so you know which knob to turn.
- Goodput ties GPU count to the user-facing SLO, which makes capacity plans and cost per request honest.
- Standard across engines and tools (vllm bench serve, NVIDIA AIPerf, formerly GenAI-Perf), so you can compare vendors on equal terms.
− You pay
- Meaningless without the workload: the prompt/output length mix and concurrency change every number.
- Tokens differ by tokenizer, so tokens/s doesn't compare across model families; also track requests/s.
- Client-side numbers include network, gateway and guardrails; server-side ones miss them. You need both.
Use it when
Any LLM feature where a user waits: set TTFT and TPOT SLOs at p95/p99 before picking a model, engine or GPU, then load-test for goodput with realistic prompt and output lengths.
Avoid it when
Offline batch jobs don't care about TTFT or TPOT: optimize total throughput and cost per million tokens. Never quote single-request latency on an idle server as production performance.
Numbers to know 4
- E2E ≈ TTFT + TPOT × (output tokens − 1); per-user speed = 1/TPOT (20 ms → 50 tokens/s).
- People read ~200–300 words/min ≈ ~4–7 tokens/s; streaming at ~10+ tokens/s outpaces them.
- MLPerf Inference Llama-2-70B server limits (p99): TTFT ≤ 2 s, TPOT ≤ 200 ms; the v5.0 interactive scenario tightens them to 450 ms and 40 ms.
- Rule of thumb for chat: p95 TTFT under ~1 s and TPOT under ~50 ms (20+ tokens/s).
Common pitfalls 4
- Benchmarking one request on an idle server: under real load, TTFT is mostly queueing.
- Counting stream chunks as tokens; servers may pack several tokens per chunk. Use the usage counts.
- Watching only average TPOT: a long prefill entering the batch can freeze streams for hundreds of ms. Check ITL p99.
- Load-testing with fixed short prompts and outputs that don't match the production length distribution.
Interview questions 2
Answer out loud first, then reveal.
Users say the assistant feels slow. How do you diagnose it?Show answer
First I split the latency, client-side and server-side, into TTFT, TPOT and output length at p95. High TTFT on an idle GPU means long prompts: trim context or add prefix caching. High TTFT only under load means queueing: scale out or add admission control. High TPOT means decode is the bottleneck: batch too large or model too big, so I'd look at quantization, speculative decoding or a smaller model. If both are fine but E2E is long, the outputs are too long: cap max_tokens and prompt for brevity.
Why not just maximize tokens per second per GPU?Show answer
Because throughput and latency pull against each other through batch size. Doubling concurrency can nearly double tokens/s per GPU while TPOT and queueing push p95 TTFT past the SLO, and those extra tokens go to users who already gave up. So I set SLOs first, sweep concurrency with a realistic prompt mix, and pick the highest load where ~90% of requests still meet both targets: that's goodput. I compute cost per request at that point, not at peak throughput.