AI engineering and inferenceLoading progress…

Throughput and goodput

Trace a generation request through prefill and decode and distinguish latency, throughput and hardware bottlenecks.

Throughput versus goodput

Throughput is completed work per unit time over a workload, for example tokens per second summed over all requests. Goodput counts only the work that meets a stated service objective. Putting more requests in one batch usually raises the total, because the weights are read once for all of them, but each request then gets its tokens more slowly.

per-request objective (tokens/s)10
batchstep (s)aggregate tokens/seach requestmeets objective?
10.0520
20yes
20.0633.3
16.7yes
30.0742.9
14.3yes
40.0850
12.5yes
50.0955.6
11.1yes
60.160
10yes
70.1163.6
9.1no
80.1266.7
8.3no
90.1369.2
7.7no
100.1471.4
7.1no
step time = 0.05 + 0.01·(b − 1) s (a toy model) throughput counts all tokens/s; goodput counts only the work that meets the objective (here: batches where every request gets ≥ the objective).
A toy model where each extra sequence adds 10 ms to a step. Change the per-request objective.

Predict first. Can batching raise aggregate throughput while delaying one request?

Chapter context

An autoregressive model first processes a prompt, then generates tokens whose identities determine later steps. Prefill and decode often have different hardware behavior, so a single tokens-per-second number does not describe the whole request.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

For roughly steady output gaps:

Trequest≈TTFT+(nout−1) ITL.T_{request}\approx TTFT+(n_{out}-1)\,ITL.

For a simplified single-sequence dense weight scan, FLOPs≈2N and weight bytes≈Nb, giving arithmetic intensity≈2/b FLOPs per byte. This excludes activations, KV traffic and other work.

Worked example

A fictional request has TTFT=0.20 seconds and then emits four more tokens at 0.05-second intervals. Five outputs finish in 0.20+4×0.05=0.40 seconds. Steady decode rate is 1/0.05=20 tokens/second; total request output rate is 5/0.40=12.5 tokens/second. Both are valid measurements with different definitions.

Reference code

The following example uses the Python standard library and does not call a remote service.

from math import isclose
first,gap,count=.2,.05,5
elapsed=first+(count-1)*gap
assert isclose(elapsed,.4)
assert 1/gap == 20
assert isclose(count/elapsed,12.5)
assert 2/2 == 1

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

An average latency hides tail behavior. Prefill/decode bottlenecks depend on batch and shapes, not only phase names. Compare metric definitions before comparing serving engines.