Optimizing LLM Inference Services Under Limited GPU Compute
This article explains why large language model services start rate-limiting or pausing new sign-ups when compute runs short, and how to fix it. It breaks down the two phases of inference—prefill (compute-bound) and decode (memory-bandwidth-bound)—and shows how KV Cache size, which grows linearly with sequence length and concurrency, becomes the true ceiling on how many users a service can handle at once. It then walks through proven engineering techniques: continuous batching, paged KV Cache management, and offload/recompute tradeoffs, followed by guidance on elastic scaling and cost balance. Developers and operators will gain a practical framework for capacity planning, throughput tuning, and keeping GPU resources fully utilized.
The Symptom: Why Do LLM Services Get Rate-Limited?
Lately, several AI chat products have started pausing new user sign-ups or asking members to wait in a queue. On the surface this looks like a business and operations decision, but from an engineering standpoint the root cause usually points to the same hard constraint: GPU supply on the inference side can’t keep up with user growth.
To understand this, start with one basic fact. In chatbot-style scenarios, the resource that determines how many users you can serve concurrently at peak is typically not storage and not network bandwidth—it’s the GPU’s compute capacity and memory (VRAM). This article works up from the nature of inference compute, unpacks the cost of compute layer by layer, and lays out optimization paths you can actually ship.
1. The Two Phases of Inference: Prefill vs. Decode
Autoregressive inference in a large language model splits cleanly into two phases with very different resource profiles:
- Prefill: The model processes the user’s entire prompt in parallel, computing the representation for every input token in a single pass. This phase is compute-bound and fully utilizes the GPU’s compute units.
- Decode: The model generates output tokens one at a time, handling only a single new token per step while repeatedly reading model weights and the historical KV Cache. This phase is memory-bandwidth-bound, and the GPU’s compute units are often left underutilized.
This distinction is critical. Setting aside the memory-bandwidth bottleneck of decode, we can approximate that the GPU is running near full tilt against its bottleneck. How many tokens a user gets per second determines how fast a single request finishes; and how many such requests you can sustain at once is determined by how many concurrent sessions fit in GPU memory. That is what “compute pressure” actually means in engineering terms.
2. What Really Caps Concurrency: The KV Cache
In autoregressive decoding, to avoid recomputing attention over all previous tokens at every step, the system caches each token’s Key and Value vectors. This is the KV Cache.
Its size can be approximated as:
KV Cache ≈ 2 × num_layers × num_heads × head_dim × sequence_length × concurrency × bytes_per_element
Here the factor of 2 accounts for the two caches, K and V. The formula reveals a harsh reality: KV Cache memory usage grows linearly with both sequence length and the number of concurrent users. When many users are active and each carries a long context, VRAM fills up fast. At that point, even if the GPU still has compute headroom, the system can’t admit new requests—because there’s nowhere to put the new KV Cache.
This is precisely the technical driver behind many services choosing to rate-limit or pause sign-ups: the model can still compute; the problem is that VRAM can’t hold any more concurrent sessions.
3. Engineering Techniques for Throughput and Concurrency
Once the bottleneck is clear, engineering has a mature toolkit for addressing it. The core idea can be summed up as: make limited VRAM carry as many effective concurrent requests as possible.
3.1 Continuous Batching
The traditional approach is “static batching”: requests are grouped into a batch, and the entire batch must finish before the next one can load. This leaves requests that finish early holding VRAM while idling, and GPU utilization stays low.
Continuous batching refines the scheduling granularity down to each individual decode iteration: as soon as a request finishes and frees its VRAM, its slot is handed immediately to a new request waiting in the queue. The scheduling loop looks roughly like this:
# Continuous batching scheduler core loop (illustrative)while engine.running:# 1. New requests arrive; admit them to the running batch if VRAM allowsfor req in waiting_queue:if kv_cache_can_allocate(req):batch.add(req)# 2. Run one decode iteration on the current batch (each request emits one token)tokens = model.decode_step(batch)# 3. Completion check: exit on end token or max length, then free memoryfor req in batch:if req.is_finished(tokens[req]):batch.remove(req)kv_cache_release(req) # slot immediately freed for new requests
This “iteration-level scheduling” significantly boosts GPU utilization and overall throughput, making it the first-priority technique for raising concurrency capacity.
3.2 Paged Memory Management
When the KV Cache is repeatedly allocated and freed within contiguous VRAM, it tends to create heavy memory fragmentation, leading to the awkward situation where “there’s still memory available, but no contiguous block can be allocated.” The industry widely borrows the virtual memory paging idea from operating systems: the KV Cache is split into fixed-size blocks that are allocated on demand and mapped non-contiguously. This greatly reduces fragmentation and also lets multiple requests share cache blocks for identical prefixes (such as the same system prompt), saving even more memory.
3.3 Offload vs. Recompute Tradeoffs
When VRAM gets tight, there’s another class of optimizations based on traffic characteristics. Looking at real chat traffic reveals a pattern: a large share of sessions are one-off and rarely reused. For example, “Will it rain today?”, “Help me write a short leave-of-absence email,” or “Suggest a simple home-cooked dish”—these requests are usually asked once and left behind, with a low probability that the user returns to the same session.
Based on this, a system can adopt an aggressive strategy: when memory is critical, it prioritizes discarding or offloading the KV Cache of these low-value sessions, freeing precious VRAM for new requests. If the user eventually comes back to continue the conversation, the cache is swapped back in from slower media such as CPU memory or local SSD, or is simply recomputed from the full history. Compared to “flat-out rejecting new users due to insufficient memory,” paying for one extra recomputation is usually well worth it. This is a classic trade of a little compute for overall availability.
4. Balancing Elastic Resources and Cost
Beyond the technical measures, balancing capacity and cost matters just as much. When deploying inference services in the cloud, you can leverage general cloud infrastructure capabilities for elasticity:
- GPU cloud servers and containerized deployment: Containerizing the inference service makes it easy to replicate instances quickly and scale out horizontally.
- Auto-scaling: Automatically add or remove instances based on metrics like concurrent requests, VRAM usage, and queue length—scaling up at peak and down at trough, so you don’t pay for peak capacity year-round. For example, on Baidu AI Cloud, you can combine auto-scaling with monitoring and alerting to schedule GPU resources dynamically against business metrics.
- Request queuing and priority scheduling: When compute is genuinely short, use sensible queue and tiering policies (such as prioritizing paying users, or rate-limiting long sessions separately) to smooth the experience rather than bluntly rejecting service.
- End-to-end monitoring: Set up monitoring and alerting on key metrics like token throughput, VRAM usage, and queue latency to anticipate capacity problems ahead of time.
5. Practical Advice for Developers and Enterprises
- Measure capacity before scaling out: Use your target concurrency and average context length to estimate the required VRAM and GPU count, and avoid blindly piling on cards.
- Route large and small models separately: Send simple, high-frequency, low-difficulty requests to smaller models and reserve large models for complex requests, diluting the per-unit compute cost across the whole.
- Maximize cache reuse: Reuse prefix caching for stable prefixes such as system prompts and common documents to cut redundant computation.
- Differentiate service by priority: Design tiered concurrency quotas and queuing policies for different payment tiers so compute flows to higher-value requests.
- Keep load-testing and tuning: Parameters for continuous batching, paged management, and offload/recompute need repeated tuning against real traffic—there’s no set-and-forget configuration.
Conclusion
“Compute pressure leads to rate-limiting” may look like an operational challenge for a product, but it’s really an inevitable engineering problem arising from three factors in LLM inference: the VRAM constraint, the memory-bandwidth bottleneck, and KV Cache management. For developers, once you understand the resource profiles of prefill and decode, and grasp how the KV Cache determines the concurrency ceiling, you hold the keys to the solution: raise throughput with continuous batching, squeeze every drop out of VRAM with paging and offload, and balance cost with auto-scaling. Compute will always be finite, but strong scheduling and optimization can make every unit of it count.
