High-Throughput LLM Inference: Engineering Practices and Optimization

    This article breaks down the engineering workflow for high-throughput large language model inference in production. It defines the core metrics—output TPS, per-request TPS, TTFT, and end-to-end latency—and explains the trade-off between throughput and latency during memory-bound decoding. It then covers how to locate bottlenecks across compute, memory capacity, memory bandwidth, and scheduling, followed by common optimization techniques such as continuous batching, paged KV cache management, prefix reuse, quantization, speculative decoding, and parallelism strategies. Finally, it outlines a capacity planning and load testing method, along with common pitfalls to avoid.

    1. What Real Inference Traffic Looks Like

    Recent industry observations show that some lightweight LLMs are being called at a scale of trillions of tokens per week, placing them near the top of public usage rankings. These numbers are not tied to any specific product, but they point to a broader reality: LLM inference has moved from the demo stage into production, and traffic shows a clear tidal pattern—request density during daytime peaks can be several times higher than the overnight trough.

    For developers, this means two things. First, averages are meaningless; what actually shapes user experience is throughput and latency at peak hours. Second, capacity planning for inference services must be built on reproducible load test data, not on peak numbers quoted in vendor marketing.

    It is worth stressing that any claim about “how many tokens/s can be served at peak” is only meaningful with its preconditions attached: model size, input/output length distribution, concurrency, batching strategy, and hardware specification. Throughput figures stripped of these conditions have no engineering value.

    2. Defining the Metrics: Throughput, Latency, and Effective Compute

    2.1 Four Core Metrics

    • Output TPS: The total number of tokens the system produces per unit of time; a measure of overall capacity.
    • Per-request TPS: The “typing speed” an individual user perceives; strongly correlated with batch size.
    • TTFT (Time to First Token): The time from sending a request to receiving the first token; drives the subjective sense of whether the service feels laggy.
    • End-to-end latency: TTFT plus the time to generate all output tokens; determines the completion experience for long-text tasks.

    2.2 The Trade-off Between Throughput and Latency

    During the decode phase, generating each token requires reading all model weights and the KV cache, which makes it a typical memory-bound workload. Increasing batch size amortizes the cost of weight reads and can substantially raise total throughput, but it also makes each request wait longer in queue, lowering per-request TPS. In practice, teams therefore set service level objectives—for example, maximizing total throughput under the constraint that TTFT stays below a threshold and per-request TPS stays above a minimum.

    A schematic expression of the service constraint:

    1. # Pseudocode: pick the largest feasible batch size under SLO constraints
    2. def choose_batch_size(requests, slo):
    3. best = 1
    4. for bs in range(1, MAX_BATCH + 1):
    5. metrics = simulate(requests, batch_size=bs)
    6. if metrics.ttft_p99 <= slo.ttft_ms and \
    7. metrics.per_request_tps >= slo.min_tps:
    8. best = bs # keep trying larger batches while constraints hold
    9. else:
    10. break
    11. return best

    3. Locating the Bottleneck: Where Is It Actually Stalling?

    Before optimizing, you must locate the bottleneck. There are four common types:

    1. Compute bottleneck: Dense matrix multiplications, common in the prefill phase and with very long inputs.
    2. Memory capacity bottleneck: Weights and the KV cache compete for space, preventing batch size from increasing.
    3. Memory bandwidth bottleneck: The dominant factor in the decode phase; it sets the ceiling on per-request TPS.
    4. Scheduling and queuing bottleneck: Uneven request distribution and long requests blocking short ones leave effective compute idle.

    For diagnosis, collect GPU utilization, memory usage, batch size distribution, queue wait time, and token-level output intervals at the same time, and put them on a single comparison dashboard. If GPU utilization is high but throughput is low, the batch is likely too small or the workload is memory-bound; if utilization is low but latency is high, the problem lies in scheduling and queuing.

    4. General Optimization Techniques

    4.1 Continuous Batching

    Traditional static batching requires all requests in a batch to start and finish together, so short requests must wait for long ones to complete, which wastes a great deal of capacity. Continuous batching swaps requests in and out dynamically at iteration granularity: as soon as one request finishes generating, its slot is released and a new request fills it immediately. In practice, this typically delivers a several-fold throughput improvement.

    4.2 Paged Cache Management

    Splitting the KV cache into fixed-size blocks that are allocated on demand and stored non-contiguously significantly reduces internal and external fragmentation, keeps memory utilization more stable, and thereby supports larger concurrent batches.

    4.3 Prefix Reuse

    Many requests share the same system prompt or few-shot prefix. Reusing the KV cache for this common prefix skips redundant prefill and directly lowers TTFT. In implementation, the cache key must include the model version and tokenizer configuration to avoid incorrect cache hits.

    4.4 Quantization and Low Precision

    Low-bit quantization of weights and compression of the KV cache can expand the batch size that fits in memory with a controllable loss of accuracy. The key to adoption is a layered accuracy evaluation set covering long text, code, math, and other capability dimensions, rather than looking at a single metric.

    4.5 Speculative Decoding

    A small model or a lightweight draft mechanism first proposes several candidate tokens, and the large model then verifies them in parallel in a single pass, producing multiple tokens at once when they are accepted. In the memory-bound decode phase, this kind of method can noticeably improve per-request TPS, at the cost of draft overhead and implementation complexity.

    4.6 Parallelism and Scaling Strategies

    Tensor parallelism reduces per-GPU memory pressure and improves bandwidth utilization; pipeline parallelism raises multi-GPU throughput; data parallelism combined with load balancing enables horizontal scaling. Which combination to choose depends on model size and the request length distribution.

    5. Capacity Planning and Load Testing

    Build a capacity baseline with the following steps:

    1. Construct a request set from sampled real traffic, preserving the original distribution of input and output lengths; do not test only fixed lengths.
    2. Apply load in steps, recording how throughput, TTFT percentiles, and per-request TPS change with concurrency.
    3. Find the maximum concurrency that satisfies the SLO; this is the capacity ceiling for a single instance.
    4. Divide the peak-hour peak by the single-instance capacity, then apply a redundancy factor to get the number of instances.
    5. Combine this with elastic scaling and queue-based rate limiting so that, under overload, the completion quality of already accepted requests is prioritized.
    1. # Illustration: observability dimensions for stepped load testing (not a specific tool command)
    2. # Concurrency: 8 -> 16 -> 32 -> 64 -> 128
    3. # Record: output_tps, ttft_p50/p99, per_request_tps, gpu_util, kv_cache_used

    6. Common Pitfalls

    • Looking only at peak throughput: Throughput numbers that ignore the SLO cannot be converted into usable capacity.
    • Load testing with fixed lengths: Long-tail requests in real workloads are the main cause of latency degradation.
    • Ignoring cache consistency: If prefix reuse does not isolate tenants and versions, cross-contamination can occur.
    • No overload protection: Without rate limiting and degradation strategies, peak traffic can trigger an avalanche.

    7. Conclusion

    High-throughput inference is not the product of any single technique; it is systems engineering across metric definition, bottleneck analysis, scheduling optimization, and capacity governance. If developers build a reproducible load testing loop and an elastic scaling mechanism on top of general-purpose capabilities such as the container platform, object storage, log service, and monitoring and alerting offered by Baidu AI Cloud, they can reliably deliver a predictable token output rate and response experience during peak hours.