Inference Cache Slowdown: The Hidden Cost of Caching in LLM Serving

    This article examines a counterintuitive production incident where enabling a cross-request attention cache left median latency unchanged but pushed p99 latency from 3.96s to 17.3s on a large MoE model. It breaks down the three-layer workload structure behind the issue, provides a measurable checklist of where cache costs actually go, and outlines fixes such as asynchronous writes, hotspot sharding, topology alignment, admission control, and eviction policies. Readers will learn how to diagnose whether a slowdown comes from waiting rather than computing, and how to keep caching in net-positive territory.

    1. A Counterintuitive Production Incident

    A team serving inference for a very large mixture-of-experts (MoE) model ran into a phenomenon that defied expectations. The hardware was a single node with 8 high-end accelerator cards. The model used a sparse activation architecture: the total parameter count was huge, but each token activated only a small subset of the expert networks. To speed up long-context scenarios, the team deployed a cross-request attention cache that stored previously computed intermediate attention results and reused them directly when a new request shared a similar prefix.

    The expected benefit was clear: eliminate redundant prefix computation. The actual result was that median latency barely moved, while the tail 1% of requests (p99) jumped from 3.96 seconds to 17.3 seconds, roughly a 4.4x increase. The team’s first instinct was a full rollback.

    The value of this case is that it puts a long-overlooked fact on the table: reading from a cache is not a zero-cost operation. Cache writes, indexing, serialization, network transfer, and concurrent queuing all consume resources that should have gone to computation. When these costs exceed the computation saved, the cache stops being an accelerator and becomes an amplifier—amplifying the long tail of latency.

    2. Understand the Workload Shape Before Talking About Caching

    To reproduce and locate this class of problem, you first need to see the system’s three-layer structure.

    Layer 1: Attention compression mechanism. This scenario uses a low-rank latent attention design that compresses each token’s key-value information into a shared low-dimensional vector. The direct benefit is that the amount of intermediate data each token needs to persist or transfer stays constant regardless of how many attention heads the model has. At FP8 precision, every 256 tokens are packed into one block of roughly 12.4MB, which works out to only about 48.4KB per token. This number matters—it means cache entries are not “small,” and a single hit on a long context can move nearly a hundred megabytes of data.

    Layer 2: Prefill context parallelism. The compute cost of the prefill stage for long text grows with the square of the length. In practice, the sequence is split into segments assigned to multiple cards for parallel processing, and collective communication then synchronizes each rank’s intermediate results to all participants. The cost of this design is tight coupling: the 8 ranks mesh like gears, and if any one card is slowed down, the other seven can only idle and wait.

    Layer 3: Two-tier cache. The L1 cache sits close to compute in local host memory—fast but capacity-limited. The L2 cache lives in an external key-value store service—large capacity, shareable across multiple inference instances, essentially a public library.

    The bottleneck lands exactly on the L2 cache. An analogy helps: individual chain stores each keeping their own running ledger (L1 cache) is fast, but if headquarters requires all entries to be consolidated into a single master ledger (L2 cache) with only one accountant recording them, then during peak hours eight stores writing simultaneously all pile up at the accountant’s desk—while the stores’ customers (compute resources) can only wait.

    3. Where the Cost Actually Goes: A Verifiable Checklist

    Breaking “cache reads are slow” into measurable items is the only way to apply the right fix:

    1. Write amplification and serialization. Each block’s metadata, index, and lifecycle must pass through a unified entry point, creating a single serialization point under a hot key space.
    2. Network round trips and bandwidth contention. L2 cache reads and writes share the same NIC as the collective communication for context parallelism, and the two crowd each other out.
    3. Synchronization blocking. Under the parallel topology, the slowest rank sets the overall pace, and cache jitter is amplified into a global stall.
    4. Hit-determination overhead. Prefix matching, hash computation, and block-alignment checks themselves consume CPU and memory bandwidth.
    5. Memory pressure and reclamation. L1 cache occupies host memory, and paging or reclamation directly hits latency.
    6. Tail amplification. Any occasional jitter in the items above gets amplified to p99 through parallel synchronization.

    A practical triage order: fix the request sample, collect p50, p95, p99, and GPU utilization with the cache off and on; if p50 stays flat while p99 worsens and GPU utilization drops at the same time, you can conclude it is a “waiting” problem rather than a “computing” problem.

    1. Observation matrix (same load-test sample, only toggling the cache)
    2. Metric Cache off Cache on Reading
    3. p50 latency baseline ≈baseline compute path unchanged
    4. p99 latency 3.96s 17.3s long tail amplified
    5. GPU util (avg) high drops resources waiting
    6. NIC in/out BW low rises sharply cache traffic crowds out communication

    4. The Fix: Bringing the Cache Back into Net-Positive Territory

    1) Take the L2 cache off the critical path. The core principle is asynchrony: return as soon as prefill completes, and hand cache writes to a background queue for batched flushing; for reads, use a “check local first, compute directly on a miss” strategy, and never let a request block on a remote lookup.

    2) Shard to spread hotspots. Apply consistent sharding by block hash to split a single entry point into multiple parallel shards, avoiding all instances contending for the same metadata node.

    3) Align with the parallel topology. Align cache shards with the rank layout of context parallelism, keep data movement within a node as much as possible to reduce cross-node round trips, and reserve a dedicated bandwidth channel for cache traffic when necessary.

    4) Admission control and benefit estimation. Only cache blocks that are “likely to be reused and cheap to rebuild.” A simple criterion:

    1. def should_cache(block, hit_rate, read_bytes, recompute_ms, link_bw_gbps):
    2. # Estimate read time (ms); convert link bandwidth to MB/ms
    3. read_ms = read_bytes / (link_bw_gbps * 1e6 / 1e3)
    4. # Cache only when saved compute time clearly exceeds read cost
    5. return hit_rate * recompute_ms > read_ms * 3

    5) Capacity and eviction policy. L1 cache evicts with weights based on “recent reuse + rebuild cost”; L2 cache sets a total size cap and lease expiration to avoid stale entries occupying space long-term.

    6) Make load testing routine. Add the cache toggle to the regression matrix, use p99 rather than the mean as the admission gate, and build monitoring and alerting dashboards for cache hit rate, read/write bytes, and queueing time.

    5. Transferable Takeaways

    • Caching is essentially trading space and bandwidth for compute, and it only holds when the hit rate is high enough and the per-read cost is low enough.
    • In tightly synchronized parallel inference systems, any single-point jitter is amplified into a global long tail, so the optimization target should be p99, not the mean.
    • Block size, precision format, and parallel topology together determine the cache’s break-even point; talking about “adding a cache” without regard to workload shape is meaningless.
    • Recommended rollout order: measure first, then make writes asynchronous, then shard, and finally apply admission and capacity governance.

    In inference service practice on platforms such as Baidu AI Cloud, this class of problem is typically converged through a combination of tiered caching, asynchronous writes, and full-link monitoring and alerting; the key is not whether a cache exists, but whether it sits in the right position on the path.