TTFT vs TPOT on vLLM and Ollama
Users call the endpoint slow, GPU utilization is high, and nobody can say whether the wait is before the first token or between tokens.
📜 Table of Contents
📖 Keep reading
Two people say your endpoint is slow and they mean different things. One waits four seconds before the first word appears, then reads fast. The other sees the first word in half a second but the paragraph crawls out at nine tokens a second. Optimizing "latency" without separating those two cases is how teams spend a week on quantization and shave nothing off what users feel.
Time to first token (TTFT) is the wait before anything appears. Time per output token (TPOT, also called inter-token latency) is the pace afterwards. They are produced by different parts of the stack, and on a self-hosted vLLM or Ollama server you can read both without a commercial APM: one from a client-side stream, one from the server's own metrics.
What each number is actually made of
| Number | Formula | What is inside it | Who feels it |
|---|---|---|---|
| TTFT | t_first_token - t_request_sent | queue wait + prompt prefill + network + client parsing | Everyone, on every message |
| TPOT / ITL | (t_last - t_first) / (tokens_out - 1) | attention over the KV cache, one token at a time, plus scheduler interleaving | Anyone reading a long answer |
| Throughput | tokens_out / wall_clock | batch size x decode speed, minus idle gaps | Your bill, not your users |
A 20-token answer is almost all TTFT. A 900-token answer is almost all TPOT. If you benchmark with max_tokens=16 and then wonder why long answers feel slow, the harness measured the wrong half.
Step 1: measure from the client, in 40 lines
The client is the only place that sees what a user sees. This script streams a chat completion, timestamps the first content chunk, and computes both numbers. It works against any OpenAI-compatible endpoint, vLLM included.
import json, time, statistics, requests
URL = "http://127.0.0.1:8000/v1/chat/completions"
PROMPT = "List five failure modes of vector search indexes, one line each."
def one_run(max_tokens=300):
t0 = time.perf_counter()
r = requests.post(URL, stream=True, timeout=300, json={
"model": "your-served-model",
"messages": [{"role": "user", "content": PROMPT}],
"max_tokens": max_tokens,
})
t_first = None
chunks = 0
for line in r.iter_lines():
if not line or not line.startswith(b"data: "):
continue
payload = line[6:]
if payload == b"[DONE]":
break
obj = json.loads(payload)
delta = obj["choices"][0]["delta"].get("content") or ""
if delta and t_first is None:
t_first = time.perf_counter()
chunks += 1
t_last = time.perf_counter()
ttft_ms = (t_first - t0) * 1000
tpot_ms = (t_last - t_first) * 1000 / max(chunks - 1, 1)
return ttft_ms, tpot_ms, chunks
for _ in range(2): # warm-up: model load, CUDA graphs, cold prefix cache
one_run(16)
runs = [one_run() for _ in range(5)]
print("TTFT ms p50=%.0f p95=%.0f" % (statistics.median(r[0] for r in runs),
max(r[0] for r in runs)))
print("TPOT ms p50=%.1f" % statistics.median(r[1] for r in runs))
print("chunks per run:", [r[2] for r in runs])
Two details decide whether the number is meaningful. First, count content deltas, not SSE lines: the first few chunks often carry a role field and no text, and counting those as tokens makes TPOT look better than it is. Second, chunk count approximates tokens only for models that emit one token per chunk; when in doubt, read usage.completion_tokens from the final chunk (add "stream_options": {"include_usage": true}) and divide by that.
Step 2: read the server, so you know which half is slow
vLLM 0.34.0 (released 2026-11-16) exposes Prometheus metrics from the OpenAI-compatible server at /metrics. The names below come from vllm/v1/metrics/loggers.py at that tag, not from a blog post:
| Metric | Question it answers |
|---|---|
vllm:time_to_first_token_seconds | histogram of user-facing TTFT |
vllm:request_queue_time_seconds | how long the request sat waiting for a slot |
vllm:request_prefill_time_seconds | prompt processing, i.e. the compute part of TTFT |
vllm:request_decode_time_seconds | generating tokens, i.e. the body of TPOT |
vllm:request_time_per_output_token_seconds | TPOT as the engine sees it |
vllm:inter_token_latency_seconds | jitter between tokens, not just the average |
vllm:prefix_cache_hits / vllm:prefix_cache_queries | share of prompt tokens served from cache |
vllm:kv_cache_usage_perc | KV pressure; near 1.0 means preemption and stalled decodes |
vllm:num_requests_running / vllm:num_requests_waiting | batch state right now |
curl -s localhost:8000/metrics | grep -E 'vllm:(time_to_first_token|request_prefill_time|request_queue_time|kv_cache_usage|num_requests_(running|waiting))'
Histograms need histogram_quantile, not an eyeballed average. A five-line Prometheus scrape config gets you p50 and p95 per metric:
scrape_configs:
- job_name: vllm
metrics_path: /metrics
static_configs:
- targets: ["127.0.0.1:8000"]
# then, in Grafana or a query:
histogram_quantile(0.95, rate(vllm:time_to_first_token_seconds_bucket[5m]))
Step 3: subtract, and the fix picks itself
On the engine side, request_queue_time_seconds + request_prefill_time_seconds covers most of the client's TTFT; the remainder is network and client parsing. Decode time divided by output tokens is TPOT. Once you have all four, the diagnosis is mechanical:
| Reading | What it means | What to change |
|---|---|---|
| queue_time > prefill_time | the box is saturated; requests wait for a slot | raise --max-num-seqs if VRAM allows, add a replica, or cut concurrency upstream |
| TTFT high, queue_time near zero, prefill_time large | prompt processing dominates: long system prompt or long context | trim the prompt, enable --enable-prefix-caching for a shared preamble, lower --max-num-batched-tokens only if TTFT matters more than throughput |
| TPOT high, kv_cache_usage_perc near 1.0 | KV cache full, requests preempted and recomputed | lower --max-num-seqs, lower context, quantize weights, or move to a smaller model |
| TPOT average fine, inter_token_latency p99 bad | chunked prefill is interleaving big prompts with decodes | cap --max-num-batched-tokens, or isolate long-prompt traffic to its own replica |
| prefix_cache_hits / queries low on a shared system prompt | cache is off or the prefix is not stable (timestamps, user IDs at the top) | enable prefix caching, move volatile fields to the end of the prompt |
One trap worth naming: chunked prefill. In vLLM 0.34.0 the --enable-chunked-prefill flag defaults to None, and the engine then uses model_config.is_chunked_prefill_supported. Whether it is on depends on the model and runner, so do not assume it from an old guide. It trades decode smoothness for TTFT under mixed load: it lets a long prompt start producing sooner while keeping the batch busy, and it is exactly why a single long request can make everyone else's TPOT wobble. Check the startup log line that says whether chunked prefill and prefix caching were enabled, and record it next to your numbers.
Ollama: the fields are in the response already
Ollama does not need Prometheus for a first look. Its API returns the split you need in the final chunk of a stream:
| Field | Meaning (per Ollama's API reference) |
|---|---|
prompt_eval_count | number of tokens in the prompt |
prompt_eval_duration | time in nanoseconds spent evaluating uncached prompt tokens |
eval_count | number of tokens generated |
eval_duration | time in nanoseconds spent generating them |
total_duration | whole request, including model load when the model was not resident |
That gives you server-side TPOT as eval_count / eval_duration * 1e9 (the formula in Ollama's own docs) and a server-side prefill speed as prompt_eval_count / prompt_eval_duration * 1e9. Two caveats matter more than the formula. The word uncached is load-bearing: with a repeated prompt, re-measured prefill collapses toward zero while real TTFT does not, because the client still waits for the network round trip and the first sampled token. And keep_alive defaults to 5m, so a model that unloaded between tests makes the first run include weight loading; check /api/ps before you trust a number, and repeat the run so the second one is warm.
What not to conclude from a single number
Concurrency is the biggest source of misleading measurements. A TTFT of 300 ms at concurrency 1 tells you nothing about what your users get at 20 concurrent chats, because the queue time that appears at load is invisible when you are the only client. Run the harness at the concurrency you actually expect, and read the server histograms at the same time. Likewise, changing prompt length between runs changes prefill time; keep the prompt fixed and vary one input at a time.
If you are still choosing the serving stack, the memory side of these numbers is covered in the KV cache and concurrency tables and in the VRAM fit table; if you are paying per token instead of per GPU, the agent loop cost breakdown is the more relevant comparison.
Checklist
- Warm up twice, then measure; discard the first run after a model load.
- Count content deltas or read
usage.completion_tokens; never count SSE lines. - Report TTFT and TPOT separately, at the concurrency you expect in production.
- Read queue, prefill and decode times from the server before changing any flag.
- Log whether prefix caching and chunked prefill were on; they change the numbers more than most model swaps.
- Use p95 from
histogram_quantile, not the average.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.