Compute Bottlenecks in LLM Inference Services and KV Cache Scheduling Strategies
When chat services scale up, symptoms like queued new sessions, slower responses, and temporarily restricted features often point to a common root cause: insufficient inference compute. This article explains the two phases of LLM inference (prefill and decode), how KV Cache memory determines concurrency limits, and how to balance throughput and latency. It covers three KV Cache handling strategies—retention, offloading, and recomputation—a layered scheduling approach, capacity planning steps, and operational mitigation techniques, concluding with a practical checklist for developers.
Compute Bottlenecks in LLM Inference Services and KV Cache Scheduling Strategies
1. Problem Background
As chat services grow their user base, common symptoms emerge: new sessions queue up, existing sessions respond more slowly, and some features are temporarily restricted. These issues usually stem from insufficient inference compute. To diagnose where the problem lies and how to respond, you first need to understand how inference services consume resources.
2. The Two Phases of Inference
Large language model generation typically happens in two phases.
Phase 1: Prefill. The model reads the user prompt and conversation history in one pass, computes the key and value vectors for every layer, and writes them into the cache. This phase parallelizes computation across many tokens and is primarily compute-bound—the longer the input, the longer it takes.
Phase 2: Decode. The model generates new tokens one at a time. Each token requires reading all model weights plus the session’s cached KV Cache. The per-step computation is small but memory-access intensive, so performance here is usually limited by memory bandwidth rather than peak compute.
Understanding this distinction clarifies the optimization direction: prefill needs more compute resources, while decode benefits from higher memory-access efficiency and smarter batching.
3. What Determines the Concurrency Limit
GPU resources determine how many concurrent sessions a service can sustain. A rough estimation framework:
max_sessions ≈ memory_available_for_cache / average_kv_cache_per_session
The KV Cache size per token can be estimated as:
kv_bytes_per_token = 2 × layers × kv_heads × head_dim × dtype_bytes
The factor of 2 accounts for storing both keys and values. Memory usage scales linearly with context length, so long conversations exhaust VRAM much faster than short Q&A interactions.
In code, the budget calculation looks roughly like this:
budget = total_gpu_memory - model_weights - runtime_reservekv_per_token = 2 * layers * kv_heads * head_dim * dtype_bytesmax_sessions = budget // (avg_context_len * kv_per_token)
This result is only a theoretical upper bound. In practice, you must also account for fragmentation, bursty context lengths, and overhead from the inference framework itself—so always leave headroom when planning capacity.
4. The Throughput-Latency Trade-off
Operators typically care about two metrics: throughput (total tokens output per unit of time) and latency (time to first token and per-token output speed as perceived by users).
Increasing the batch size improves GPU utilization and raises total output per unit time. But larger batches mean each request gets a smaller share of compute and bandwidth, so individual user latency rises. The goal of scheduling is to maximize throughput within acceptable latency constraints.
Another key factor is the session lifecycle. Once a session finishes its current reply and goes idle, its KV Cache becomes reclaimable memory. The faster it is reclaimed, the sooner that memory can serve new requests.
5. Three KV Cache Handling Strategies
When a session is idle, operators can choose among three strategies:
1. Keep in VRAM. The KV Cache stays in GPU memory. Resuming the conversation requires no extra computation, giving the lowest latency. The downside is maximum memory usage—best suited to high-frequency, continuous interactions.
2. Offload to other storage. Move the KV Cache to host memory or local storage. This frees VRAM, but resuming requires reloading the data. The cost depends on data volume and I/O bandwidth; offloading long contexts is expensive.
3. Drop and recompute. Don’t store the KV Cache at all; instead, re-run prefill over the conversation history when resuming. This consumes no storage, but recomputation cost grows linearly with conversation length—the longer the context, the longer the wait.
No single strategy is universally best. The right choice depends on:
- Session reuse probability: If one-shot Q&A dominates, dropping and recomputing is cheap; frequently continued conversations are better kept or offloaded.
- Context length: Short contexts recompute quickly; long contexts favor offloading or retention.
- Hardware constraints: VRAM capacity, host memory, and storage I/O speed jointly determine whether offloading pays off.
- Business tolerance: How sensitive users are to resume delays dictates how much recomputation latency is acceptable.
In real systems, a tiered combination is common: active sessions stay in VRAM, short-term idle sessions are offloaded, long-unused sessions are dropped, and recomputation happens on demand when resuming.
6. Implementing the Scheduling Strategy
The following pseudocode illustrates a tiered management approach based on idle duration, for logic illustration only:
def schedule(sessions):for s in sessions:if s.idle_seconds > IDLE_LIMIT:offload_kv(s) # offload to lower-tier storageif s.is_active and not s.in_gpu:ensure_capacity(s) # evict least recently used sessions if neededload_or_recompute(s) # prefer loading; fall back to recompute
Three key points in this logic:
- Use idle duration as the reclamation trigger, avoiding premature release of sessions likely to be reused.
- Use least-recently-used (LRU) as the eviction criterion to minimize disruption to hot sessions.
- Provide two recovery paths—loading with a fallback to recomputation—to keep the service available.
A production implementation must also address concurrency safety, prioritization, fairness, and failure retry.
7. Practical Steps for Capacity Planning
Capacity planning should not rely on averages alone. Follow these steps:
- Profile the real session length distribution. Watch for long-tail requests—average context length often masks the resource consumption of a few extremely long sessions.
- Measure peak concurrency and session reuse rates. Estimate peak hours and normal hours separately.
- Derive per-GPU capacity from service targets. For example, set upper bounds on time-to-first-token and per-token speed, then use load testing to determine the stable concurrency each GPU can handle.
- Reserve redundancy. Keep a buffer of resources for traffic spikes, node failures, and version rollouts.
- Trust load test results. Theoretical peaks are only estimation references and should not be used directly as external commitments.
8. Operational Mitigation Measures
When compute genuinely falls short of demand, technical fixes must be paired with operational strategies:
- Queuing and admission control: When capacity is insufficient, clearly communicate expected wait times to users and prevent unbounded queues from causing timeouts.
- Tiered rate limiting: Allocate quotas by request type, context length, and user priority to keep critical requests available.
- Context length limits: Cap extremely long sessions and prompt users to start a new session, reducing per-session resource consumption.
- Prefix reuse: Cache and reuse identical system prompts or document prefixes to cut repeated prefill costs.
- Model tiering: During peak periods, route non-critical requests to smaller models to protect quality for core use cases.
- Transparent communication: Inform users of resource conditions and estimated recovery times to reduce frustration caused by information gaps.
9. Developer Checklist
- Monitor VRAM usage, KV Cache hit rate, queue length, time-to-first-token, and per-token output speed.
- Set idle timeouts and maximum context lengths for sessions to prevent long-term resource occupation.
- Cover long contexts, traffic spikes, and multi-session concurrency in load tests.
- Record timing separately for each recovery path (loading, offload-in, recomputation) to pinpoint bottlenecks.
- Integrate resource alerts into your monitoring system with tiered thresholds, so you can scale up or throttle before capacity runs out.
10. Conclusion
The concurrency capacity of an inference service is jointly determined by VRAM capacity, memory bandwidth, scheduling policy, and user behavior. Understanding how KV Cache occupies and releases memory across the session lifecycle—and designing a strategy that combines retention, offloading, and recomputation accordingly—is the core approach to relieving compute pressure. On that foundation, capacity planning, admission control, and transparent operational communication keep the service stable and predictable under limited resources.
