Cache Reads Can Also Slow Down Tail Latency: The Hidden Cost in LLM Inference

    Caching Key-Value (KV) data is a common optimization for accelerating Large Language Model (LLM) inference, but cache reads themselves introduce hidden overhead. This article analyzes a real-world tail latency rollback case involving shared KV caching in a Mixture of Experts (MoE) model. It explores the memory structure of inference systems, breaks down the four main stages of cache reading (index lookup, data transfer, format conversion, and device copy), and provides a systematic framework for locating tail latency and quantifying the true break-even point of caching benefits.

    I. A Tail Latency Rollback Case Study

    A team enabled shared caching on an inference service for a large-scale Mixture of Experts (MoE) model. The model was deployed on a node equipped with eight next-generation data center GPUs. The cache stored previously computed attention data (KV), expecting to reuse it directly when similar requests arrived and save recomputation time.

    After launch, the median latency remained largely unchanged, but the slowest 1% of requests (p99) significantly degraded. The tail latency began impacting Service Level Objectives (SLOs), prompting the team to roll back the feature entirely.

    This case illustrates that a cache hit only saves computation; reading the cache itself still takes time, and this cost is often underestimated. The net benefit of caching can be written as:

    Net Benefit = Hit Rate × Recomputation Time Saved per Hit − Query Time per Request − Read Time per Hit

    Many teams only account for the first two terms and ignore the latter two. The median is insensitive to fluctuations in read latency, but p99 gets amplified by slow links along the read path. Therefore, evaluating cache effectiveness requires examining both average benefits and tail performance.

    II. Memory Structure of Inference Systems

    2.1 Mixture of Experts Models and Inference Workloads

    Mixture of Experts (MoE) models split the network into multiple expert subnetworks, activating only a small subset of experts for each input token. This allows parameter scaling with limited growth in computational volume. The tradeoff is higher VRAM usage on the node and more complex communication and scheduling across multiple cards.

    2.2 Multi-head Latent Attention and KV Data

    During inference, the model saves Key-Value (KV) vectors for each processed token, which subsequent generation depends on. Multi-head Latent Attention (MLA) uses low-rank compression to merge the KV information of all attention heads into a shared, low-dimensional latent vector. As a result, the amount of data that needs to be stored per token is much smaller than in standard Multi-Head Attention and is largely independent of the number of attention heads.

    This optimization only applies to models using the MLA architecture. For models using Grouped-Query Attention (GQA) or standard Multi-Head Attention, the KV size per token must be recalculated based on their respective structures.

    In the case study, the cache used FP8 precision, grouping every 256 tokens into a block. Each block was approximately 12.4MB, translating to about 48.4KB per token. The two figures align: 256 multiplied by 48.4KB equals roughly 12.4MB. However, these numbers depend on the specific model configuration. The original text did not list the number of layers, latent dimensions, or whether metadata was included, so readers should recalculate using the following formulas:

    Bytes per Token = Number of Layers × Cache Dimension per Layer × Bytes per Element + Alignment and Metadata Overhead

    Bytes per Block = Bytes per Token × Block Size

    For FP8, each element is 1 byte. If the implementation stores additional position-encoding-related components or aligns data to a specific byte boundary, the actual value will be higher than the pure formula result. If recalculation results do not match measured block sizes, check these two factors first.

    The management unit for the cache is a block. A hit transfers the entire block of data; even if only a small segment of the block is needed, the transfer and copy costs of the entire block must be borne.

    2.3 The Position of the Cache in the Inference Pipeline

    The cache sits between the storage layer and the computation layer. When the computation side requires a segment of KV data, it queries the index first. If there is a hit, the data is moved from the storage layer to VRAM; if there is a miss, the GPU recomputes it. Therefore, every request incurs at least one query cost, and a hit incurs an additional transfer cost.

    III. Components of the Cache Reading Cost

    The read path typically involves four stages:

    1. Index Lookup: Determines whether the prefix or block exists, involving hash calculations and metadata access, potentially across processes or nodes.
    2. Data Transfer: Reads block data from remote memory, local disk, or shared storage, impacted by bandwidth and network congestion.
    3. Format Conversion: When the data layout does not match the requirements of the compute kernel, rearrangement or dequantization is required. This step consumes CPU or GPU time.
    4. Device Copy: Copies data from host memory to GPU VRAM. If pinned memory is not used, or if the copy does not overlap with computation, the copy will block subsequent calculations.

    Observation metrics and optimization directions for each stage are as follows:

    Stage Observation Metrics Common Bottlenecks Optimization Directions
    Index Lookup Query latency p99, metadata service request volume Cross-node round trips, hash table contention Local index replicas, batch queries, cached metadata
    Data Transfer Transfer time per block, network bandwidth utilization, retransmission rate Bandwidth saturation, queuing due to congestion Limit concurrent loads, priority scheduling, store hot data locally
    Format Conversion Conversion time ratio, number of rearrangements before kernel Storage layout mismatch with kernel Use kernel-friendly layout directly during storage
    Device Copy Host-to-device copy time, overlap ratio between copy and computation Non-pinned memory, synchronous copy Pinned memory, asynchronous copy, overlap with compute pipeline

    IV. How to Locate Tail Latency

    When locating issues, you can proceed with the following steps:

    1. Group by Hit Status: Divide requests into hit and miss groups, and calculate p50, p95, and p99 for each separately. If the p99 of the hit group is higher than that of the miss group, it indicates that the read path is a primary source of tail latency.
    2. Segmented Timing: Record the time spent on index lookup, transfer, conversion, copy, computation, and queuing for each request. Tail requests typically show significant elongation in only one or two stages, allowing for quick localization.
    3. Align Timelines: Align the occurrence time of p99 requests with network traffic, GPU scheduling, and CPU load. If tail requests cluster during traffic peaks, the problem is likely network or queuing related.
    4. Bucket by Request Characteristics: Group by prefix length and block count. The more blocks hit, the longer the read time. Requests with long prefixes are often the main source of tail latency.
    5. Set Up a Control Group: Run the same workload with caching disabled. This confirms that tail changes are indeed caused by caching rather than other version modifications.

    V. A Framework for Quantifying Cache Benefits

    Let $C$ be the recomputation time for a single request, $R$ be the time to read a hit block, $L$ be the time to query the index, and $h$ be the hit rate. With caching enabled, the expected latency of a request is:

    $L + h \times R + (1 - h) \times C$

    Without caching, the expected latency is $C$. Therefore, the condition for caching to be beneficial for average latency is:

    $L + h \times R < h \times C$

    This condition can only be satisfied if $C$ is greater than $R$. In this case, the break-even hit rate is:

    $h^* = \frac{L}{C - R}$

    Assume that recomputing a block takes 40 milliseconds, reading takes 10 milliseconds, and querying takes 2 milliseconds. The break-even hit rate is $2 \div 30$, or approximately 6.67%.