Education › Inference › Stage 3: Analysing inference performance

Latency and throughput metrics

TTFT, TPOT, inter-token latency, goodput and percentiles — and where each kind of bottleneck shows up.

Intermediate ~30 min read Module 5 of 15

"Is it fast?" has at least five different answers for an LLM service, and optimising the wrong one is the most common mistake in inference work. This lesson defines the metrics precisely (time to first token, time per output token, inter-token latency, end-to-end latency, throughput and goodput), shows how to compute them from timestamps, explains why percentiles matter more than averages, and maps each kind of bottleneck to the metric it damages.

After this module you can
  • Define TTFT, TPOT, ITL, end-to-end latency, throughput and goodput precisely
  • Compute those metrics from request and token timestamps
  • Explain the throughput versus latency trade-off as concurrency rises
  • Use percentiles and say where measurements should be taken
  • Map queueing, prefill, decode, memory and CPU bottlenecks to the metrics they hurt

The latency metrics

MetricDefinitionDriven mostly by
TTFT (time to first token)Request sent to first output token receivedQueue wait + prefill
TPOT (time per output token)(end-to-end - TTFT) / (output tokens - 1), per requestDecode step time, batch size
ITL (inter-token latency)Each gap between consecutive streamed tokensDecode steps, interference from prefill
E2E latencyRequest sent to last token receivedAll of the above x output length

TPOT and ITL are close relatives. TPOT is one average number per request; ITL is the whole distribution of gaps, which exposes stalls: a stream that usually ticks every 20 ms but freezes for 400 ms while the engine prefills someone else's long prompt has a fine average TPOT and a terrible ITL tail. Users read that freeze as the service hanging.

Metrics from client-side timestamps for one streamed request
python
def request_metrics(t_sent, token_times):
    """t_sent: request start; token_times: arrival time of each streamed token."""
    ttft = token_times[0] - t_sent
    e2e = token_times[-1] - t_sent
    n = len(token_times)
    tpot = (e2e - ttft) / (n - 1) if n > 1 else 0.0
    itl = [b - a for a, b in zip(token_times, token_times[1:])]
    return {"ttft": ttft, "tpot": tpot, "e2e": e2e, "itl": itl}

Throughput, goodput and the trade-off

Throughput is work per unit time: output tokens per second (the usual headline), total tokens per second, or requests per second. Per GPU is the number that maps to cost. Goodput is throughput that meets your latency targets, for example requests per second completed with TTFT under 500 ms and TPOT under 50 ms. A configuration that doubles throughput by blowing through the latency target has improved nothing users care about.

As you raise concurrency, batches get bigger: throughput climbs because each weight read serves more requests, but every request's decode step gets slower and queues start forming, so TTFT and TPOT rise. Plotted as throughput against latency, every engine and configuration traces a curve, and the right operating point is the highest throughput that still meets the latency SLO.

Tip

Never report a throughput number without the concurrency or request rate, the input and output lengths, and the latency percentiles it was measured at. Without those, the number is not comparable to anything.

Percentiles and where to measure

  • Report p50, p90 and p99, not the mean. LLM latency distributions have long tails from queueing, long prompts and preemption.
  • Client-side measurement includes network and the gateway; it is what users feel and what SLOs should use.
  • Server-side engine metrics (histograms for TTFT and inter-token latency) isolate the engine, which is what you tune.
  • A large gap between the two points at the network, a gateway, or the client's own processing.
  • Measure under the real mix of input and output lengths; a benchmark of 128-token prompts says little about a RAG app with 6,000-token prompts.

A worked example: reading one benchmark run

Suppose a benchmark at concurrency 16 reports p50 TTFT of 180 ms, p99 TTFT of 2.1 s, p50 TPOT of 24 ms and p99 TPOT of 31 ms, with 2,900 output tokens per second. The decode numbers are tight, so steady-state generation is healthy: at 24 ms per token each user sees roughly 40 tokens per second, faster than anyone reads. The trouble is the TTFT tail. A p99 more than ten times the median means a minority of requests waited a long time before starting.

There are two usual explanations, and the other metrics tell them apart. If waiting requests climbed during the run, capacity ran short at moments of burst and requests queued: add replicas, or admit fewer requests per replica and scale out earlier. If the slow requests were the ones with the longest prompts, prefill itself is the cost: prefix caching, chunked prefill, a faster GPU for prefill, or eventually disaggregated prefill are the levers. Look at TTFT broken down by input length before choosing.

Now rerun at concurrency 32. If throughput rises to 3,600 tokens per second but p99 TPOT jumps to 58 ms, you have crossed a 50 ms streaming target: the extra throughput is not goodput. The operating point for this configuration sits somewhere between 16 and 32 concurrent requests per replica, and that number, not the peak throughput, is what you feed into capacity planning and autoscaling thresholds.

Bottlenecks and their fingerprints

BottleneckMetric it hurtsFingerprint
Queueing (not enough capacity)TTFTWaiting requests grow; TTFT rises while TPOT is steady
Prefill computeTTFT, ITL tailTTFT tracks prompt length; stalls in other streams during long prefills
Decode bandwidth / large batchTPOTTPOT rises with concurrency; GPU memory traffic saturated
KV-cache memoryTTFT, tail latencyCache usage near full; preemptions
CPU (tokenizer, scheduler, HTTP)EverythingCPU pegged, GPU underused
Network or gatewayClient-side onlyServer metrics fine, client metrics poor

With these fingerprints you can read most incidents from a dashboard of four panels: TTFT and TPOT percentiles, running versus waiting requests, KV-cache usage, and throughput. The observability lesson builds exactly that.

Hands-on practice

Measure the curve yourself

  1. Serve a small model with any OpenAI-compatible engine.
  2. Write a client (or adapt the function above) that sends streamed requests and records TTFT, TPOT, ITL and E2E per request.
  3. Run 50 requests at concurrency 1, 4, 16 and 32 with fixed input (about 500 tokens) and output (about 200 tokens) lengths.
  4. For each level, compute output tokens per second and p50/p99 of TTFT and TPOT.
  5. Plot throughput against p99 TPOT and mark the highest point under a 50 ms TPOT target: that is your goodput operating point.
  6. Repeat one level with 4,000-token prompts and compare ITL tails.
Cheat sheet

Latency and throughput metrics — at a glance

Main things to focus on

  • TTFT = queue + prefill; TPOT and ITL = decode behaviour.
  • ITL distribution reveals stalls that average TPOT hides.
  • Goodput (throughput within SLO) beats raw throughput.
  • More concurrency: more throughput, worse latency; pick the point on the curve.
  • Report percentiles with lengths and concurrency, or the number means nothing.
  • SLOs from the client side; tuning from engine metrics.

Definitions

TTFT = t_first_token - t_sentResponsiveness
TPOT = (E2E - TTFT) / (n_out - 1)Average decode speed per request
ITL_i = t_token[i+1] - t_token[i]Each streaming gap
E2E = t_last_token - t_sentWhole request
tokens/s per user ~ 1 / TPOTStreaming speed a user sees

Throughput

output tok/s = sum(n_out) / wall_timeHeadline throughput
tok/s per GPUThe number that maps to cost
goodput = requests/s meeting all SLOsThroughput users benefit from

Reporting checklist

input / output length distributionAlways state it
concurrency or request rateLoad level of the run
p50 / p90 / p99Percentiles, not means
client-side vs server-sideWhere it was measured

Fingerprints

TTFT up, TPOT flatQueueing: add capacity
TPOT up with concurrencyDecode saturation: smaller batch or more GPUs
ITL spikesPrefill interference: chunked prefill or disaggregation

Common pitfalls

  • Optimising average latency while p99 users wait seconds.
  • Quoting tokens per second without lengths, concurrency or percentiles.
  • Benchmarking with short synthetic prompts when production prompts are long.
  • Raising throughput past the point where latency targets break.
  • Setting SLOs on server metrics that ignore the gateway and network.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →