LLM Serving Under Compute Constraints: Concurrency Capacity and Access Strategies
LLM serving capacity depends on accelerator throughput, memory bandwidth, and the memory required for each session’s KV cache. This article explains these constraints, provides a simplified concurrency estimator, and outlines scheduling and access strategies for maintaining stable service when resources are limited.
1. Why Hardware Capacity Determines Concurrent Sessions
The concurrency capacity of a large language model inference service depends primarily on accelerator compute capacity and device memory. The server does not process only one request at a time. Instead, it groups requests from multiple users into a batch and generates one new token for each session during each decoding step. When a session finishes, the system releases its allocated memory and admits another queued request.
Token throughput therefore directly affects how many sessions the system can support simultaneously. More accelerators and higher throughput per accelerator increase peak concurrency capacity.
2. Where Token Generation Becomes Bottlenecked
Inference typically has two stages:
- Prefill: Processes the input prompt in one pass. This stage involves substantial computation but is highly parallelizable, making it primarily compute-bound.
- Decode: Generates output tokens one at a time. Each step reads the model weights and the existing attention cache. Relative to prefill, it involves less computation and more memory access, making it primarily memory-bandwidth-bound.
For long responses, decoding accounts for most of the inference time. The bandwidth constraint can be understood through this rough relationship:
Lower bound on time per decoding step ≈(model weight bytes + KV cache bytes across all sessions in the batch)÷ device memory bandwidth
This relationship highlights two points. First, larger batches require more KV cache data to be read at each step, increasing step time. Second, once memory bandwidth is saturated, spare compute capacity alone cannot keep increasing throughput.
A GPU operating at full capacity should therefore be understood in terms of both memory bandwidth and compute utilization, rather than a single utilization metric.
3. KV Cache: A Key Constraint on Concurrency
The attention mechanism caches the keys and values of previous tokens in the KV cache. This cache grows linearly with context length and is a major source of memory consumption as concurrency increases.
The KV cache size per token can be estimated as:
KV cache bytes per token =2 × number of layers × number of KV heads× head dimension × bytes per element
Consider an illustrative model with 32 layers, 8 KV heads, a head dimension of 128, and 16-bit floating-point storage at 2 bytes per element:
2 × 32 × 8 × 128 × 2 = 131,072 bytes, or approximately 128 KiB
At a context length of 8,192 tokens, one session requires approximately:
8,192 × 128 KiB = 1 GiB of KV cache
The more sessions resident in device memory, the larger the combined cache footprint.
The important implication is that concurrency depends not only on compute capacity but also on how many session caches fit in memory. Two clusters with identical compute capacity can support substantially different numbers of concurrent sessions if their average context lengths differ by several times.
4. Example Code for Estimating Capacity
A simplified memory model can provide an initial upper bound for capacity planning. The following code is illustrative only. Actual deployments must also account for activations, memory fragmentation, parallel partitioning, and scheduling policies.
The calculation uses binary memory conversions. Although the parameter names retain gb and kb, use consistent GiB and KiB values when applying this estimate.
def estimate_max_concurrency(gpu_mem_gb: float, # Memory per GPU (GiB)num_gpus: int, # Number of GPUs participating in parallel executionweight_gb: float, # Total model weight memory (GiB)reserve_ratio: float, # Fraction reserved for activations, fragmentation, etc.kv_per_token_kb: float, # KV cache size per token (KiB)avg_ctx_tokens: int, # Average context length in tokens) -> int:total_mem = gpu_mem_gb * num_gpususable = total_mem * (1 - reserve_ratio) - weight_gbif usable <= 0:raise ValueError("Model weights and reserved memory exceed available GPU memory")kv_per_seq_gb = kv_per_token_kb * avg_ctx_tokens / 1024 / 1024return int(usable // kv_per_seq_gb)
For a single GPU with 80 GiB of memory, 16 GiB of model weights, a 10% reserve, 128 KiB of KV cache per token, and an average context length of 2,048 tokens:
- Memory available for KV cache: 80 × 0.9 − 16 = 56 GiB
- KV cache per session: 128 × 2,048 / 1,024 / 1,024 = 0.25 GiB
- Theoretical concurrency limit: 56 / 0.25 = 224 sessions
This is a memory-only theoretical limit. Real throughput also depends on bandwidth and scheduling, so the concurrency a system can serve reliably is typically lower.
5. How Scheduling Affects Capacity
- Continuous batching: Admits new requests as soon as existing sessions finish, rather than waiting for the slowest request in an entire batch. This improves device utilization.
- Interleaving prefill and decode: Prefilling long prompts consumes compute resources and can slow sessions that are already decoding. A common approach is to split prefill into chunks to limit its impact on latency.
- Maximum output length: This setting limits how much additional cache a session may consume during generation. An excessively high limit reduces the number of concurrent sessions the system can accommodate.
- Prefix reuse: Sessions with the same system prompt can share the corresponding KV cache, reducing duplicate computation and memory usage.
6. How Providers Respond to Resource Constraints
When resources are insufficient, service providers typically combine several measures:
- Rate limiting and queueing: Set admission thresholds based on capacity. Requests above those thresholds are queued or receive an explicit busy response, preventing all requests from slowing down simultaneously.
- Tiered quotas: Allocate resources according to user tier, context length, and output length, giving priority to core workloads.
- Staged access: Gradually enable access for new users or features as capacity allows, protecting latency for existing users.
- Graceful degradation: Preserve service availability by reducing maximum output length or routing some requests to smaller models.
