LLM Inference Cache Optimization: When Read Overhead Defies Performance Conventional Wisdom

    In distributed system design, "adding a cache layer" is almost a reflexive response to performance bottlenecks. However, in large language model (LLM) inference serving, this conventional wisdom can backfire spectacularly. When a shared cache was introduced in long-context processing to reuse attention intermediate data, median latency stayed flat while p99 latency spiked dramatically. This article dissects the root causes of this counterintuitive phenomenon and outlines how to rebuild the cache system into a genuine accelerator.

    In distributed system design, “adding a cache layer” is almost muscle memory when tackling performance bottlenecks. Whether for web applications or database optimization, placing hot data into a high-speed cache layer reliably delivers significant gains. Yet in large language model (LLM) inference serving, this “common sense” met its Waterloo. When we introduced a shared cache in long-context processing—hoping to reuse attention intermediate data and save compute—not only did overall performance fail to improve, but tail latency soared. This article takes a deep dive into the underlying logic of this counterintuitive phenomenon and explores how to restructure a cache system that was dragging performance down into a true accelerator.

    1. Background: Memory and Communication Challenges of Massive MoE Models

    To understand why the cache failed, we first need to understand the architecture of modern large-scale inference systems. Contemporary massive models typically adopt the Mixture-of-Experts (MoE) architecture. MoE’s core idea is to assign different subnetworks (experts) of the model to different types of tasks, dramatically expanding the parameter count without significantly increasing compute per inference. While this architecture reduces computational complexity per request, it places extreme demands on memory capacity and intra-node communication.

    In long-context scenarios, the compute and storage overhead of attention is especially pronounced. To optimize this, the industry introduced Multi-head Latent Attention (MLA). MLA compresses each token’s key-value information into a shared low-rank latent vector. Under this design, regardless of how many attention heads the model has, the intermediate data stored per token is fixed and tiny. For example, at FP8 precision, every 256 tokens can be packed into a “block,” and a single block holds only about 12.4MB—less than 50KB per token on average. This high compression ratio makes caching attention data for later reuse feasible.

    However, long-context processing depends heavily on multi-GPU coordination. Systems typically use Prefill Context Parallelism (PCP), splitting a long text into multiple shards distributed across the GPUs within a node for simultaneous processing. Once processing completes, all GPUs must synchronize globally over the network so each holds the complete context. In this tightly coupled system, 8 GPUs (8 ranks in academic terms) work like interlocking gears—any stall on one step leaves the remaining GPUs idle and waiting.

    To accelerate long-context inference, the engineering team built a two-level cache system. L1 is a local GPU-memory cache: fast but capacity-limited. L2 lives in a distributed key-value database: large capacity, shared by all inference engines—essentially a global data warehouse.

    The intent was sound: when similar requests arrive, attention data already computed can be fetched directly from L1 or L2, skipping the expensive computation. Actual results were dismaying: with the feature enabled, median latency was essentially unchanged, but the slowest 1% of requests (p99 latency) jumped from roughly 4 seconds to over 17 seconds—a severe tail-latency problem.

    Investigation traced the issue to concurrent reads and writes on L2. It’s like a bubble tea chain where each branch store keeps its own books (L1 cache), but every transaction must be consolidated into a single head-office ledger (L2 cache) handled by one accountant. At peak hours, all 8 branches request postings simultaneously, and everything jams up in front of the accountant.

    In the 8-GPU PCP architecture, processing a long text means all 8 GPUs may issue read/write requests to the L2 cache simultaneously. Traditional distributed key-value databases struggle with such bursty, highly concurrent access, easily hitting lock contention, network I/O saturation, and connection-pool exhaustion. At that point, “reading from cache” is no longer a lightweight pointer dereference—it becomes a heavy operation involving network transfer, serialization/deserialization, and database lock acquisition.

    3. Deep Dive: The Severely Underestimated Hidden Costs of Cache Reads

    The essence of this phenomenon is that engineering practice systematically underestimates “cache read cost.” In traditional web systems, cached objects are typically KB-scale structured data, where millisecond-level network latency is acceptable. In LLM inference, the cached objects are MB-scale tensor data, and latency sensitivity is extreme.

    1. Network and serialization overhead: Extracting a 12.4MB block from the L2 database involves cross-node network transfer. Under high throughput, bandwidth becomes the bottleneck, and serializing data from memory into network packets and deserializing back into GPU tensors imposes heavy CPU overhead.
    2. Thundering herd and synchronous blocking: In PCP mode, 8 GPUs must jointly complete one request. If one GPU misses the cache and must compute, or multiple GPUs contend for L2 resources and stall on retrieval, the entire request is dragged down by the slowest GPU.
    3. Diminishing returns on cache hit rate: Long-context inputs are highly diverse, so the actual hit rate may fall short of expectations. In a miss, the fallback computation plus cache-lookup time can end up slower than pure computation alone.

    4. The Way Forward: Engineering Practices for Rebuilding the Inference Cache

    To make the cache genuinely accelerate inference, the architecture must be rebuilt around two core principles: decoupling from the critical path and eliminating single points of contention.

    1. Asynchronous Writes and Read/Write Separation

    First, L2 cache writes must be removed from the inference critical path. Once a GPU completes attention computation, it should not synchronously wait for the data to be written to L2. Instead, an async task pushes the data to a message queue, where background consumers write to the distributed key-value store at a sustainable pace. The inference engine then only cares about reading from L1 (nanosecond-level latency), while L2 serves purely as an asynchronous cold-data sync layer.

    2. Distributed Sharding with Consistent Hashing

    To address the concurrent read/write bottleneck on L2, replace the centralized single-point architecture with consistent hashing that shards cache data across multiple nodes. Combined with high-performance distributed storage services available in cloud-native environments (such as Baidu AI Cloud), requests from 8 GPUs naturally route to different cache shards, eliminating lock contention and enabling true parallel reads and writes.

    3. Smart Prefetching and Locality-Aware Scheduling

    Introduce intelligent prediction at the scheduling layer. By analyzing request prefix features, the scheduler can route requests with similar prefixes to the same node, maximizing L1 cache hit rates. Meanwhile, before a request officially begins computation, an L2-to-L1 prefetch is triggered asynchronously, using idle network bandwidth windows to hide data-transfer latency.

    4. Adaptive Cache Degradation

    The system needs adaptive capability—continuously monitoring L2 access latency. When network congestion or slowdowns in the cache service are detected, the inference engine should decisively trigger a fallback strategy: skip the cache read and compute locally. This sacrifices some compute, but it stabilizes p99 latency.

    5. Conclusion

    Performance optimization for LLM inference systems is a systems-level endeavor. In this battle of cache “failure” and “rebuild,” one lesson stands out: no single technique is a silver bullet. A cache’s effectiveness depends heavily on the synergy between the underlying hardware architecture, data distribution characteristics, and concurrency model. Only by deeply understanding the communication patterns of the MoE architecture and the data characteristics of MLA—and by precisely quantifying the relative costs of network versus compute—can we design cache systems truly fit for the LLM era. In future cloud-native AI infrastructure, this kind of holistic system insight will be our core weapon for breaking through performance ceilings.