TTFT vs TPOT on vLLM and Ollama

🔧 AI Tools 2026-11-25 8 min read

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

NumberFormulaWhat is inside itWho feels it
TTFTt_first_token - t_request_sentqueue wait + prompt prefill + network + client parsingEveryone, on every message
TPOT / ITL(t_last - t_first) / (tokens_out - 1)attention over the KV cache, one token at a time, plus scheduler interleavingAnyone reading a long answer
Throughputtokens_out / wall_clockbatch size x decode speed, minus idle gapsYour 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:

MetricQuestion it answers
vllm:time_to_first_token_secondshistogram of user-facing TTFT
vllm:request_queue_time_secondshow long the request sat waiting for a slot
vllm:request_prefill_time_secondsprompt processing, i.e. the compute part of TTFT
vllm:request_decode_time_secondsgenerating tokens, i.e. the body of TPOT
vllm:request_time_per_output_token_secondsTPOT as the engine sees it
vllm:inter_token_latency_secondsjitter between tokens, not just the average
vllm:prefix_cache_hits / vllm:prefix_cache_queriesshare of prompt tokens served from cache
vllm:kv_cache_usage_percKV pressure; near 1.0 means preemption and stalled decodes
vllm:num_requests_running / vllm:num_requests_waitingbatch 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:

ReadingWhat it meansWhat to change
queue_time > prefill_timethe box is saturated; requests wait for a slotraise --max-num-seqs if VRAM allows, add a replica, or cut concurrency upstream
TTFT high, queue_time near zero, prefill_time largeprompt processing dominates: long system prompt or long contexttrim 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.0KV cache full, requests preempted and recomputedlower --max-num-seqs, lower context, quantize weights, or move to a smaller model
TPOT average fine, inter_token_latency p99 badchunked prefill is interleaving big prompts with decodescap --max-num-batched-tokens, or isolate long-prompt traffic to its own replica
prefix_cache_hits / queries low on a shared system promptcache 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:

FieldMeaning (per Ollama's API reference)
prompt_eval_countnumber of tokens in the prompt
prompt_eval_durationtime in nanoseconds spent evaluating uncached prompt tokens
eval_countnumber of tokens generated
eval_durationtime in nanoseconds spent generating them
total_durationwhole 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

Related Articles
2026-08-24
Best AI Email Marketing Tool in 2026: 6 Tools for E-commerce Brands
2026-08-17
Best AI Coding Assistant in Prague 2026: 7 Tools for Czech Dev Teams
2026-08-15
Best AI Resume Builder in Singapore 2026: 7 Tools for the SG Job Market
2026-08-17
Best AI Scheduling Assistant for Wedding Photographers 2026: 6 Tools That Book More Shoots
2026-08-20
Best AI Product Photo Generator for Wholesale in Guangzhou 2026: 6 Tools for E-commerce Exporters
2026-08-10
AI Ecommerce Tools 2026: 8 Open Source and Free Tools That Pay for Themselves

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.

💬 Comments (0)

No comments yet. Be the first!

Login to comment