LLM High-Throughput Inference: A Practical Guide to Optimization and Capacity Planning

    This guide explains how to improve high-throughput inference for large language models in production. It breaks down key metrics such as throughput, latency, TTFT, and P99, then walks through bottleneck measurement, core optimization paths including continuous batching, paged attention caching, quantization, speculative decoding, and prefill-decode disaggregation. It also covers service-side engineering practices, capacity planning, and common pitfalls to help teams balance cost, latency, and stability.

    1. From “Fast” to “Stable”: The Real Problem Behind High-Throughput Inference

    Once LLM applications move into production, teams stop asking “Can it run?” and start asking “How many users can we serve per unit of cost?” When people say inference is “running at hundreds of tokens per second,” they are really describing a service’s ability to keep producing valid tokens under concurrent load, not the peak speed of a single request on an idle system. These two ideas get mixed up all the time, which leads to serious errors in capacity planning.

    To understand why throughput matters, you first need to separate the metrics:

    • Throughput: The total number of tokens the entire service produces per unit of time, usually measured in tokens/s. It directly reflects cost and concurrency capacity.
    • Per-request latency: The time from the first token to the end of a single request, which determines the user experience.
    • Time to first token (TTFT): Strongly tied to the compute cost of the prefill phase and queue wait time.
    • Tail latency (P99): Determines availability during peak hours and is often more important than the average.

    The goal of high-throughput optimization is to push hardware utilization higher while still meeting latency constraints (for example, keeping P99 from degrading beyond a certain threshold). Talking about throughput without latency constraints has no engineering value, because batching requests into oversized batches can raise total throughput while making TTFT unacceptable.

    2. Locating Bottlenecks: Measure First, Optimize Second

    Any performance work should start from a trustworthy baseline. Build a minimal, reproducible load-testing environment, fix the model weights, input/output length distribution, concurrency, and sampling parameters, then change one variable at a time.

    A simplified load-testing script might look like this. The key is to record percentile latency rather than only looking at averages:

    1. import time, statistics
    2. from concurrent.futures import ThreadPoolExecutor
    3. def one_request(client, prompt, max_new_tokens=256):
    4. t0 = time.perf_counter()
    5. first_token_at = None
    6. tokens = 0
    7. for chunk in client.stream(prompt, max_new_tokens=max_new_tokens):
    8. if first_token_at is None:
    9. first_token_at = time.perf_counter()
    10. tokens += 1
    11. end = time.perf_counter()
    12. return {
    13. "ttft": first_token_at - t0,
    14. "total": end - t0,
    15. "tps": tokens / (end - first_token_at),
    16. }
    17. def bench(client, prompts, concurrency=32):
    18. with ThreadPoolExecutor(max_workers=concurrency) as pool:
    19. results = list(pool.map(lambda p: one_request(client, p), prompts))
    20. ttfts = sorted(r["ttft"] for r in results)
    21. tps = sorted(r["tps"] for r in results)
    22. p = lambda arr, q: arr[int(len(arr) * q)]
    23. return {
    24. "throughput_total": sum(r["tokens"] for r in results) / sum(r["total"] for r in results),
    25. "ttft_p50": p(ttfts, 0.5), "ttft_p99": p(ttfts, 0.99),
    26. "tps_p50": p(tps, 0.5), "tps_p10": p(tps, 0.1),
    27. }

    Load testing should cover three typical workloads: short input with short output (chat-completion-heavy), long input with short output (document QA, retrieval-augmented generation), and short input with long output (content generation). The optimal configuration differs greatly across the three. Using one set of parameters for all of them is a common reason throughput stays low.

    3. Key Optimization Paths

    1. Continuous Batching and Scheduling

    Traditional static batching requires a batch of requests to start and finish at the same time, so short requests must wait for long ones to finish generating before resources are freed. Continuous batching refines the scheduling granularity to each decoding step: as soon as one request finishes, it immediately yields its slot, which significantly increases the effective batch size. Combined with a priority queue and a maximum queue-wait limit, this can balance throughput and tail latency.

    2. Paged Management of Attention Caches

    The key-value cache is the main consumer of GPU memory, and its usage grows linearly with concurrency and context length. Paged management splits the cache into fixed-size blocks allocated on demand, reducing fragmentation and reserved waste, so more concurrency fits within the same memory budget. Requests that share the same prefix (such as the same system prompt) can share cache blocks, which pays off clearly in scenarios like coding assistants and customer service bots.

    3. Quantization and Low-Precision Compute

    Weight quantization (such as 8-bit or 4-bit) reduces memory bandwidth pressure and is especially effective for the memory-bound decode phase. Quantizing activations and caches can further expand concurrency. Note that quantization may cause accuracy loss, so you should validate results on your own business evaluation set rather than relying only on general leaderboards.

    4. Speculative Decoding and Parallel Sampling

    Use a lightweight draft model or the model’s own shallow-layer predictions to generate several candidate tokens first, then have the main model verify them all at once and accept the matching prefix. For highly predictable text (code, structured output), this can noticeably reduce the serial cost per token. Parallel sampling suits scenarios that return multiple candidates at once, combining several independent requests into in-batch parallelism.

    5. Prefill and Decode Disaggregation

    Prefill is compute-intensive while decode is memory-intensive, and co-locating them causes interference. Deploying the two phases to separate resource pools, each scaling independently, makes TTFT more controllable for long-document scenarios.

    4. Engineering Implementation and Capacity Planning

    Optimization does not stop at the engine layer. Common service-side practices include:

    • Request prioritization: Split queues by business value, reserve compute for interactive requests, and fill valleys with offline batch jobs.
    • Streaming responses: Emit the first token as early as possible to improve perceived speed and reduce connection hold time.
    • Cache reuse: Cache results for high-frequency identical requests and cache prefixes for long system prompts.
    • Elastic scaling: Use queue wait time and memory watermark as scaling signals, which is more accurate than looking at CPU utilization alone.
    • Observability: Collect metrics such as TTFT, P99, batch size, and cache hit rate through logging, monitoring, and alerting, and build a capacity dashboard.

    When deploying on the cloud, you can combine container platforms to host inference instances, object storage to hold models and datasets, message queues to smooth request spikes, and monitoring and alerting to ensure stability. The general cloud product categories offered by Baidu AI Cloud can serve as the foundation for this kind of architecture; refer to the official documentation for specific specifications and quotas.

    For capacity planning, use a “maximum concurrency under a target latency constraint” back-calculation approach: first set the acceptable upper bounds for P99 and TTFT, then gradually increase load to find the inflection point, leave more than 30% headroom for business peaks, and run periodic regression checks to avoid silent performance regressions after model or framework upgrades.

    5. Common Pitfalls

    1. Looking only at average latency while ignoring the long tail, causing timeouts to spike during peak hours.
    2. Blindly increasing batch size, which makes throughput numbers look good but breaks the interactive experience.
    3. Evaluating quantization on general leaderboards while ignoring your own business distribution.
    4. Treating cache hit rate as a given and failing to monitor invalidation caused by system prompt changes.
    5. Lacking a regression baseline, so optimization gains cannot be quantified or attributed.

    6. Conclusion

    High-throughput inference is not a single trick. It is systems engineering across scheduling, memory management, numerical precision, model structure, and service governance. Start from a trustworthy baseline, choose an optimization mix based on workload characteristics, and use percentile metrics to constrain every adjustment. Only then can you achieve a sustainable balance among cost, latency, and stability.