<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Latency on vishctl</title><link>https://vishctl.dev/tags/latency/</link><description>Recent content in Latency on vishctl</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 17 Nov 2026 09:00:00 +0800</lastBuildDate><atom:link href="https://vishctl.dev/tags/latency/index.xml" rel="self" type="application/rss+xml"/><item><title>Speculative Decoding, Simply: A Small Model Guesses, the Big Model Checks</title><link>https://vishctl.dev/posts/speculative-decoding-draft-model-explained/</link><pubDate>Tue, 17 Nov 2026 09:00:00 +0800</pubDate><guid>https://vishctl.dev/posts/speculative-decoding-draft-model-explained/</guid><category>speculative-decoding</category><category>inference</category><category>vllm</category><category>latency</category><category>ai-infra</category><description>A simple, diagram-first guide to speculative decoding: why checking tokens is cheaper than writing them, how acceptance rate decides the speedup, when it makes serving slower, and how to turn it on in vLLM.</description><content:encoded><![CDATA[<p>A large model writes one token per pass. Every token costs a full trip through billions of weights, even an obvious one like the closing bracket of a JSON object.</p>
<p>Speculative decoding asks a simple question: what if something cheap guessed the easy tokens, and the large model only had to check them?</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Normal decoding      = the big model writes every token itself, one pass per token
</span></span><span class="line"><span class="cl">Speculative decoding = a small model drafts a few tokens, the big model checks them in one pass
</span></span></code></pre></div><figure class="mermaid-figure">
  <div class="mermaid">flowchart TD
    subgraph NORMAL["Normal decoding"]
        direction LR
        N1["Big pass<br/>token 1"] n1@--> N2["Big pass<br/>token 2"]
        N2 n2@--> N3["...and<br/>so on"]
        N3 n3@--> N4["5 tokens<br/>5 big passes"]
    end

    subgraph SPEC["Speculative decoding"]
        direction LR
        S1["Small model<br/>drafts 5 tokens"] s1@--> S2["Big model<br/>checks all 5<br/>in 1 pass"]
        S2 s2@--> S3["4 tokens kept<br/>1 big pass"]
    end

    NORMAL ~~~ SPEC
    n1@{ animate: true }
    n2@{ animate: true }
    n3@{ animate: true }
    s1@{ animate: true }
    s2@{ animate: true }

    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef tree fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    class N1,N2,N3,N4 warn;
    class S1 tree;
    class S2,S3 gpu;</div>
  <figcaption>Top: five tokens cost five big-model passes. Bottom: a small model drafts five tokens, and one big-model pass checks them all.</figcaption>
</figure>

<p>The surprising part is the guarantee: done properly, <strong>the output is the same as what the big model would have written alone.</strong> This is a speed trick, not a quality trade.</p>
<p>This post explains why that works, how much it helps, and when it makes things worse.</p>
<h2 id="why-checking-is-cheaper-than-writing">Why checking is cheaper than writing</h2>
<p>A model writes slowly because each token depends on the one before it. It cannot start token 5 until token 4 exists.</p>
<p>Checking has no such problem. If someone hands the model five tokens, it can score all five positions <strong>in a single pass</strong>, the same way it reads a whole prompt at once during <a href="https://vishctl.dev/posts/llm-basics-visual-guide/">prefill</a>.</p>
<p>Think of a senior engineer and a junior engineer:</p>
<ul>
<li><strong>Writing a runbook from scratch</strong> takes the senior engineer an hour.</li>
<li><strong>Reviewing the junior&rsquo;s draft</strong> takes ten minutes, and most lines are fine.</li>
</ul>
<p>The senior still decides every line. They just do not have to type the obvious ones.</p>
<h2 id="one-round-step-by-step">One round, step by step</h2>
<p>Suppose the model is finishing this sentence: <em>&ldquo;The pod is in&hellip;&rdquo;</em></p>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart LR
    D["Draft<br/>5 tokens"] r1@--> V["Verify<br/>1 big pass"]
    V r2@--> A["Accept<br/>first 3"]
    A r3@--> F["Fix<br/>token 4"]
    F r4@--> N["Next round<br/>starts here"]

    r1@{ animate: true }
    r2@{ animate: true }
    r3@{ animate: true }
    r4@{ animate: true }

    classDef tree fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef input fill:#13264a,stroke:#38bdf8,color:#e6f6ff,stroke-width:2px;
    class D tree;
    class V,A gpu;
    class F warn;
    class N input;</div>
  <figcaption>One round. The small model drafts five tokens. The big model agrees with the first three, rejects the fourth, and supplies its own.</figcaption>
</figure>

<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Step</th>
            <th scope="col">What happens</th>
            <th scope="col">Tokens so far</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1. Draft</td>
            <td>Small model proposes: <code>Crash</code> <code>Loop</code> <code>BackOff</code> <code>status</code> <code>now</code></td>
            <td>0 confirmed</td>
        </tr>
        <tr>
            <td>2. Verify</td>
            <td>Big model scores all five positions in one pass</td>
            <td>0 confirmed</td>
        </tr>
        <tr>
            <td>3. Accept</td>
            <td>It agrees with <code>Crash</code> <code>Loop</code> <code>BackOff</code></td>
            <td>3 confirmed</td>
        </tr>
        <tr>
            <td>4. Fix</td>
            <td>It disagrees with <code>status</code>, and writes <code>state</code> instead</td>
            <td>4 confirmed</td>
        </tr>
    </tbody>
  </table>
</div>
<p>The fifth draft token is thrown away, because it was built on a token that got rejected.</p>
<p>Result: <strong>four tokens for the price of one big pass</strong>, plus five cheap small ones. The worst case is also safe: if the very first draft token is wrong, the big model still supplies one correct token, so the round is never wasted.</p>
<h3 id="why-the-output-does-not-change">Why the output does not change</h3>
<p>In step 3, the big model is not &ldquo;trusting&rdquo; the draft. It computes what it would have produced at each position, and a draft token only survives if it passes that test.</p>
<p>With greedy decoding, the test is simply &ldquo;is this the token I would have picked?&rdquo;. With sampling, a slightly cleverer accept-or-reject rule is used so that the final text follows the big model&rsquo;s probabilities exactly.</p>
<p>vLLM&rsquo;s documentation describes its implementation as theoretically lossless, within the limits of floating-point precision. Tiny numeric differences are possible, as they are whenever batch sizes change. Token log probabilities are the exception: vLLM does not guarantee they stay stable with speculation on.</p>
<h2 id="the-number-that-decides-everything-acceptance-rate">The number that decides everything: acceptance rate</h2>
<p>The <strong>acceptance rate</strong> is how often the big model agrees with a drafted token. It decides how many tokens each big pass yields.</p>
<p>With a draft length of 5:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Acceptance rate</th>
            <th scope="col">Tokens per big-model pass</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>50%</td>
            <td>1.97</td>
        </tr>
        <tr>
            <td>70%</td>
            <td>2.94</td>
        </tr>
        <tr>
            <td>80%</td>
            <td>3.69</td>
        </tr>
        <tr>
            <td>90%</td>
            <td>4.69</td>
        </tr>
    </tbody>
  </table>
</div>
<p>Those are not the speedup yet. Drafting is cheap, but it is not free.</p>
<h3 id="speedup-after-paying-for-the-drafts">Speedup, after paying for the drafts</h3>
<p>Assume one small-model pass costs 10% of a big-model pass:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Acceptance rate</th>
            <th scope="col">Draft 3 tokens</th>
            <th scope="col">Draft 5 tokens</th>
            <th scope="col">Draft 8 tokens</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>50%</td>
            <td>1.44x</td>
            <td>1.31x</td>
            <td>1.11x</td>
        </tr>
        <tr>
            <td>70%</td>
            <td>1.95x</td>
            <td>1.96x</td>
            <td>1.78x</td>
        </tr>
        <tr>
            <td>80%</td>
            <td>2.27x</td>
            <td>2.46x</td>
            <td>2.40x</td>
        </tr>
        <tr>
            <td>90%</td>
            <td>2.65x</td>
            <td>3.12x</td>
            <td>3.40x</td>
        </tr>
    </tbody>
  </table>
</div>
<p>Read across the 50% row. <strong>Drafting more tokens made it slower.</strong> When the small model is often wrong, long drafts are mostly wasted work.</p>
<p>Now read the 90% row. Long drafts pay off, because most of them survive.</p>
<h3 id="the-draft-model-must-be-much-smaller">The draft model must be much smaller</h3>
<p>Hold acceptance at 70% and draft length at 5, and change only how expensive the small model is:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Small model cost (share of a big pass)</th>
            <th scope="col">Speedup</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>2%</td>
            <td>2.67x</td>
        </tr>
        <tr>
            <td>10%</td>
            <td>1.96x</td>
        </tr>
        <tr>
            <td>25%</td>
            <td>1.31x</td>
        </tr>
        <tr>
            <td>50%</td>
            <td>0.84x</td>
        </tr>
    </tbody>
  </table>
</div>
<p>At 50%, speculative decoding is <strong>slower than doing nothing</strong>. A draft model that is half the size of the target is not a draft model. A common starting point is a model roughly ten times smaller, from the same family, so it guesses in a similar style.</p>
<p>These tables come from a simplified formula that treats every token as an independent coin flip. Real text is burstier than that, so treat the numbers as the shape of the trade-off, not a forecast.</p>
<h2 id="not-every-draft-needs-a-second-model">Not every draft needs a second model</h2>
<p>&ldquo;A small model drafts&rdquo; is the classic version. The draft can come from other places too.</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Draft source</th>
            <th scope="col">How it guesses</th>
            <th scope="col">Best for</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Draft model</td>
            <td>A separate small LLM</td>
            <td>General text, when a good small sibling exists</td>
        </tr>
        <tr>
            <td>N-gram, or prompt lookup</td>
            <td>Copies a run of tokens that already appears in the prompt</td>
            <td>Editing, summarizing, RAG answers that quote the context</td>
        </tr>
        <tr>
            <td>Extra prediction heads</td>
            <td>Small layers added to the big model itself, such as EAGLE</td>
            <td>Highest speedups, but needs heads trained for that exact model</td>
        </tr>
    </tbody>
  </table>
</div>
<p>The n-gram method deserves attention because it costs almost nothing. If you ask a model to fix one line in a 200-line file, most of the output is a copy of the input. Guessing &ldquo;the next tokens are the same as in the prompt&rdquo; is right most of the time.</p>
<p>vLLM rates n-gram gains as low to medium. The price is also close to zero, with no second model to load.</p>
<h2 id="when-it-helps-and-when-it-hurts">When it helps and when it hurts</h2>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Situation</th>
            <th scope="col">Effect</th>
            <th scope="col">Why</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Code, JSON, structured text</td>
            <td>Helps a lot</td>
            <td>Predictable tokens mean high acceptance</td>
        </tr>
        <tr>
            <td>Editing or quoting the prompt</td>
            <td>Helps, even with n-gram</td>
            <td>The answer repeats the input</td>
        </tr>
        <tr>
            <td>Creative writing, high temperature</td>
            <td>Helps little</td>
            <td>The next token is a toss-up, so drafts miss</td>
        </tr>
        <tr>
            <td>One user, latency matters</td>
            <td>Helps</td>
            <td>Spare GPU time is turned into speed</td>
        </tr>
        <tr>
            <td>Busy server near saturation</td>
            <td>Can hurt</td>
            <td>Draft work competes with real requests for the same GPU</td>
        </tr>
        <tr>
            <td>Tight GPU memory</td>
            <td>Can hurt</td>
            <td>The draft model takes memory away from the KV cache</td>
        </tr>
    </tbody>
  </table>
</div>
<p>The last two rows are the ones that surprise people in production.</p>
<p>Speculative decoding spends extra compute to save time. On a quiet GPU, that compute was idle anyway. On a GPU that is already full, every wasted draft token is work taken from another user, so total throughput can go <strong>down</strong>.</p>
<p>And a draft model is not free to hold. Its weights and its own KV cache come out of the same memory budget described in the <a href="https://vishctl.dev/posts/llm-gpu-memory-sizing-weights-kv-cache/">GPU memory sizing guide</a>.</p>
<h2 id="what-it-does-to-your-metrics">What it does to your metrics</h2>
<p>If you track the numbers from my <a href="https://vishctl.dev/posts/llm-inference-metrics-ttft-tpot-throughput-goodput/">inference metrics guide</a>, expect this:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Metric</th>
            <th scope="col">What changes</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>TTFT</td>
            <td>About the same. The first token still needs a full prefill</td>
        </tr>
        <tr>
            <td>TPOT</td>
            <td>Improves, by roughly the speedup factor</td>
        </tr>
        <tr>
            <td>ITL</td>
            <td>Gets bursty. Several tokens can arrive in one chunk, then a pause</td>
        </tr>
        <tr>
            <td>Throughput at low load</td>
            <td>Improves</td>
        </tr>
        <tr>
            <td>Throughput at high load</td>
            <td>May get worse. Measure it</td>
        </tr>
    </tbody>
  </table>
</div>
<p>That ITL row is why TPOT and ITL can disagree. A stream that delivers four tokens at once and then waits looks fast on average and uneven up close.</p>
<h2 id="try-it-the-math-in-a-script">Try it: the math in a script</h2>
<p>This script produces the tables above and checks the formula against a simulation. It uses only the Python standard library.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="ch">#!/usr/bin/env python3</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;&#34;&#34;spec_decode.py: how much does speculative decoding help?&#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">random</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">tokens_per_round</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">draft_len</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;&#34;&#34;Expected tokens produced by one big-model pass.&#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">accept</span> <span class="o">**</span> <span class="p">(</span><span class="n">draft_len</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">accept</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">speedup</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">draft_len</span><span class="p">,</span> <span class="n">draft_cost</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;&#34;&#34;Speed versus normal decoding. draft_cost = small-model pass / big-model pass.&#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">tokens_per_round</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">draft_len</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">draft_len</span> <span class="o">*</span> <span class="n">draft_cost</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">simulate</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">draft_len</span><span class="p">,</span> <span class="n">rounds</span><span class="o">=</span><span class="mi">200_000</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;&#34;&#34;Check the formula by actually flipping coins.&#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">total</span> <span class="o">=</span> <span class="mi">0</span>
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">rounds</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="n">kept</span> <span class="o">=</span> <span class="mi">0</span>
</span></span><span class="line"><span class="cl">        <span class="k">while</span> <span class="n">kept</span> <span class="o">&lt;</span> <span class="n">draft_len</span> <span class="ow">and</span> <span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">()</span> <span class="o">&lt;</span> <span class="n">accept</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">            <span class="n">kept</span> <span class="o">+=</span> <span class="mi">1</span>
</span></span><span class="line"><span class="cl">        <span class="n">total</span> <span class="o">+=</span> <span class="n">kept</span> <span class="o">+</span> <span class="mi">1</span>          <span class="c1"># accepted drafts plus one token from the big model</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">total</span> <span class="o">/</span> <span class="n">rounds</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="s2">&#34;Tokens per big-model pass (draft length 5)&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="k">for</span> <span class="n">accept</span> <span class="ow">in</span> <span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;  acceptance </span><span class="si">{</span><span class="n">accept</span><span class="si">:</span><span class="s2">.0%</span><span class="si">}</span><span class="s2">: formula </span><span class="si">{</span><span class="n">tokens_per_round</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span><span class="si">:</span><span class="s2">.2f</span><span class="si">}</span><span class="s2">, simulated </span><span class="si">{</span><span class="n">simulate</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span><span class="si">:</span><span class="s2">.2f</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="s2">&#34;</span><span class="se">\n</span><span class="s2">Speedup when the draft model costs 10</span><span class="si">% o</span><span class="s2">f the big model&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="s2">&#34;  acceptance   draft 3   draft 5   draft 8&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="k">for</span> <span class="n">accept</span> <span class="ow">in</span> <span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">row</span> <span class="o">=</span> <span class="s2">&#34;   &#34;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;</span><span class="si">{</span><span class="n">speedup</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mf">0.10</span><span class="p">)</span><span class="si">:</span><span class="s2">5.2f</span><span class="si">}</span><span class="s2">x&#34;</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">8</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">    <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;  </span><span class="si">{</span><span class="n">accept</span><span class="si">:</span><span class="s2">&gt;9.0%</span><span class="si">}</span><span class="s2">    </span><span class="si">{</span><span class="n">row</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="s2">&#34;</span><span class="se">\n</span><span class="s2">Speedup at 70</span><span class="si">% a</span><span class="s2">cceptance, draft length 5, by draft cost&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="k">for</span> <span class="n">cost</span> <span class="ow">in</span> <span class="p">(</span><span class="mf">0.02</span><span class="p">,</span> <span class="mf">0.10</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.50</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;  draft costs </span><span class="si">{</span><span class="n">cost</span><span class="si">:</span><span class="s2">&gt;4.0%</span><span class="si">}</span><span class="s2"> of a big pass: </span><span class="si">{</span><span class="n">speedup</span><span class="p">(</span><span class="mf">0.7</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="n">cost</span><span class="p">)</span><span class="si">:</span><span class="s2">.2f</span><span class="si">}</span><span class="s2">x&#34;</span><span class="p">)</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">python3 spec_decode.py
</span></span></code></pre></div><p>The first block of output shows the formula and the simulation agreeing:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Tokens per big-model pass (draft length 5)
</span></span><span class="line"><span class="cl">  acceptance 50%: formula 1.97, simulated 1.97
</span></span><span class="line"><span class="cl">  acceptance 70%: formula 2.94, simulated 2.94
</span></span><span class="line"><span class="cl">  acceptance 80%: formula 3.69, simulated 3.69
</span></span><span class="line"><span class="cl">  acceptance 90%: formula 4.69, simulated 4.68
</span></span></code></pre></div><p>Change the numbers to match your own case. If your draft model is 5% of the target&rsquo;s size and you expect 75% acceptance, the script tells you whether a draft length of 4 or 8 is the better bet.</p>
<h2 id="turn-it-on-in-vllm">Turn it on in vLLM</h2>
<p>Speculative decoding is a server setting. Clients do not change anything.</p>
<p>The cheapest experiment is n-gram, because it needs no second model:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vllm serve &lt;target-model&gt; <span class="se">\
</span></span></span><span class="line"><span class="cl">  --speculative-config <span class="s1">&#39;{
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;method&#34;: &#34;ngram&#34;,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;num_speculative_tokens&#34;: 4,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;prompt_lookup_min&#34;: 2,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;prompt_lookup_max&#34;: 5
</span></span></span><span class="line"><span class="cl"><span class="s1">  }&#39;</span>
</span></span></code></pre></div><p>With a separate draft model:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vllm serve &lt;target-model&gt; <span class="se">\
</span></span></span><span class="line"><span class="cl">  --speculative-config <span class="s1">&#39;{
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;method&#34;: &#34;draft_model&#34;,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;model&#34;: &#34;&lt;draft-model&gt;&#34;,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;num_speculative_tokens&#34;: 5
</span></span></span><span class="line"><span class="cl"><span class="s1">  }&#39;</span>
</span></span></code></pre></div><p>Both commands follow the current <a href="https://docs.vllm.ai/en/latest/features/speculative_decoding/">vLLM speculative decoding docs</a>. The option names have changed across releases, so check the page for your version.</p>
<p>Then measure, with the same prompts, before and after:</p>
<ol>
<li><strong>Run a single request</strong> with the timing script from the <a href="https://vishctl.dev/posts/llm-inference-metrics-ttft-tpot-throughput-goodput/#try-it-measure-ttft-and-tpot-yourself">inference metrics guide</a>. TPOT should drop.</li>
<li><strong>Run a load test</strong> at your normal request rate. Check that throughput did not fall.</li>
<li><strong>Try your real prompts</strong>, not a demo prompt. Acceptance on your traffic is the only number that matters.</li>
</ol>
<h2 id="should-you-use-it">Should you use it?</h2>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart TD
    Q1["Is the GPU usually<br/>near saturation?"] d1@-->|"Yes"| X["Skip it<br/>add capacity first"]
    Q1 d2@-->|"No"| Q2["Is the output<br/>predictable?"]
    Q2 d3@-->|"Copies the prompt"| N["Try n-gram<br/>almost free"]
    Q2 d4@-->|"Code or JSON"| D["Try a draft model<br/>about 10x smaller"]
    Q2 d5@-->|"Creative text"| M["Small gain<br/>measure before keeping"]

    d1@{ animate: true }
    d2@{ animate: true }
    d3@{ animate: true }
    d4@{ animate: true }
    d5@{ animate: true }

    classDef question fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    classDef idle fill:#101e27,stroke:#324950,color:#8aa0a8;
    class Q1,Q2 question;
    class X warn;
    class N,D gpu;
    class M idle;</div>
  <figcaption>Start with how busy the GPU is. Speculation spends spare compute, so it pays off when there is some to spend.</figcaption>
</figure>

<h2 id="cheat-sheet">Cheat sheet</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Speculative decoding = a cheap drafter proposes tokens, the big model verifies them in one pass
</span></span><span class="line"><span class="cl">Draft model          = the small LLM that proposes; should be about 10x smaller than the target
</span></span><span class="line"><span class="cl">Target model         = the big model whose output you actually want
</span></span><span class="line"><span class="cl">Verification         = one big-model pass that scores every drafted position at once
</span></span><span class="line"><span class="cl">Acceptance rate      = how often the target agrees with a drafted token
</span></span><span class="line"><span class="cl">Draft length         = how many tokens are proposed per round (num_speculative_tokens)
</span></span><span class="line"><span class="cl">Tokens per pass      = (1 - acceptance^(draft length + 1)) / (1 - acceptance)
</span></span><span class="line"><span class="cl">Lossless             = the output follows the target model&#39;s own choices, not the draft&#39;s
</span></span><span class="line"><span class="cl">N-gram, prompt lookup = draft by copying tokens that already appear in the prompt
</span></span><span class="line"><span class="cl">EAGLE-style heads    = small extra layers on the target model that do the drafting
</span></span><span class="line"><span class="cl">Where it hurts       = saturated GPUs and tight memory, where draft work crowds out requests
</span></span><span class="line"><span class="cl">Rule of thumb        = predictable output and spare GPU time: use it; busy GPU: skip it
</span></span></code></pre></div><p>Related: speculative decoding makes each stream faster, while <a href="https://vishctl.dev/posts/why-vllm-is-dominating-ai-inference-market/">continuous batching</a> makes the whole server carry more streams. For another way to skip work on structured output, see jump-forward decoding in <a href="https://vishctl.dev/posts/sglang-vs-vllm/">SGLang vs. vLLM</a>.</p>
]]></content:encoded></item><item><title>LLM Inference Metrics, Simply: TTFT, TPOT, Throughput, and Goodput</title><link>https://vishctl.dev/posts/llm-inference-metrics-ttft-tpot-throughput-goodput/</link><pubDate>Fri, 13 Nov 2026 09:00:00 +0800</pubDate><guid>https://vishctl.dev/posts/llm-inference-metrics-ttft-tpot-throughput-goodput/</guid><category>inference</category><category>benchmarking</category><category>latency</category><category>vllm</category><category>observability</category><category>ai-infra</category><description>A simple, diagram-first guide to reading LLM serving numbers: what TTFT, TPOT, ITL, throughput, percentiles, and goodput measure, how they trade off, and a 40-line script to measure them on any OpenAI-compatible endpoint.</description><content:encoded><![CDATA[<p>A benchmark says your model server does 2,000 tokens per second. A user says the chatbot feels slow. Both can be true at the same time.</p>
<p>They are looking at different clocks. Almost every confusing LLM performance conversation comes down to mixing these two up:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Latency    = how long ONE user waits     (TTFT, TPOT, end-to-end)
</span></span><span class="line"><span class="cl">Throughput = how much ALL users get done (tokens per second, requests per second)
</span></span></code></pre></div><figure class="mermaid-figure">
  <div class="mermaid">flowchart TD
    subgraph USER["One user's view"]
        direction LR
        U1["Send<br/>prompt"] a1@--> U2["Wait for<br/>first word"]
        U2 a2@--> U3["Read the<br/>stream"]
        U3 a3@--> U4["Answer done<br/>7.8 s"]
    end

    subgraph PLATFORM["The platform's view"]
        direction LR
        P1["32 users<br/>at once"] b1@--> P2["One GPU<br/>one batch"]
        P2 b2@--> P3["960 tokens<br/>per second"]
    end

    USER ~~~ PLATFORM
    a1@{ animate: true }
    a2@{ animate: true }
    a3@{ animate: true }
    b1@{ animate: true }
    b2@{ animate: true }

    classDef input fill:#13264a,stroke:#38bdf8,color:#e6f6ff,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    class U1,P1 input;
    class U2,U3 warn;
    class U4,P2,P3 gpu;</div>
  <figcaption>Top: one user cares about their own wait. Bottom: the platform cares about total work per GPU. The same server produces both numbers.</figcaption>
</figure>

<p>This post explains each metric with one running example, then gives you a small script to measure them yourself. It works on vLLM, SGLang, Ollama, LM Studio, or anything else that speaks the OpenAI API.</p>
<p>If terms like prefill, decode, and KV cache are new, read <a href="https://vishctl.dev/posts/llm-basics-visual-guide/">What Happens When You Ask an LLM a Question</a> first.</p>
<h2 id="one-request-four-clocks">One request, four clocks</h2>
<p>Here is the life of a single streaming request, split at the moment the first token arrives. Every latency metric is just a stopwatch between two of these points.</p>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart TD
    subgraph WAIT["Before first token"]
        direction LR
        S["Request<br/>sent"] e1@--> Q["Queue<br/>wait for a slot"]
        Q e2@--> P["Prefill<br/>read the prompt"]
        P e3@--> F["First token<br/>arrives"]
    end

    subgraph STREAM["After first token"]
        direction LR
        D1["Token 2"] e4@--> D2["Token 3"]
        D2 e5@--> D3["...and<br/>so on"]
        D3 e6@--> L["Last token<br/>arrives"]
    end

    WAIT ~~~ STREAM
    e1@{ animate: true }
    e2@{ animate: true }
    e3@{ animate: true }
    e4@{ animate: true }
    e5@{ animate: true }
    e6@{ animate: true }

    classDef input fill:#13264a,stroke:#38bdf8,color:#e6f6ff,stroke-width:2px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef router fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    class S input;
    class Q warn;
    class P router;
    class F,D1,D2,D3,L gpu;</div>
  <figcaption>Top: everything before the first token adds up to TTFT. Bottom: the gaps between the tokens after it are what TPOT averages.</figcaption>
</figure>

<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Metric</th>
            <th scope="col">Starts at</th>
            <th scope="col">Stops at</th>
            <th scope="col">Plain meaning</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><strong>TTFT</strong></td>
            <td>Request sent</td>
            <td>First token</td>
            <td>How long until something shows up</td>
        </tr>
        <tr>
            <td><strong>TPOT</strong></td>
            <td>First token</td>
            <td>Last token, divided by tokens</td>
            <td>How fast the text streams</td>
        </tr>
        <tr>
            <td><strong>ITL</strong></td>
            <td>One token</td>
            <td>The next token</td>
            <td>The gap between two tokens</td>
        </tr>
        <tr>
            <td><strong>End-to-end</strong></td>
            <td>Request sent</td>
            <td>Last token</td>
            <td>How long until the answer is complete</td>
        </tr>
    </tbody>
  </table>
</div>
<h3 id="the-running-example">The running example</h3>
<p>One request, with made-up but realistic numbers:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Prompt:  2,000 tokens      Answer: 300 tokens
</span></span><span class="line"><span class="cl">Queue:   50 ms             Prefill: 250 ms
</span></span><span class="line"><span class="cl">Decode:  25 ms per token
</span></span></code></pre></div><div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Step</th>
            <th scope="col">What happens</th>
            <th scope="col">Clock reads</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Request waits in the queue</td>
            <td>50 ms</td>
        </tr>
        <tr>
            <td>2</td>
            <td>GPU reads the 2,000-token prompt (prefill)</td>
            <td>300 ms</td>
        </tr>
        <tr>
            <td>3</td>
            <td>First token is sent back</td>
            <td>300 ms: this is the <strong>TTFT</strong></td>
        </tr>
        <tr>
            <td>4</td>
            <td>299 more tokens arrive, 25 ms apart</td>
            <td>7,775 ms: this is the <strong>end-to-end latency</strong></td>
        </tr>
    </tbody>
  </table>
</div>
<p>Keep these numbers in mind. Every section below refers back to them.</p>
<h2 id="1-ttft-time-to-first-token">1. TTFT: time to first token</h2>
<p><strong>TTFT is the wait before anything appears.</strong> It is the number that decides whether a chat feels responsive.</p>
<p>In the example, TTFT is 300 ms. It has three ingredients:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">TTFT = network time + queue time + prefill time
</span></span></code></pre></div><p>What makes it worse:</p>
<ul>
<li><strong>Long prompts.</strong> Prefill has to read every input token. A 20,000-token prompt takes far longer than a 2,000-token one.</li>
<li><strong>A busy server.</strong> If every slot is taken, the request sits in the queue first.</li>
<li><strong>Cold caches.</strong> If the server has seen the start of this prompt before, it can skip most of the prefill. That is what prefix caching does.</li>
</ul>
<p>This is why TTFT is the metric that <a href="https://vishctl.dev/posts/why-lmcache-is-needed/">LMCache</a> and cache-aware routers like <a href="https://vishctl.dev/posts/llm-d-kubernetes-inference-routing/">llm-d</a> target. They do not make tokens generate faster. They make the first one arrive sooner.</p>
<h2 id="2-tpot-and-itl-how-fast-the-text-streams">2. TPOT and ITL: how fast the text streams</h2>
<p><strong>TPOT (time per output token)</strong> is the average gap between tokens after the first one. It is calculated once per request:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">TPOT = (end-to-end latency - TTFT) / (output tokens - 1)
</span></span><span class="line"><span class="cl">     = (7,775 ms - 300 ms) / 299
</span></span><span class="line"><span class="cl">     = 25 ms
</span></span></code></pre></div><p>Flip it over and you get the speed one user sees: <code>1000 / 25 = 40 tokens per second</code>.</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">TPOT</th>
            <th scope="col">Tokens per second</th>
            <th scope="col">How it feels</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>200 ms</td>
            <td>5</td>
            <td>Slower than most people read</td>
        </tr>
        <tr>
            <td>100 ms</td>
            <td>10</td>
            <td>Comfortable reading pace</td>
        </tr>
        <tr>
            <td>50 ms</td>
            <td>20</td>
            <td>Faster than you can read</td>
        </tr>
        <tr>
            <td>25 ms</td>
            <td>40</td>
            <td>Feels instant for chat</td>
        </tr>
        <tr>
            <td>10 ms</td>
            <td>100</td>
            <td>Only matters for agents and long outputs</td>
        </tr>
    </tbody>
  </table>
</div>
<p>For a human reading a chat reply, anything under about 50 ms is already faster than their eyes. For an <strong>agent</strong> that waits for the full answer before acting, every millisecond of TPOT still counts.</p>
<h3 id="itl-is-the-same-idea-measured-per-gap">ITL is the same idea, measured per gap</h3>
<p><strong>ITL (inter-token latency)</strong> measures each individual gap between two streamed chunks, instead of one average per request.</p>
<p>Most of the time ITL and TPOT are nearly identical. They split apart when:</p>
<ul>
<li><strong>A chunk carries several tokens.</strong> With speculative decoding, one streamed chunk can contain a few tokens at once.</li>
<li><strong>The stream stutters.</strong> A request with 298 fast gaps and one 2-second pause has a healthy TPOT but an ugly P99 ITL.</li>
</ul>
<p>Use TPOT to describe speed. Use ITL to catch stutter.</p>
<h2 id="3-end-to-end-latency-output-length-dominates">3. End-to-end latency: output length dominates</h2>
<p>Put the pieces together:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">End-to-end = TTFT + TPOT x (output tokens - 1)
</span></span><span class="line"><span class="cl">           = 300 ms + 25 ms x 299
</span></span><span class="line"><span class="cl">           = 7,775 ms
</span></span></code></pre></div><p>Look at the split. TTFT is 300 ms. Decoding is 7,475 ms.</p>
<p><strong>About 96% of the wait is the answer being written.</strong></p>
<p>That leads to two practical rules:</p>
<ul>
<li><strong>To make a chat feel faster, cut TTFT.</strong> Users forgive a long answer that starts immediately.</li>
<li><strong>To make a batch job or an agent faster, cut output tokens or TPOT.</strong> Asking for a shorter answer is often the cheapest optimization there is.</li>
</ul>
<p>It also means end-to-end latency is a poor number to compare across workloads. A request that returns 50 tokens will always beat one that returns 500, on any server.</p>
<h2 id="4-throughput-the-platforms-number">4. Throughput: the platform&rsquo;s number</h2>
<p><strong>Throughput is how much work the whole server finishes per second</strong>, summed across every user.</p>
<p>It usually comes in two flavors:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Throughput</th>
            <th scope="col">Unit</th>
            <th scope="col">Answers</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Request throughput</td>
            <td>requests per second</td>
            <td>How many users can I serve?</td>
        </tr>
        <tr>
            <td>Token throughput</td>
            <td>tokens per second</td>
            <td>How much text does one GPU produce?</td>
        </tr>
    </tbody>
  </table>
</div>
<p>Here is the trap. A modern engine uses <a href="https://vishctl.dev/posts/why-vllm-is-dominating-ai-inference-market/">continuous batching</a>, so it generates tokens for many requests in the same step.</p>
<p>Say 32 users are streaming at once, and each sees 30 tokens per second:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Per-user speed     = 30 tokens per second
</span></span><span class="line"><span class="cl">System throughput  = 32 x 30 = 960 tokens per second
</span></span></code></pre></div><p>Both numbers describe the same GPU at the same moment. A headline of &ldquo;960 tokens per second&rdquo; does not mean any single user gets 960. Nobody does.</p>
<p><strong>When you read a benchmark, always ask: is this per request or summed over all requests?</strong></p>
<h2 id="5-the-trade-off-you-cannot-max-out-both">5. The trade-off: you cannot max out both</h2>
<p>Batching more requests together raises throughput, but each request gets a smaller share of every step. So latency rises with load.</p>
<p>These numbers are invented to show the shape, not measured on real hardware:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Concurrent requests</th>
            <th scope="col">System tokens per second</th>
            <th scope="col">Per-user TPOT</th>
            <th scope="col">TTFT</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>60</td>
            <td>17 ms</td>
            <td>150 ms</td>
        </tr>
        <tr>
            <td>8</td>
            <td>400</td>
            <td>20 ms</td>
            <td>180 ms</td>
        </tr>
        <tr>
            <td>32</td>
            <td>960</td>
            <td>33 ms</td>
            <td>300 ms</td>
        </tr>
        <tr>
            <td>64</td>
            <td>1,150</td>
            <td>56 ms</td>
            <td>900 ms</td>
        </tr>
        <tr>
            <td>128</td>
            <td>1,200</td>
            <td>107 ms</td>
            <td>6,000 ms</td>
        </tr>
    </tbody>
  </table>
</div>
<p>Read the last two rows carefully. Going from 64 to 128 users adds almost no throughput, while TTFT explodes. The GPU is full, so new requests wait in the queue.</p>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart LR
    Z1["Idle<br/>fast but<br/>GPU wasted"] e1@--> Z2["Sweet spot<br/>busy GPU<br/>latency OK"]
    Z2 e2@--> Z3["Saturated<br/>throughput flat<br/>latency climbs"]
    Z3 e3@--> Z4["Overloaded<br/>queue grows<br/>TTFT explodes"]

    e1@{ animate: true }
    e2@{ animate: true }
    e3@{ animate: true }

    classDef idle fill:#101e27,stroke:#324950,color:#8aa0a8;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:3px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef router fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    class Z1 idle;
    class Z2 gpu;
    class Z3 router;
    class Z4 warn;</div>
  <figcaption>As load rises, a server moves through four zones. The goal is to run in the second one, not the third.</figcaption>
</figure>

<p>So a single number never describes a server. A useful benchmark is a <strong>curve</strong>: latency plotted against load. The right operating point is the highest load where latency still fits your budget.</p>
<h2 id="6-percentiles-why-the-mean-lies">6. Percentiles: why the mean lies</h2>
<p>Latency is never one number. It is a spread, and the slow end is where users complain.</p>
<p>Take 100 requests. 99 of them have a 200 ms TTFT. One hits a full queue and takes 5,000 ms.</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Statistic</th>
            <th scope="col">Value</th>
            <th scope="col">What it tells you</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Mean</td>
            <td>248 ms</td>
            <td>Looks fine, hides the problem</td>
        </tr>
        <tr>
            <td>P50 (median)</td>
            <td>200 ms</td>
            <td>The typical request</td>
        </tr>
        <tr>
            <td>P99</td>
            <td>About 5,000 ms</td>
            <td>The slowest 1 in 100</td>
        </tr>
    </tbody>
  </table>
</div>
<p>&ldquo;P99 = 5 seconds&rdquo; means 1 request in 100 is at least that slow. That sounds rare until you remember that people send many requests.</p>
<p>A user who sends 20 messages in a session has this chance of hitting the slow tail at least once:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">1 - 0.99^20 = 18%
</span></span></code></pre></div><p>Nearly one in five sessions feels the P99. For an agent that makes 50 model calls per task, it is 39%. <strong>This is why serious latency targets are written as P95 or P99, never as an average.</strong></p>
<h2 id="7-goodput-throughput-that-actually-counts">7. Goodput: throughput that actually counts</h2>
<p>Throughput counts every finished request, even the ones that were painfully slow. <strong>Goodput</strong> counts only the requests that met your latency target.</p>
<p>First you set a target, called an <strong>SLO</strong> (service level objective). For example:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">SLO: TTFT under 500 ms  and  TPOT under 50 ms
</span></span></code></pre></div><p>Then you count only the requests that pass.</p>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart LR
    IN["Server finishes<br/>10 requests<br/>per second"] g1@--> C["SLO check<br/>TTFT under 500 ms<br/>TPOT under 50 ms"]
    C g2@--> OK["6 pass<br/>goodput is 6"]
    C g3@--> BAD["4 too slow<br/>users gave up"]

    g1@{ animate: true }
    g2@{ animate: true }
    g3@{ animate: true }

    classDef input fill:#13264a,stroke:#38bdf8,color:#e6f6ff,stroke-width:2px;
    classDef router fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:3px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    class IN input;
    class C router;
    class OK gpu;
    class BAD warn;</div>
  <figcaption>Ten requests per second finish, but only six meet the SLO. Throughput is 10. Goodput is 6.</figcaption>
</figure>

<p>Goodput is the honest way to compare two setups. Look back at the load table: at 128 concurrent requests throughput is the highest in the table, but with a 500 ms TTFT target the goodput is close to zero.</p>
<p>It also turns capacity planning into one question: <strong>what is the highest request rate where goodput still equals throughput?</strong> That rate is what one replica can really carry.</p>
<h2 id="try-it-measure-ttft-and-tpot-yourself">Try it: measure TTFT and TPOT yourself</h2>
<p>You do not need a benchmark suite to see these numbers. This script sends one streaming request and times it. It uses only the Python standard library.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="ch">#!/usr/bin/env python3</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;&#34;&#34;llm_clock.py: time one streaming request to an OpenAI-compatible API.&#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">json</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">os</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">sys</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">time</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">urllib.request</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">base</span><span class="p">,</span> <span class="n">model</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s2">&#34;/&#34;</span><span class="p">),</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="n">prompt</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span> <span class="k">else</span> <span class="s2">&#34;Explain a Kubernetes Pod in 150 words.&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">body</span> <span class="o">=</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;model&#34;</span><span class="p">:</span> <span class="n">model</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;messages&#34;</span><span class="p">:</span> <span class="p">[{</span><span class="s2">&#34;role&#34;</span><span class="p">:</span> <span class="s2">&#34;user&#34;</span><span class="p">,</span> <span class="s2">&#34;content&#34;</span><span class="p">:</span> <span class="n">prompt</span><span class="p">}],</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;stream&#34;</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;stream_options&#34;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&#34;include_usage&#34;</span><span class="p">:</span> <span class="kc">True</span><span class="p">},</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;max_tokens&#34;</span><span class="p">:</span> <span class="mi">256</span><span class="p">,</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="n">headers</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&#34;Content-Type&#34;</span><span class="p">:</span> <span class="s2">&#34;application/json&#34;</span><span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&#34;OPENAI_API_KEY&#34;</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">headers</span><span class="p">[</span><span class="s2">&#34;Authorization&#34;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&#34;Bearer &#34;</span> <span class="o">+</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&#34;OPENAI_API_KEY&#34;</span><span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="n">req</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">Request</span><span class="p">(</span><span class="n">base</span> <span class="o">+</span> <span class="s2">&#34;/v1/chat/completions&#34;</span><span class="p">,</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">body</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(),</span> <span class="n">headers</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
</span></span><span class="line"><span class="cl"><span class="n">first</span> <span class="o">=</span> <span class="n">last</span> <span class="o">=</span> <span class="kc">None</span>
</span></span><span class="line"><span class="cl"><span class="n">chunks</span><span class="p">,</span> <span class="n">exact_tokens</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="kc">None</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">with</span> <span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">req</span><span class="p">)</span> <span class="k">as</span> <span class="n">resp</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="n">raw</span> <span class="ow">in</span> <span class="n">resp</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">        <span class="n">line</span> <span class="o">=</span> <span class="n">raw</span><span class="o">.</span><span class="n">decode</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span> <span class="ow">not</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&#34;data:&#34;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">line</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&#34;[DONE]&#34;</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">            <span class="k">continue</span>
</span></span><span class="line"><span class="cl">        <span class="n">event</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">line</span><span class="p">[</span><span class="mi">5</span><span class="p">:])</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&#34;usage&#34;</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">            <span class="n">exact_tokens</span> <span class="o">=</span> <span class="n">event</span><span class="p">[</span><span class="s2">&#34;usage&#34;</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&#34;completion_tokens&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="n">delta</span> <span class="o">=</span> <span class="p">(</span><span class="n">event</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&#34;choices&#34;</span><span class="p">)</span> <span class="ow">or</span> <span class="p">[{}])[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&#34;delta&#34;</span><span class="p">,</span> <span class="p">{})</span>
</span></span><span class="line"><span class="cl">        <span class="k">if</span> <span class="n">delta</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&#34;content&#34;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">delta</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&#34;reasoning_content&#34;</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">            <span class="n">last</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">            <span class="n">first</span> <span class="o">=</span> <span class="n">first</span> <span class="ow">or</span> <span class="n">last</span>
</span></span><span class="line"><span class="cl">            <span class="n">chunks</span> <span class="o">+=</span> <span class="mi">1</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">if</span> <span class="n">first</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">    <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s2">&#34;No tokens were streamed back.&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">tokens</span> <span class="o">=</span> <span class="n">exact_tokens</span> <span class="ow">or</span> <span class="n">chunks</span>
</span></span><span class="line"><span class="cl"><span class="n">ttft</span> <span class="o">=</span> <span class="n">first</span> <span class="o">-</span> <span class="n">start</span>
</span></span><span class="line"><span class="cl"><span class="n">e2e</span> <span class="o">=</span> <span class="n">last</span> <span class="o">-</span> <span class="n">start</span>
</span></span><span class="line"><span class="cl"><span class="n">tpot</span> <span class="o">=</span> <span class="p">(</span><span class="n">e2e</span> <span class="o">-</span> <span class="n">ttft</span><span class="p">)</span> <span class="o">/</span> <span class="nb">max</span><span class="p">(</span><span class="n">tokens</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;Output tokens : </span><span class="si">{</span><span class="n">tokens</span><span class="si">}</span><span class="s2"> (</span><span class="si">{</span><span class="s1">&#39;reported by server&#39;</span> <span class="k">if</span> <span class="n">exact_tokens</span> <span class="k">else</span> <span class="s1">&#39;counted from chunks&#39;</span><span class="si">}</span><span class="s2">)&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;TTFT          : </span><span class="si">{</span><span class="n">ttft</span> <span class="o">*</span> <span class="mi">1000</span><span class="si">:</span><span class="s2">8.1f</span><span class="si">}</span><span class="s2"> ms&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;TPOT          : </span><span class="si">{</span><span class="n">tpot</span> <span class="o">*</span> <span class="mi">1000</span><span class="si">:</span><span class="s2">8.1f</span><span class="si">}</span><span class="s2"> ms  (</span><span class="si">{</span><span class="mi">1</span> <span class="o">/</span> <span class="n">tpot</span><span class="si">:</span><span class="s2">.1f</span><span class="si">}</span><span class="s2"> tokens per second)&#34;</span> <span class="k">if</span> <span class="n">tpot</span> <span class="k">else</span> <span class="s2">&#34;TPOT          : n/a&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;End-to-end    : </span><span class="si">{</span><span class="n">e2e</span> <span class="o">*</span> <span class="mi">1000</span><span class="si">:</span><span class="s2">8.1f</span><span class="si">}</span><span class="s2"> ms&#34;</span><span class="p">)</span>
</span></span></code></pre></div><p>Save it as <code>llm_clock.py</code> and point it at any server:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># vLLM or SGLang</span>
</span></span><span class="line"><span class="cl">python3 llm_clock.py http://localhost:8000 &lt;model-name&gt;
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Ollama</span>
</span></span><span class="line"><span class="cl">python3 llm_clock.py http://localhost:11434 &lt;model-name&gt;
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># LM Studio</span>
</span></span><span class="line"><span class="cl">python3 llm_clock.py http://localhost:1234 &lt;model-name&gt;
</span></span></code></pre></div><p>Three experiments make the theory concrete:</p>
<ol>
<li><strong>Run it twice with the same prompt.</strong> If the second TTFT is lower, you just saw prefix caching.</li>
<li><strong>Paste a very long prompt as the third argument.</strong> TTFT grows with it. TPOT barely moves.</li>
<li><strong>Run four copies at once.</strong> Per-request TPOT gets worse while the total tokens per second goes up. That is the trade-off from section 5.</li>
</ol>
<p>For experiment 3:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="k">for</span> i in <span class="m">1</span> <span class="m">2</span> <span class="m">3</span> 4<span class="p">;</span> <span class="k">do</span> python3 llm_clock.py http://localhost:8000 &lt;model-name&gt; <span class="p">&amp;</span> <span class="k">done</span><span class="p">;</span> <span class="nb">wait</span>
</span></span></code></pre></div><p>No GPU nearby? The <a href="https://vishctl.dev/posts/simulate-gpu-vllm-llm-d-on-laptop/">laptop GPU simulation lab</a> runs a simulated vLLM whose latency you configure, so the script works there too.</p>
<h2 id="benchmark-properly-with-vllm-bench">Benchmark properly with vllm bench</h2>
<p>One request is a measurement. A benchmark needs many requests at a controlled rate. vLLM ships a load generator for this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vllm bench serve <span class="se">\
</span></span></span><span class="line"><span class="cl">  --backend vllm <span class="se">\
</span></span></span><span class="line"><span class="cl">  --model &lt;model-name&gt; <span class="se">\
</span></span></span><span class="line"><span class="cl">  --host 127.0.0.1 --port <span class="m">8000</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  --endpoint /v1/completions <span class="se">\
</span></span></span><span class="line"><span class="cl">  --dataset-name random <span class="se">\
</span></span></span><span class="line"><span class="cl">  --random-input-len <span class="m">2000</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  --random-output-len <span class="m">300</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  --num-prompts <span class="m">200</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  --request-rate <span class="m">4</span>
</span></span></code></pre></div><p>Flags change between releases, so check <code>vllm bench serve --help</code> for your version. The summary it prints maps directly onto this post:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">============ Serving Benchmark Result ============
</span></span><span class="line"><span class="cl">Successful requests:                     10
</span></span><span class="line"><span class="cl">Benchmark duration (s):                  5.78
</span></span><span class="line"><span class="cl">Request throughput (req/s):              1.73
</span></span><span class="line"><span class="cl">Output token throughput (tok/s):         382.89
</span></span><span class="line"><span class="cl">---------------Time to First Token----------------
</span></span><span class="line"><span class="cl">Mean TTFT (ms):                          71.54
</span></span><span class="line"><span class="cl">Median TTFT (ms):                        73.88
</span></span><span class="line"><span class="cl">P99 TTFT (ms):                           79.49
</span></span><span class="line"><span class="cl">-----Time per Output Token (excl. 1st token)------
</span></span><span class="line"><span class="cl">Mean TPOT (ms):                          7.91
</span></span><span class="line"><span class="cl">P99 TPOT (ms):                           8.03
</span></span><span class="line"><span class="cl">---------------Inter-token Latency----------------
</span></span><span class="line"><span class="cl">Mean ITL (ms):                           7.74
</span></span><span class="line"><span class="cl">P99 ITL (ms):                            8.39
</span></span><span class="line"><span class="cl">==================================================
</span></span></code></pre></div><p>That sample is trimmed from the <a href="https://docs.vllm.ai/en/latest/benchmarking/cli/">vLLM benchmark docs</a>. You can now read every line of it.</p>
<p>To build the latency curve from section 5, run it several times with a rising <code>--request-rate</code> (for example 1, 2, 4, 8, 16) and write down P99 TTFT and output token throughput for each run. The rate where P99 TTFT bends upward is your saturation point.</p>
<p>The same tool reports goodput. Pass your SLO in milliseconds and the summary gains a line for the requests per second that met it:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vllm bench serve <span class="se">\
</span></span></span><span class="line"><span class="cl">  --model &lt;model-name&gt; <span class="se">\
</span></span></span><span class="line"><span class="cl">  --dataset-name random <span class="se">\
</span></span></span><span class="line"><span class="cl">  --num-prompts <span class="m">200</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  --request-rate <span class="m">4</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  --goodput ttft:500 tpot:50
</span></span></code></pre></div><h2 id="watch-the-same-metrics-in-production">Watch the same metrics in production</h2>
<p>A benchmark tells you what a server can do. Production metrics tell you what it is doing. vLLM exposes these at <code>/metrics</code> in Prometheus format:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">What you want to know</th>
            <th scope="col">vLLM metric</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>TTFT</td>
            <td><code>vllm:time_to_first_token_seconds</code></td>
        </tr>
        <tr>
            <td>Gap between tokens</td>
            <td><code>vllm:inter_token_latency_seconds</code></td>
        </tr>
        <tr>
            <td>End-to-end latency</td>
            <td><code>vllm:e2e_request_latency_seconds</code></td>
        </tr>
        <tr>
            <td>Time stuck in the queue</td>
            <td><code>vllm:request_queue_time_seconds</code></td>
        </tr>
        <tr>
            <td>Requests being served now</td>
            <td><code>vllm:num_requests_running</code></td>
        </tr>
        <tr>
            <td>Requests waiting for a slot</td>
            <td><code>vllm:num_requests_waiting</code></td>
        </tr>
        <tr>
            <td>How full the KV cache is</td>
            <td><code>vllm:kv_cache_usage_perc</code></td>
        </tr>
    </tbody>
  </table>
</div>
<p>Peek at them with one command:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -s http://localhost:8000/metrics <span class="p">|</span> grep -E <span class="s2">&#34;time_to_first_token|num_requests_(running|waiting)&#34;</span>
</span></span></code></pre></div><p>The latency metrics are histograms, so percentiles come from a query. P99 TTFT over the last five minutes:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">histogram_quantile(0.99, sum by (le) (rate(vllm:time_to_first_token_seconds_bucket[5m])))
</span></span></code></pre></div><p>If you only alert on one thing, make it <code>vllm:num_requests_waiting</code>. A queue that stays above zero is the earliest sign that you have entered the saturated zone.</p>
<p>For the full set of panels and alert rules, see <a href="https://vishctl.dev/posts/monitoring-vllm-prometheus-dashboard-alerts/">Monitoring vLLM in Production</a>.</p>
<h2 id="which-knob-moves-which-metric">Which knob moves which metric</h2>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Symptom</th>
            <th scope="col">Likely cause</th>
            <th scope="col">What helps</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>High TTFT, empty queue</td>
            <td>Long prompts being prefilled every time</td>
            <td>Prefix caching, <a href="https://vishctl.dev/posts/why-lmcache-is-needed/">LMCache</a>, stable prompt prefixes</td>
        </tr>
        <tr>
            <td>High TTFT, growing queue</td>
            <td>Not enough capacity</td>
            <td>More replicas, autoscale on queue depth</td>
        </tr>
        <tr>
            <td>High TTFT on some replicas only</td>
            <td>Requests land where the cache is cold</td>
            <td>Cache-aware routing with <a href="https://vishctl.dev/posts/llm-d-kubernetes-inference-routing/">llm-d</a></td>
        </tr>
        <tr>
            <td>High TPOT for everyone</td>
            <td>Batch too large, or a noisy neighbor on a <a href="https://vishctl.dev/posts/kubernetes-gpu-sharing-time-slicing-mps-mig/">shared GPU</a></td>
            <td>Cap concurrency, isolate the GPU</td>
        </tr>
        <tr>
            <td>Good TPOT, ugly P99 ITL</td>
            <td>Stutter from long prefills in the same batch</td>
            <td>Separate long-prompt traffic, or disaggregate prefill and decode</td>
        </tr>
        <tr>
            <td>Slow strict-JSON answers</td>
            <td>Token-by-token constrained decoding</td>
            <td>An engine with jump-forward decoding, see <a href="https://vishctl.dev/posts/sglang-vs-vllm/">SGLang vs. vLLM</a></td>
        </tr>
    </tbody>
  </table>
</div>
<h2 id="cheat-sheet">Cheat sheet</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">TTFT              = time to first token: network + queue + prefill
</span></span><span class="line"><span class="cl">TPOT              = time per output token: (end-to-end - TTFT) / (output tokens - 1)
</span></span><span class="line"><span class="cl">ITL               = inter-token latency: the gap between two streamed chunks
</span></span><span class="line"><span class="cl">End-to-end        = TTFT + TPOT x (output tokens - 1); dominated by answer length
</span></span><span class="line"><span class="cl">Tokens per second = 1000 / TPOT in ms for one user; summed over all users for a system
</span></span><span class="line"><span class="cl">Throughput        = total requests or tokens finished per second, across everyone
</span></span><span class="line"><span class="cl">P50 / P99         = the typical request / the slowest 1 in 100
</span></span><span class="line"><span class="cl">SLO               = the latency target you promise, such as P99 TTFT under 500 ms
</span></span><span class="line"><span class="cl">Goodput           = requests per second that met the SLO
</span></span><span class="line"><span class="cl">Saturation point  = the load where throughput stops rising and latency takes off
</span></span><span class="line"><span class="cl">Queue depth       = requests waiting for a slot; the earliest warning sign
</span></span><span class="line"><span class="cl">Rule of thumb     = chat cares about TTFT, agents and batch care about TPOT and output length
</span></span></code></pre></div><p>To see what makes TTFT drop, read <a href="https://vishctl.dev/posts/why-lmcache-is-needed/">Why LMCache Exists</a> and the <a href="https://vishctl.dev/posts/llm-d-kubernetes-inference-routing/">llm-d routing guide</a>. To see what continuous batching does to throughput, read <a href="https://vishctl.dev/posts/why-vllm-is-dominating-ai-inference-market/">Why vLLM Is Dominating the AI Inference Market</a>.</p>
]]></content:encoded></item></channel></rss>