All posts
LLM Infrastructure

TTFT and TPOT: How to Measure LLM Latency on Kubernetes

TTFT and TPOT are the only two latency numbers users feel, and both are easy to measure in a way that stays green through a real incident. Where to take each one, and the stall a mean TPOT cannot see.

By Sharon Sahadevan··10 min read

Your chat product's p95 TTFT is 380 ms against an 800 ms target. p95 TPOT is 41 ms against 60 ms. Availability is 99.98 percent. And support is getting tickets that say responses freeze halfway through. Every number on the dashboard is correct, and none of them can see the problem, because each one is measured at the wrong point or averaged over the thing that went wrong.

QUICK ANSWER

TTFT (time to first token) is the time from the client sending a request to the first token arriving. It is perceived responsiveness: how long the cursor blinks.

TPOT (time per output token) is the time between tokens once the stream has started: (end-to-end latency - TTFT) / (output tokens - 1). It is how fast the text scrolls.

They are the only two latency numbers users feel, and they have different fixes. TTFT moves with queueing, admission and prefill. TPOT moves with batch size, KV cache pressure and memory bandwidth.

Two measurement mistakes make both lie. TTFT taken at the inference engine leaves out the gateway, the network and any queue in front of the engine, so it reads better than reality by exactly the amount that grows under load. And TPOT as a per-request mean absorbs a multi-second stall inside a long response without moving. Measure TTFT where the client is, and judge decode by the worst gap in each stream, not the average.

What each number is made of#

TTFT is a sum, and each term has a different owner:

  • Gateway processing and auth
  • Queue wait, before the engine admits the request into a batch
  • Prefill, which grows with prompt length
  • The first decode step

When TTFT spikes the question is always which term moved. Usually it is queue wait, and the chain behind it is KV cache usage climbing, the scheduler running out of blocks to admit new requests, and the waiting queue growing. KV cache is the cause and TTFT is the symptom.

TPOT is effectively the decode step time spread over the generation. A bigger batch raises aggregate throughput and also raises every request's TPOT, which is the trade continuous batching makes on your behalf. KV cache pressure shows up here too, as preemption: a request is evicted from the batch, waits, and resumes.

PRO TIP

Publish TTFT and TPOT as separate SLIs. They have different fix mechanisms, and a single "latency" number that blends them loses the one thing you need during an incident: which half of the request got slower.

Where vLLM starts the clock#

vLLM exports both, plus the components of TTFT, as Prometheus histograms. Port-forward to a serving pod and look at what is there:

$ kubectl -n inference port-forward deploy/vllm-llama 8000:8000 &
$ curl -s localhost:8000/metrics | grep -E '^# HELP vllm:(time_to_first_token|inter_token_latency|request_time_per_output_token|request_queue_time|e2e_request_latency)'
# HELP vllm:time_to_first_token_seconds Histogram of time to first token in seconds.
# HELP vllm:inter_token_latency_seconds Histogram of inter-token latency in seconds.
# HELP vllm:request_time_per_output_token_seconds Histogram of time_per_output_token_seconds per request.
# HELP vllm:request_queue_time_seconds Histogram of time spent in WAITING phase for request.
# HELP vllm:e2e_request_latency_seconds Histogram of e2e request latency in seconds.

The vLLM metrics design document is specific about where the TTFT clock starts: at the frontend's arrival_time, which "starts when tokenization begins". Everything before the request reaches the vLLM API server is outside the measurement. That includes your gateway, its auth and rate limiting, any queue the gateway holds, and the network path back to the client.

That is the right number for debugging the engine and the wrong number for an SLO. Under load, queueing in front of the engine is exactly the term that grows, so an engine-side TTFT gets more optimistic the more saturated you are. An SLI whose optimism is proportional to your saturation is worse than none.

Two decode metrics, and why the difference matters#

Look again at that list. vLLM exports decode latency two ways, and they answer different questions.

vllm:request_time_per_output_token_seconds is one sample per request: that request's mean TPOT. vllm:inter_token_latency_seconds is one sample per gap between consecutive tokens. Most dashboards graph the first, and it is the one that cannot see a stall.

Do the arithmetic on a 900 token response that streams at 40 ms per token except for one 4 second stall, the shape a preemption under KV pressure produces:

898 gaps x 40 ms   = 35,920 ms
  1 gap  x 4,000 ms =  4,000 ms
mean TPOT          = 39,920 ms / 899 gaps = 44.4 ms

44 ms against a 60 ms target. Green. The user watched the text stop for four seconds.

The per-gap histogram does not rescue you by default either. That stall is one gap in 899, about 0.1 percent, so the fleet's p99 inter-token latency sits at 40 ms unless more than one gap in a hundred is a stall. A percentile over gaps is not a percentile over streams. What the per-gap histogram does give you is a count: the buckets above your stall threshold count stalled gaps directly, without averaging.

# p95 TTFT as the engine sees it (excludes everything before vLLM)
histogram_quantile(0.95,
  sum by (le) (rate(vllm:time_to_first_token_seconds_bucket[5m])))

# p95 per-request mean TPOT (the one that absorbs stalls)
histogram_quantile(0.95,
  sum by (le) (rate(vllm:request_time_per_output_token_seconds_bucket[5m])))

# Gaps longer than 2.5 s per second, counted rather than averaged
sum(rate(vllm:inter_token_latency_seconds_count[5m]))
- sum(rate(vllm:inter_token_latency_seconds_bucket{le="2.5"}[5m]))

Check the bucket boundaries your version actually exports with curl -s localhost:8000/metrics | grep inter_token_latency_seconds_bucket before you pick the le value, since a threshold has to sit on a boundary.

If your dashboards came from an older vLLM, check the names too. vllm:gpu_cache_usage_perc and vllm:time_per_output_token_seconds do not appear in the current metrics documentation; KV cache usage is vllm:kv_cache_usage_perc.

Measure from the client side once#

The fastest way to see how far the engine's numbers are from the user's is to run the same load through both paths. vllm bench serve measures from the client, streaming, and reports TTFT, TPOT and ITL separately, with TPOT computed "excluding the first token" and ITL as "the time between consecutive streamed outputs":

# Straight at the engine, bypassing the gateway
$ kubectl -n inference port-forward svc/vllm-llama 8000:8000 &
$ vllm bench serve --backend openai-chat --endpoint /v1/chat/completions \
    --base-url http://localhost:8000 --model meta-llama/Llama-3.1-70B-Instruct \
    --dataset-name random --num-prompts 500 --request-rate 8 \
    --percentile-metrics ttft,tpot,itl --metric-percentiles 95,99

# The same run through the path your users take
$ vllm bench serve --backend openai-chat --endpoint /v1/chat/completions \
    --base-url https://llm.example.internal --model meta-llama/Llama-3.1-70B-Instruct \
    --dataset-name random --num-prompts 500 --request-rate 8 \
    --percentile-metrics ttft,tpot,itl --metric-percentiles 95,99

Compare P99 TTFT (ms) between the two runs. The difference is your gateway, its queue and the network, which is the part the engine's histogram will never report. Then compare P99 ITL (ms). If ITL through the gateway is near zero while TTFT is close to the full generation time, something on the path is buffering the response, which brings us to the cheapest fix.

The fixes, cheapest first#

1. Turn off response buffering on every hop. A proxy that accumulates the response before forwarding destroys your measurement and your product at once. Every token appears to arrive together, the maximum gap becomes zero, TTFT becomes the whole generation time, and streaming quietly stops being streaming.

location /v1/ {
    proxy_pass http://inference-gateway;
    proxy_buffering off;          # without this, streaming is not streaming
    proxy_read_timeout 300s;      # a long generation is not an idle connection
}

Check the ingress controller and any mesh sidecar as well as your own proxy. The symptom is slowness rather than breakage, so it survives review. And set idle timeouts against the longest acceptable gap between tokens, not against total response time, or a long generation gets cut mid-stream and the client sees a truncated answer instead of an error.

2. Graph both decode metrics. Keep per-request mean TPOT for sustained degradation, the replica at a huge batch delivering a slow, perfectly regular stream. Add the count of inter-token gaps over your stall threshold, which catches the freeze the mean absorbs. Both already exist in /metrics; this is a dashboard change.

3. Take TTFT at the gateway. Start the clock when the gateway accepts the request and stop it when the first content frame is flushed to the client socket. That interval covers auth, queue wait, admission, prefill and the first decode step, which is what the user experiences. Keep the engine's TTFT next to it: the gap between the two lines is your queue, and watching it widen is how you see saturation coming.

4. Record one line per stream at the gateway. Aggregates cannot tell you that one stream stalled. A per-stream record can:

{"req_id":"9f2c","model":"llama-70b","ttft_ms":412,"tokens_out":734,
 "mean_tpot_ms":38,"max_gap_ms":2310,"gaps_over_2s":1,
 "finish_reason":"stop","terminated_by":"server","good":false}

Fast start, healthy mean, one 2.3 second gap. No histogram would have surfaced it. Recording the maximum gap and a count of gaps over threshold costs two numbers per request rather than a series per token. Recording terminated_by lets you tell a user who stopped reading from a server that cut the stream, which is cheap to capture at the time and impossible to reconstruct later.

5. Make the SLI a verdict per stream. A request is good only if TTFT, maximum gap and mean TPOT are all under threshold and the stream ended with a finish reason. That conjunction turns a response that degrades continuously back into one boolean per request, which is what error budget arithmetic needs. HTTP status cannot do this job for streaming: the 200 is sent with the first token, so everything that goes wrong afterwards has already been counted as success.

WAR STORY

A team ran a chat product through a four hour degradation with every dashboard green. Availability was 100 percent because every request returned 200. TTFT p95 was inside target because prefill was cache-warm. Mean TPOT p95 was 44 ms against a 60 ms target. The incident was found through support tickets. The cause was KV pressure on a subset of replicas producing preemption stalls: affected streams delivered a burst of tokens, stopped for three to five seconds, then resumed. They added max inter-token gap to the gateway record that week, and the same failure now shows up in the good-stream ratio within minutes.

In production#

Publish TTFT measured where your user is, never at the engine, and judge decode by the worst gap in each stream rather than the average across it. The engine's histograms are for finding which component moved. The gateway's per-stream record is for knowing whether anyone noticed.

For where these numbers lead once you have them, see why continuous batching trades TPOT for throughput, scaling on queue depth and KV cache rather than CPU, and what happens when KV cache fills.

TTFT, TPOT and the metrics that lead them are in module 1 of Production LLM Inference on Kubernetes, whose first lessons are free.

More in LLM Infrastructure

LLM Infrastructure··12 min read

You Changed the Prompt. Is the Model Better or Worse? You Don't Have a Test That Tells You.

Operating an LLM in production is not MLOps and it is not traditional ops. It is running a non-deterministic component with no ground-truth notion of 'correct,' where a one-line prompt edit is a deploy and there is no green checkmark that says it's safe to ship. The operational surface that replaces the unit test: evals as your test suite, prompts and model versions as deployable config, RAG freshness, observability for systems that have no 'wrong answer' to alert on, and rollout you can't fully validate offline.

Read post