页面简介
In large-scale LLM serving, routing directly impacts TTFT, TPOT, and throughput. We show how Ray Serve LLM goes beyond KV cache reuse with token-load-aware routing to efficiently balance requests across LLM replicas.
正文摘录
HomeBlogBlog DetailOptimizing LLM Serving Efficiency: Moving Beyond KV Cache Reuse to Token-Load Awareness with Ray Serve LLMBy Jeffrey Wang, Seiji Eicher, Kourosh Hakhamaneshi and Rudy Pei (NVIDIA) | August 25, 2026In large-scale LLM serving, the orchestration layer is critical to the overall system efficiency. How effectively the orchestration layer distributes heterogeneous request streams across a fleet of LLM engine replicas directly impacts serving TTFT, TPOT, and throughput. When operating a cluster of vLLM replicas, the most critical decision your router makes is simple: Who gets the next request? In this blog, we’ll unpack the misconception of optimizing solely for KV cache reuse, introduce token-load-aware routing, and explain why it is critical for efficient LLM serving.LinkChallenges of LLM Request RoutingLLM serving differs fundamentally from traditional microservice routing due to the autoregressive nature of inference and the high variability of LLM requests. Traditional microservices typically process requests independently, with little benefit from routing related requests to the same replica. LLM serving, in contrast, introduces statefulness, high heterogeneity, and unpredictable execution costs.Stateful execution: An engine can reuse KV caches computed by previous requests. Routing a request to a replica that already holds its prefix can significantly reduce prefill computation and TTFT.High heterogeneity: Requests vary widely in input and output sequence lengths, leading to large differences in GPU resource usage and execution time.Non-deterministic generation: Even for the same input, the number of generated output tokens can vary, making the total cost of a request difficult to predict in advance.Together, these properties create a unique challenge for the orchestration layer: how to take advantage of KV cache reuse while balancing heterogeneity across engine replicas.LinkNaive Optimization: Maximize KV Cache ReuseMaximizing KV cache reuse is the most naive approach to reduce TTFT and optimize serving efficiency. There are three common ways to maximize KV cache reuse: session affinity, prefix affinity, and KV cache affinity.LinkSession AffinityRay Serve LLM supports session affinity through consistent hashing, which requires clients to associate requests from the same session with a session ID. For multi-turn workloads, this routes subsequent turns to the same replica, allowing them to reuse KV caches computed by earlier turns.An added benefit of consistent hashing for session affinity is session-level load balancing: with enough virtual nodes, it distributes sessions evenly across replicas.Figure 1: Consistent hashing with virtual nodes offers session-level load balancing.Consistent hashing with virtual nodes offers session-level load balancingsession_affinity_config = LLMConfig( model_loading_config=..., deployment_config=( "request_router_config": RequestRouterConfig( request_router_class=( "ray.serve.experimental.", "consistent_hash_router.ConsistentHashRouter" ) ), engine_kwargs={...}, )LinkPrefix AffinityBased on incoming requests, Ray Serve LLM’s prefix affinity router builds a prefix tree that tracks which prefixes have been sent to each replica. Later requests walk the tree to find the replica with the largest prefix overlap.Approximate: The prefix tree tracks request strings, not the actual KV cache. KV caching operates at the token level, so the router’s view may differ from the engine’s actual cache state.Not eviction-aware: The router assumes previously seen prefixes remain cached. Under high concurrency or long running services, eviction can make this view stale. KV cache offloading reduces cache misses, but the router still treats all cache tiers equally, ignoring the cost of reloading offloaded blocks back to GPU memory.prefix_affinity_config = LLMConfig( model_loading_config=..., deployment_config=( "request_router_config": RequestRouterConfig( request_router_class=( "ray.serve.llm.", "request_router.PrefixCacheAffinityRouter", ), engine_kwargs={...}, )LinkKV Cache AffinityRay Serve LLM’s KV aware router ingests KV cache events from the engines to build a global radix tree of KV cache blocks. vLLM emits events as cache blocks are created and removed, giving the router an up-to-date view of KV cache state across replicas and allowing it to compute overlap at the KV cache block level for each request.We collaborate with the NVIDIA Dynamo team to expose Dynamo’s KV indexer through modular interfaces to external libraries. The event, request, and data planes remain Ray-native, while Dynamo’s KV indexer computes KV cache overlap and contributes to request scoring. The resulting scores are then used by Ray Serve’s request plane to select the target replica.Figure 2: KV event transmission and global KV radix tree construction. vLLM engines emit KV events when KV cache blocks are created or removed. Ray Serve LLM forwards these events to the KVAwareRouter, where NVIDIA Dynamo’s KV indexer builds a global KV radix tree and scores requests based on KV cache overlap. KV event transmission and global KV radix tree construction. kv_affinity_config = LLMConfig( model_loading_config=..., deployment_config=( "request_router_config": RequestRouterConfig( request_router_class=( "ray.serve.llm.", "request_router.KVAwareRouter", ), engine_kwargs={...}, )Beyond KV cache overlap, Ray Serve LLM’s KV cache affinity router also accounts for token load when making routing decisions, which we’ll explore in the following sections.LinkWhy Isn’t Maximizing KV Cache Reuse Alone Enough?Optimizing KV cache reuse does not necessarily maximize serving performance. Consider an asynchronous multi-turn RL rollout workload with stragglers, where requests vary significantly in input and output sequence lengths.Each step runs eight rollouts, with 10 turns per rollout.Each rollout starts with a 2K-token input, and each turn generates 1K tokens, except for two stragglers whose final turn generates 8K tokens.Figure 3: Asynchronous RL multi-turn rollouts visualization.Figure 3: Asynchronous RL multi-turn rollouts visualization.For asynchronous RL rollouts, the goal is typically to minimize step time or maximize throughput at a fixed concurrency. We use p99 end-to-end rollout latency as a proxy for step time. We compare three router variants under concurrency=16 as shown in Figure 4:PureKVCacheAffinityRouter, which modifies KVAwareRouter to optimize solely for KV cache overlap.ConsistentHashRouter, which also maximizes KV cache reuse for multi-turn conversations while providing session-level load balancing. We assign each multi-turn rollout a session ID.KVAwareRouter, which considers both KV cache overlap and token load.Figure 4: Router comparison under asynchronous multi-turn RL rollouts. KVAwareRouter trades some KV cache hit rate for more balanced token load, resulting in lower p99 end-to-end rollout latency. Asynchronous multi-turn RL rolloutsKVAwareRouter has the best p99 rollout end-to-end latency despite lower prefix cache hit rate. Taking a deeper look into the KV cache hit rate and token load* which estimates the active KV cache footprint of decoding requests on a replica, KVAwareRouter trades off KV cache hit rate for more balanced token load.LinkRequest HerdingPure KV cache affinity supported by PureKVCacheAffinityRouter can cause request herding. Once a replica caches a shared prefix, such as the system prompt, subsequent requests see cache overlap and preferentially route to that replica. Requests from many different conversations collide on the same replica and create token load imbalance.LinkLoad BalancingIn consistent hashing, with enough virtual nodes, it balances the number of sessions across replicas, but it perceives those sessions uniformly. In LLM serving, they are not: one session may contain short requests, while another may become a long-running straggler. Multiple stragglers can land on the same replica, creating load imbalance despite an even request distribution.While session affinity does an excellent job of preserving KV cache locality, request-level balance does not guarantee actual load balance.LinkBeyond KV Cache Reuse: Token Load Awareness Matters MoreLet’s consider the work an engine actually performs for each request. A request goes through two phases:Prefill: The engine first reuses any overlapping KV cache, then computes the KV cache for the remaining uncached input tokens.Decode: Once prefill completes, the request starts generating output tokens. At every decode step, the engine accesses the KV cache for all tokens generated so far and performs another forward pass.This reveals the limitation of using KV cache overlap as the routing objective. KV cache overlap tells us how much prefill work can be saved, but not how much work the engine still has to do. That remaining load comes from two sources:Prefill load: active prefill tokens plus incoming tokens that are not already cached.Decode load: ongoing decode work from active requests.Token load combines both into a single metric, capturing the compute-bound prefill load and memory-bound decode load on each replica.KV cache affinity is still important, but its role changes: it is a proxy for load estimation, not the routing objective itself. KV cache overlap tells us how much of the incoming prefill can be skipped. We use that to estimate the remaining prefill load, then combine it with ongoing decode load to estimate the overall token load.KVAwareRouter is the routing policy with token-load awareness in Ray Serve LLM. It also provides some additional benefits over session affinity with consistent hashing:Automatic KV cache reuse: Session affinity through consistent hashing requires clients to provide session IDs, so applications need to explicitly define which requests belong to the same session. KVAwareRouter instead discovers and reuses available KV cache automatically, without requiring session IDs.Flexibility: Based on your