Compute Bottlenecks and KV Cache Management in LLM Inference Services
This article examines the key factors that determine concurrency capacity in large language model (LLM) inference services, with a focus on the memory footprint of KV Cache and its impact on throughput. It provides a practical framework for estimating memory usage and concurrency limits, compares three strategies for handling inactive sessions—retention, offloading, and recomputation—and discusses prefix caching, session tiering, and admission control policies for managing demand beyond compute supply. The goal is to help engineers make data-driven decisions for capacity planning and service stability.
What Determines Concurrency Capacity
In conversational LLM services, each request goes through two distinct phases during generation. The prefill phase processes the user input and historical context in a single pass. It is compute-intensive and primarily consumes computational throughput. The decode phase generates tokens one at a time. For each new token, the model must read the model weights and the cached key-value (KV) vectors from prior tokens, resulting in heavy memory access. This phase is typically bound by GPU memory bandwidth, leaving compute units frequently idle while waiting for data.
The practical constraint for a service provider is: at any given moment, how many requests can the GPU hold in memory and continue advancing through decode? The more tokens produced per unit of time, the faster individual responses complete, which frees up resources. The scheduler can then allocate those resources to the next request in the queue. Therefore, both throughput and concurrency are directly tied to the token generation rate per second.
For one-shot question-answering, the session can be closed as soon as the response is delivered, allowing resources to be recycled quickly. For multi-turn conversations, however, the historical context grows continuously, and every turn occupies resources. Under the same memory budget, multi-turn sessions support far fewer concurrent requests than single-turn requests.
Why KV Cache Consumes So Much GPU Memory
Every time a Transformer model generates a new token, it must perform attention over all previous tokens. To avoid redundant computation, inference frameworks store the Key and Value vectors for each layer—this is the KV Cache. Its size grows linearly with sequence length, and each active request maintains its own private copy.
The memory footprint of a single request’s KV Cache can be estimated with the following formula:
KV bytes = 2 × num_layers × num_kv_heads × head_dim × sequence_length × bytes_per_element
The factor of 2 accounts for storing both Key and Value. When using Grouped Query Attention (GQA), where the number of KV heads is significantly smaller than the number of query heads, the memory footprint is noticeably reduced. The following illustrative code demonstrates the calculation method; the actual model configuration may vary.
def kv_cache_bytes(layers, kv_heads, head_dim, seq_len, dtype_bytes=2):return 2 * layers * kv_heads * head_dim * seq_len * dtype_bytes# The factor of 2 accounts for storing both Key and Value.# Example configuration: 32 layers, 8 KV heads, head dim 128, context length 4096, FP16size = kv_cache_bytes(32, 8, 128, 4096)print(f"{size / 2**20:.0f} MiB") # Output: 512 MiB
As this example illustrates, the KV Cache for a single request can be hundreds of MiB. If a single GPU serves many long-context requests simultaneously, memory is quickly exhausted.
Estimating Concurrency Capacity
The theoretical upper bound for concurrency can be estimated as follows:
- Calculate the memory available for KV Cache: total GPU memory × utilization ceiling − model weights − activation memory and runtime overhead.
- Compute the per-request KV Cache size for the average context length using the formula from the previous section.
- Divide the result from step 1 by the result from step 2 to obtain the theoretical concurrency limit.
def max_concurrency(total_mem, util, weight_mem, runtime_mem, per_req_kv):usable = total_mem * util - weight_mem - runtime_memif usable <= 0:return 0return int(usable // per_req_kv)
This result is only a theoretical value. In real traffic, request lengths follow a long-tail distribution—a small number of very long requests can consume a disproportionate share of memory, pulling down the effective peak. Capacity planning should therefore estimate based on the P95 or P99 context length, not just the average. Headroom should also be reserved for traffic spikes to avoid memory exhaustion, which could cause requests to be rejected or forced to queue.
Three Approaches to Handling KV Cache
When GPU memory cannot accommodate all active sessions, the system must decide how to manage KV Cache for sessions that are temporarily inactive. Three common strategies exist:
- Retain in GPU memory. This provides the lowest recovery latency but consumes the most memory and has the highest capacity cost. It suits high-frequency, real-time interactions.
- Offload to host memory or local SSD. This frees GPU memory, but recovery requires transferring the data back to the GPU. The transfer time depends on data size and link bandwidth, and the scheduler must account for this latency.
- Discard and recompute when needed. This uses no storage, but recovery requires re-running the full prefill over the complete history. The longer the history, the higher the computation cost and the longer the time to first token.
| Strategy | GPU Memory Usage | Recovery Latency | Additional Cost | Recommended Use Case |
|---|---|---|---|---|
| Keep in GPU memory | High | Lowest | Memory capacity | High-frequency, real-time interactions |
| Offload to host memory or local storage | Low | Moderate, data-size dependent | Transfer bandwidth, storage management | Sessions with a moderate chance of reuse |
| Discard and recompute | None | Grows with history length | Compute resources | One-shot requests or rarely resumed sessions |
The choice among these strategies depends on three factors: the probability of session reuse, the length of historical context, and the recovery latency the application can tolerate. One-shot question-answering requests can usually be discarded, as recomputation cost is limited and such recomputation is rarely triggered. Long-running, frequently resumed sessions, on the other hand, are worth keeping in memory or offloading—otherwise, every resumption incurs significant redundant computation.
Prefix Caching and Session Tiering
Many requests share a common prefix, such as system prompts, fixed tool descriptions, or knowledge-base snippets. The KV Cache computed for these prefixes can be cached with a content hash. When a subsequent request matches the cached prefix, the system can reuse the KV Cache directly and skip the redundant prefill computation. The benefit of prefix caching depends on the actual hit ratio and should be validated with production metrics rather than assumed.
Session tiering is another common practice. The system can classify sessions into three tiers—hot, warm, and cold—based on recent activity and history length, and apply separate strategies to each: retention, offloading, and recomputation.
def choose_tier(idle_seconds, history_tokens):# Thresholds are examples; adjust them based on measured hit rate and latency budget.if idle_seconds < 60:return "gpu"if idle_seconds < 3600 and history_tokens < 32000:return "host_memory"return "recompute"
In addition, early turns of a long conversation can be compressed into a summary, reducing the length of subsequent prefill. Compression inherently loses detail, so the product should inform users transparently and allow key content to be preserved in its original form.
Scheduling and Admission Control Under Capacity Pressure
When request volume exceeds compute supply, the service provider needs to protect the core experience through scheduling policies rather than letting all requests slow down uniformly. Common measures include:
- Queueing and timeouts: Set a maximum waiting time; return a clear message when it is exceeded, preventing requests from piling up indefinitely.
- Length limits: Constrain the maximum input and output length per request to reduce the memory footprint of long-tail requests.
- Tiered quotas: Allocate concurrency quotas by service level, prioritizing critical business and paid scenarios.
- Model downgrade: Switch to a smaller or quantized model version during peak periods. This changes output quality and must be disclosed transparently to users.
The effectiveness of these policies requires continuous monitoring. It is recommended to track GPU memory utilization, queueing time, time to first token, token generation rate per second, and KV Cache hit rate. These metrics should directly drive capacity expansion, policy adjustments, or quota changes, rather than relying on intuition.
Operational and Communication Considerations
When capacity is tight, technical decisions and business decisions become intertwined. Adjusting concurrency quotas, pausing new sign-ups, or changing plan entitlements are business decisions that should be grounded in real capacity data and user-impact assessments. External communication should clearly state the scope of impact, the expected improvement path, and how existing users’ entitlements will be handled. Keep communication open, verifiable, and specific to avoid ambiguity and misunderstanding.
Practical Checklist
- Use the real request-length distribution for capacity planning; do not rely on averages.
- Establish monitoring for KV Cache usage, offload transfer volume, and hit rate.
- Apply different strategies to one-shot requests versus long-running sessions.
- Set explicit latency budgets for offloading and recomputation; trigger downgrades or queueing when budgets are exceeded.
- Keep a fallback path and run stress tests before rollout.
Conclusion
The concurrency capacity of an inference service is jointly determined by GPU memory capacity, decode throughput, and request length, with KV Cache being the dominant consumer of GPU memory. For handling temporarily inactive sessions, retention, offloading, and discard-with-recomputation each come with different trade-offs; the choice should be based on real data about session reuse probability and recovery latency. Under compute constraints, reasonable tiering, rate limiting, and transparent communication are more effective at ensuring service stability than optimizing the cost of a single request in isolation.
