LLM Serving Under Compute Constraints: Capacity Planning and Session Management
When compute is scarce, LLM serving teams must quantify how many active sessions they can support, how long to retain KV cache, and when to admit new users. This article discusses memory-bandwidth bottlenecks, tiered KV cache, recomputation cost, admission control, product quotas, observability metrics, and common pitfalls for capacity planning and session management.
1. Problem Definition: What an LLM Service Can Still Provide When Compute Is Tight
Resource consumption in LLM chat services is concentrated in two stages. The prefill stage processes all user input context at once. It is compute-intensive and suitable for parallel execution. The decode stage generates output tokens one by one. Each generated token requires reading model weights and historical KV cache, so this stage is clearly limited by GPU memory bandwidth.
When resources are insufficient, service providers usually have three options: scale out, rate limiting, and degradation. Scaling is constrained by procurement cycles and cost, so it is difficult to complete in the short term. Rate limiting and degradation directly affect user experience. From an engineering perspective, three questions need to be quantified: how many active sessions can be served concurrently, how long cache should be retained, and when new users can be admitted. Only after quantification can an appropriate strategy be selected.
2. Memory Bandwidth Bottleneck in the Decode Stage
In an ideal model that ignores other overheads, the time for a single decode step is approximately equal to the time required to read model weights and active KV cache. At this point, the GPU’s compute units are often far from fully utilized; the real limit is GPU memory bandwidth.
This leads to three conclusions:
- Increasing the batch size amortizes the cost of reading weights and improves throughput.
- Every active session occupies KV cache. As batch size grows, GPU memory will be exhausted first.
- Therefore, concurrency capability is jointly determined by GPU memory capacity and bandwidth utilization.
The following function can be used for a rough estimate. The parameters are illustrative and should be replaced with model configuration and measured data in practice.
def estimate_max_concurrency(gpu_memory_gb: float, # Total GPU memory per cardweight_memory_gb: float, # Memory occupied by model weightsreserved_ratio: float, # Ratio reserved for activations, fragmentation, etc.; 0 to 1kv_bytes_per_token: int, # KV cache bytes per token, determined by layers, heads, head dimension, and data typeavg_context_tokens: int, # Average context length of active sessions) -> int:"""Estimate the number of active sessions that can be retained concurrently on one GPU. This model considers only GPU memory capacity, not bandwidth constraints."""usable_gb = gpu_memory_gb * (1 - reserved_ratio) - weight_memory_gbif usable_gb <= 0:return 0kv_per_session_gb = kv_bytes_per_token * avg_context_tokens / (1024 ** 3)return int(usable_gb // kv_per_session_gb)
This function provides only an upper bound from the GPU memory dimension. Actual concurrency also needs to be combined with decode throughput tests to find an operating point with acceptable latency.
3. KV Cache: Retain or Discard
KV cache stores the attention intermediate results of historical tokens. If it is retained, subsequent requests can skip repeated prefill computation. The cost is that GPU memory usage grows linearly with context length.
Different scenarios depend on cache to very different degrees:
- Single-turn question answering or short conversations: cache reuse value is low and can be released after the session ends.
- Long-running tasks, multi-turn creation, and code collaboration: cache reuse rate is high, and discarding it makes recomputation expensive.
- Intermittent user return visits: cache value depends on return probability and recomputation cost.
Therefore, whether to retain cache can be viewed as a cost problem. On one side is the opportunity cost in concurrency caused by occupied GPU memory; on the other side is the time to first token and compute consumption caused by recomputation. The comparison changes with load, and there is no one-time answer.
4. Tiered Cache Strategy
A common approach is to manage cache in tiers based on access heat:
- Hot data: remain in GPU memory to serve active sessions.
- Warm data: offload to host memory. When restored, transfer it back over PCIe or similar channels, with latency much lower than recomputation.
- Cold data: write to local high-speed storage and load on demand.
- No cache: release the session completely. On restore, re-prefill based on historical messages.
Below is a simplified two-tier cache example that shows the basic logic of eviction and backfill.
from collections import OrderedDictclass TieredKVCache:def __init__(self, gpu_slots: int, host_slots: int):self.gpu = OrderedDict() # GPU tier, ordered by most recent accessself.host = OrderedDict() # Host memory tierself.gpu_slots = gpu_slotsself.host_slots = host_slotsdef put(self, session_id, kv_blob):self.gpu[session_id] = kv_blobself.gpu.move_to_end(session_id)while len(self.gpu) > self.gpu_slots:old_id, old_blob = self.gpu.popitem(last=False)self.host[old_id] = old_blobwhile len(self.host) > self.host_slots:self.host.popitem(last=False) # Fully discard; recomputation will be needed laterdef get(self, session_id):if session_id in self.gpu:self.gpu.move_to_end(session_id)return self.gpu[session_id], "gpu"if session_id in self.host:blob = self.host.pop(session_id)self.put(session_id, blob)return blob, "host"return None, "miss" # Caller must re-prefill using historical messages
This example does not handle concurrency safety, data serialization, or asynchronous transfer; it only illustrates the tiering idea. In production, eviction policies usually also need to consider session length and recomputation cost.
5. Recomputation Cost on Cache Miss
After a cache miss, the service needs to re-prefill using the full historical messages. Recomputation time generally grows with the number of historical tokens, and long sessions have the highest recovery cost.
The following measures can be taken for this problem:
- Create rolling summaries of historical messages to keep recomputation length within an acceptable range.
- Record historical length for each session and include recomputation cost in priority calculations during scheduling.
- Use a separate queue for recovery requests to avoid competing with new sessions for resources.
- For sessions with no activity for a long time, indicate in the interface that recovery may involve a longer first-response time.
Summary compression loses some detail, so a trade-off is needed between retaining key information and cost. For precision-sensitive scenarios such as code, legal, or medical use, traceability of the original messages should be retained.
6. Admission Control and Queueing
When resources are insufficient, continuing to accept all requests only makes latency worse for all users at the same time. A safer approach is to set admission thresholds and expose capacity pressure explicitly at the entry point.
- Decide whether to accept new requests based on the current number of active sessions and queue length.
- Distinguish request types and prioritize continuity for established sessions.
- Return a clear status and estimated wait time for requests beyond capacity, avoiding unresponsive timeouts.
The following is an illustrative admission decision:
def admit(active_sessions: int, queue_len: int, capacity: int, max_queue: int) -> str:if active_sessions < capacity:return "accept"if queue_len < max_queue:return "queue"return "reject_with_retry_hint"
Thresholds should be set based on load test results. Thresholds that are too loose cause tail latency to spike, while thresholds that are too tight waste available compute.
7. Product Design for Quotas and Subscriptions
Technical capacity directly affects business strategy. When resources are tight, common adjustments include tiered quotas, time-based rate limiting, pausing new purchases while retaining existing service, and providing upgrade paths. These decisions should follow these principles:
- Transparent announcements: explain the reason, impact scope, and recovery conditions, and do not make time commitments that cannot be fulfilled.
- Existing users’ rights should not be silently reduced; changes should be announced in advance.
- Auto-renewal, cancellation, and refund flows should be clear and controllable to reduce complaints caused by incorrect charges.
- After adjustments, validate the effects with observable metrics rather than relying on announcements alone.
8. Observability Metrics
It is recommended to continuously monitor the following metrics:
- Number of active sessions and GPU memory utilization.
- Decode throughput and time to first token (TTFT).
- Cache hit rate, broken down by GPU memory, host memory, and miss.
- Percentiles of queueing time, such as P50, P95, and P99.
- Share of requests rejected due to capacity.
Metrics should be bound to alert thresholds and reviewed after each capacity adjustment to determine whether the strategy meets expectations.
9. Common Pitfalls
- Pitfall 1: High GPU utilization means resources are exhausted. The actual bottleneck may be bandwidth or memory, and multiple metrics should be considered.
- Pitfall 2: More cache is always better. Cache consumes GPU memory, and excessive retention reduces concurrency.
- Pitfall 3: Rate limiting alone solves the problem. Long-term solutions still require scaling, model optimization, and scheduling improvements.
- Pitfall 4: An announcement only says that something is paused without explaining the impact scope. Users assume the worst case, which increases communication cost.
10. Conclusion
Compute scarcity is not a single problem. It is the combined result of concurrency, GPU memory, cache, and product strategy. Engineering teams should first quantify capacity, then design tiered cache, admission control, and session recovery mechanisms, and finally reduce user uncertainty through clear communication.
