LLM Inference Deployment Optimization Guide: From Bottlenecks to Capacity Planning

    Serving large language models in production often exposes cost and latency constraints before model capability becomes the limiting factor. This guide explains the key bottlenecks in LLM inference deployment, including GPU memory pressure, the memory-bandwidth-bound nature of autoregressive decoding, and the throughput-latency trade-off. It then examines three core optimization techniques—Paged Attention, operator fusion, and continuous batching—along with their benefits and limits, covers elastic scaling and traffic scheduling in cloud-native environments, and provides a monitoring checklist, a step-by-step capacity planning process, and a practical troubleshooting order.

    1. Bottlenecks and Metrics: Identify the Constraints First

    When a model with hundreds of billions of parameters goes live, cost and latency usually become the limiting factors before model capability does. The numbers below are order-of-magnitude estimates, with assumptions stated explicitly.

    GPU Memory Capacity Pressure

    Model weights stored in FP16 take 2 bytes per parameter, so every billion parameters requires roughly 2 GB. A 100-billion-parameter model carries about 200 GB of weights; a 175-billion-parameter model, about 350 GB. This counts weights only—framework runtime, activations, and communication buffers push actual usage higher.

    KV Cache grows with context length and the number of concurrent sequences. When long contexts overlap with high concurrency, GPU memory fills up quickly. For planning, estimate it as “max concurrency × max context length × KV Cache size per token,” and leave headroom.

    The Memory-Bandwidth Bottleneck

    In autoregressive decoding, every generated token requires reading the full model weights from GPU memory, while the matrix multiplications involved are computationally small. Compute units frequently stall waiting for data, so utilization stays low. Decoding performance is primarily bounded by memory bandwidth, not peak compute. Adding GPU compute alone therefore helps little; increasing batch size or reducing memory accesses is far more effective.

    The Throughput-Latency Trade-off

    Interactive workloads care about time to first token (TTFT) and per-token generation latency (TPOT). Offline batch processing cares about throughput—tokens processed per unit time—which directly determines unit cost. When both traffic types share one cluster, batching improves throughput but can lengthen queuing for interactive requests. Before making capacity decisions, define separate SLOs for each traffic class.

    2. Where Three Core Optimization Techniques Pay Off

    Paged Attention

    The traditional approach pre-allocates a contiguous block of memory sized for the maximum sequence length per request. Since actual lengths vary widely, this causes internal waste and external fragmentation. Paged Attention borrows the paging idea from OS virtual memory: KV Cache is split into fixed-size blocks, requests acquire blocks on demand, and a block table records the mapping between logical positions and physical blocks.

    With fragmentation reduced, the same memory holds more concurrent sequences. Remaining waste comes mainly from the last partially filled block of each sequence—larger blocks waste more, while smaller blocks increase block-table management and access overhead. Common implementations default to a block size of 16 tokens; use the actual values in your framework version’s documentation and configuration.

    The benefit depends on three conditions: how dispersed the request length distribution is, whether the block size is set sensibly, and whether the scheduler promptly reclaims blocks from finished sequences. If all requests have similar lengths, traditional pre-allocation already wastes little and the gain is limited. When short and long requests are heavily mixed, the gains are usually more pronounced.

    Operator Fusion

    The decoding and prefill phases contain many small operators: normalization, residual addition, activation functions, element-wise operations. Executed individually, each operator writes intermediate results back to GPU memory, which the next operator then reads. Operator fusion merges adjacent operations into the same kernel, reducing kernel launches and memory round-trips.

    The benefit depends on whether the fused operators are memory-bound, and whether registers and shared memory suffice after fusion. If the bottleneck is large matrix multiplication, fusion offers limited improvement. Fusion also adds compilation and maintenance costs, and its effect varies significantly across hardware and framework versions—measure with your target model.

    The impact on TTFT comes mainly from the prefill phase; the impact on TPOT comes mainly from small-operator overhead in decoding. Fusion directly reduces per-step latency; its throughput gain depends on the share of small operators in per-step time.

    A common misconception is that fusion can replace batching or memory optimization. Fusion only reduces per-step overhead—it does not reduce how often weights are read.

    Continuous Batching

    Static batching waits for an entire batch to finish before admitting new requests. Once short requests complete, the GPU idles, while long requests hold up the whole batch. Continuous batching (also called iteration-level scheduling) checks the queue after every decoding step: finished sequences exit immediately, and new requests join immediately.

    This approach markedly improves GPU utilization and suits workloads with widely varying output lengths. Its latency impact needs a closer look: admitting a new request requires prefill computation, which consumes compute during decoding steps and may raise TPOT for requests currently generating. Chunked prefill can split long prompts into smaller segments interleaved with decoding requests, easing this problem at the cost of slightly higher TTFT.

    Two common pitfalls: setting max batch size too high—when memory is tight, preemption or swapping kicks in and throughput drops while TPOT fluctuates wildly; and looking only at average latency while ignoring P95 and P99.

    Technique Comparison

    Dimension Paged KV Cache Operator Fusion Continuous Batching
    Problem addressed Memory fragmentation and concurrency ceiling Memory access and launch overhead of small operators GPU idling and queuing
    Primary metric affected Achievable concurrency Per-step latency (TPOT) Throughput, queuing time
    Conditions for benefit Wide variation in request lengths High share of memory-bound operators Varying output lengths, sustained request arrivals
    Main risks Poor block size causing management overhead or tail waste Compilation complexity, version compatibility Preemption, TPOT jitter, prefill interference
    Best fit Multi-tenant, mixed long/short requests Fixed model, stable long-term serving Online services, high concurrency
    Poor fit Highly uniform request lengths Bottleneck in large matrix multiplication Low request volume, latency-critical single requests

    3. Elastic Scaling and Traffic Scheduling in Cloud-Native Environments

    Scaling Signals

    CPU and memory utilization offer little signal for inference services. GPU utilization alone is also unreliable—decoding may be memory-bandwidth-bound, so requests can still be queuing even when GPU utilization looks high. Better signals include queue length, queuing time, KV Cache block utilization, running sequence count, and TTFT P95.

    Once these metrics are wired into Kubernetes via a custom metrics adapter, they can drive the HPA or other autoscaling controllers. Scaling thresholds should come from load testing, not fixed defaults.

    Cold Starts and Warm-Up

    Model loading is the main constraint on scaling speed. Loading 200 GB of weights from object storage into GPU memory depends on network bandwidth, storage type, and parallel loading capability. Scaling speed therefore cannot be judged by Pod scheduling time alone.

    Practical measures include: keeping a minimum replica count to absorb traffic spikes; pre-loading weights to node-local disks or shared high-speed storage; baking models into images or caching them; and sending warm-up requests before scaling to trigger kernel compilation and memory allocation. Spot instances cut costs, but reclamation interrupts in-flight requests—suitable only for retryable offline tasks.

    Traffic Scheduling

    Traffic scheduling can be layered into four tiers:

    1. Admission control: Rate-limit by tokens rather than requests only—for example, capping each tenant’s total input-plus-output tokens per minute. Return a clear error when limits are exceeded instead of queueing indefinitely.
    2. Queues and priorities: Use separate queues for interactive and offline traffic. Set a queuing timeout for the interactive queue and fail fast on timeout, so users don’t wait only to get nothing.
    3. Isolation: Give important tenants or critical workloads dedicated instance pools so a single large request cannot monopolize the cluster.
    4. Routing: When load balancing across instances, account for each instance’s current queue length and KV Cache occupancy rather than simple round-robin. With prefix caching enabled, route requests with the same prefix to the same instance—but guard against overloading that instance.

    Risk note: stacked timeouts and retries amplify traffic. Cap retry counts and add backoff, or failures can trigger request storms.

    4. Monitoring Checklist and Capacity Planning Steps

    Monitoring Checklist

    Metric Meaning How to Set Thresholds
    TTFT (P50/P95/P99) First-token latency; reflects queuing and prefill Derive from interactive SLOs and verify under load testing
    TPOT (P50/P95/P99) Per-token generation latency; reflects decoding efficiency Same as above
    Throughput (tokens/sec) Per-instance and cluster input/output throughput Baseline: max value that still meets SLOs under load testing
    Queuing delay Time requests spend waiting in queue Scale or throttle when its share of TTFT is too high
    GPU memory usage Weights, KV Cache, and runtime overhead combined Leave headroom to avoid preemption at peaks
    KV Cache block utilization Allocated blocks as a share of total Consistently near the limit means concurrency or lengths exceed planning
    Running sequences and batch size Current concurrency level Evaluate alongside memory and TPOT curves to find the optimum
    Preemption and swap-out count Sequences interrupted due to memory pressure Should be near zero; sustained growth is a fault signal
    Error and timeout rates Share of failed requests Set by business tolerance; track client-side and server-side separately

    Capacity Planning Steps

    1. Load test with a representative request distribution (input length, output length, concurrency pattern) to find the max per-instance throughput that still meets TTFT and TPOT SLOs.
    2. Measure peak-period request volume and average output length, and convert to required tokens per second.
    3. Divide the requirement from step 2 by the per-instance throughput from step 1 to get a baseline instance count.
    4. Add headroom for traffic fluctuation, node failures, and rolling deployments. The headroom ratio should be determined from historical fluctuation data.
    5. Compute scaling lead time and confirm whether traffic during cold starts exceeds existing capacity. If not, raise the minimum replica count or improve the model loading path.

    Example (numbers are illustrative—replace with your load test results): peak arrival of 20 requests per second with an average output of 300 tokens yields a requirement of 6,000 tokens per second. If load testing shows one instance sustains 1,500 tokens per second within SLO, the baseline is 4 instances. Adding 25% headroom and rounding up gives 5 instances.

    5. Troubleshooting Order and Takeaways

    When troubleshooting, first identify which phase the problem occurs in, then inspect layer by layer.

    Troubleshooting Checklist

    • Out of memory at startup: Verify weight size first, then check reserved memory for activations, CUDA graphs, and KV Cache. Reducing max sequence length or concurrency settings is usually faster than swapping hardware.
    • OOM or frequent preemption under load: Check whether max concurrency × max context length exceeds the memory budget, and review block size and scheduling policy.
    • High TTFT: Check queuing delay first. If queuing dominates, the problem is capacity or admission control; if queuing is short but prefill is slow, consider chunked prefill, reducing the share of long prompts, or adjusting batch size.
    • High and volatile TPOT: Check whether batch size is too large, whether long-prompt prefill is interleaving with decoding, and whether CPU-side tokenization or post-processing has become the bottleneck.
    • Low throughput with low GPU utilization: Usually insufficient batching, requests that are too small, or a constrained data path—check client concurrency and networking.
    • Latency still high after scaling: Confirm new instances have finished loading and warming up, and check whether the load balancer is routing traffic to unready instances.

    Takeaways

    Inference deployment optimization typically proceeds in this order: use metrics to locate the bottleneck, choose techniques that match that bottleneck, then use load test results to determine scaling size. Paged KV Cache addresses memory utilization, operator fusion reduces per-step overhead, and continuous batching raises GPU utilization. All three depend on the specific request distribution and hardware—there is no fixed multiplier that holds for every scenario.

    Before going live, run a load test on sampled real traffic, record TTFT, TPOT, throughput, and memory curves, and use those results to set scaling thresholds and instance counts.