Measure goodput against TTFT and TPOT SLOs

Why it matters Capacity planning for LLM APIs is done against goodput at a latency target, because raw throughput can rise while users get a worse experience.

Throughput counts every request, even slow ones. Goodput only counts requests that met the latency targets, which is what users actually feel.

Write slo_goodput(ttft, tpot, out_tokens, ttft_slo, tpot_slo, window_s). ttft and tpot are lists of seconds per request; out_tokens is the number of output tokens. A request meets the SLO if ttft <= ttft_slo and its tpot <= tpot_slo. A request with out_tokens <= 1 has no inter-token gap: its tpot is NaN and only the TTFT check applies. Return a dict {"goodput_rps": met / window_s, "attainment": met / n (0.0 when there are no requests), "good_tokens_per_s": total out_tokens of the requests that met the SLO / window_s}.

Signaturedef slo_goodput(ttft, tpot, out_tokens, ttft_slo, tpot_slo, window_s)

Example

ttft [0.2, 0.5, 0.1], tpot [0.03, 0.02, NaN], out_tokens [100, 50, 1], ttft_slo 0.3, tpot_slo 0.05, window 10 gives {"goodput_rps": 0.2, "attainment": 0.6667, "good_tokens_per_s": 10.1}.

Understand the idea

Goodput is like counting only the pizzas delivered hot. A shop can deliver 100 pizzas an hour, but if 40 arrive cold, customers feel 60. For LLM serving, hot means two things: the first token came fast enough (TTFT) and the following tokens kept a steady pace (TPOT, time per output token). Worked example: three requests in 10 seconds. One meets both targets with 100 tokens, one misses TTFT, one is a single-token reply that meets TTFT. Met = 2, goodput = 0.2 requests per second, attainment 2 / 3, good tokens 101 / 10 = 10.1 per second. Rule: good if ttft <= T1 and (tokens <= 1 or tpot <= T2). Serving benchmarks increase load until attainment drops below a target such as 90 percent and report the goodput at that point.

solution.pyPython idle
Ctrl/Cmd + Enter runs sample tests

Run checks the first 2 tests. Submit checks all 4.

  • Sample 1: exampleslo_goodput([0.2, 0.5, 0.1], [0.03, 0.02, float('nan')], [100, 50, 1], 0.3, 0.05, 10)
  • Sample 2: boundaryslo_goodput([0.3, 0.3], [0.05, 0.051], [10, 10], 0.3, 0.05, 2)
  • Test 3: noneslo_goodput([], [], [], 1.0, 1.0, 5)
  • Test 4: tpot failsslo_goodput([0.1, 0.1, 0.9, 0.2], [0.2, 0.01, 0.01, float('nan')], [20, 30, 40, 1], 0.5, 0.1, 4)