LLM Inference Service Scheduling Optimization and Performance Practices
In large language model (LLM) online inference services, performance bottlenecks often stem from host-side overheads such as request scheduling, batch processing, and state management, rather than just model computation. This article explores two key scheduling optimizations—multi-step scheduling and chunked prefill—designed to reduce per-request scheduling overhead and overlap compute-bound with memory-bound workloads. It covers the background, mechanisms, combined strategies, engineering implementation, and evaluation methods for these techniques.
LLM Inference Service Scheduling Optimization and Performance Practices
In large language model (LLM) online inference services, performance bottlenecks often stem from host-side overheads such as request scheduling, batch organization, state management, and output processing, rather than just the model computation itself. Recently, two notable optimizations have emerged in inference service scheduling: multi-step scheduling and chunked prefill. These approaches improve system efficiency by “reducing per-request scheduling overhead” and “overlapping compute-bound and memory-bound workloads,” respectively. This article will explore the problem background, mechanisms, combined strategies, engineering implementation, and evaluation methods for these techniques.
1. Background: Differences Between Prefill and Decode Stages
LLM inference typically divides request processing into two stages:
- Prefill Stage: Performs forward computation on the input prompt to build the context cache. This stage usually has high compute density with many tokens per batch, making it a compute-bound workload.
- Decode Stage: Autoregressively generates output tokens one by one. Each generated token requires reading model parameters and the context cache. The computation is relatively light but involves frequent memory access, making it a memory-bandwidth-bound workload. Simultaneously, each decode step incurs host-side operations like scheduling, batch assembly, sampling, output processing, and memory management.
In traditional scheduling, requests in the same batch are usually either all in the prefill stage or all in the decode stage. This “stage-aligned” approach is straightforward but introduces two issues. First, the decode stage has fixed CPU overhead per step; as steps increase, host-side overhead becomes difficult to amortize. Second, long-prompt prefills take considerable time, blocking decode requests and causing fluctuations in Time-To-First-Token (TTFT) and tail latency. Multi-step scheduling and chunked prefill address these exact problems.
2. Multi-step Scheduling: Amortizing Scheduling Overhead Across Steps
The core idea of multi-step scheduling is that after the scheduler selects a batch and generates an execution plan, it continuously executes multiple decode steps without re-scheduling at every single step. This amortizes host-side overheads—such as batch assembly, request state checking, sampling parameter preparation, output processing, and memory management—across n decode steps.
The basic structure can be understood via the following pseudo-code:
def serve_loop(running, waiting):while running or waiting:plan = scheduler.build_plan(running, waiting)# The plan can simultaneously include several decode requests and prefill chunksfor step in range(plan.max_decode_steps):inputs = assemble(plan, step)outputs = model_step(inputs)update_states(outputs)if should_reschedule(plan, step):breakscheduler.rebalance()
The benefits of multi-step scheduling include reducing the proportion of per-step CPU overhead, increasing accelerator utilization, and improving overall throughput. These gains are particularly noticeable in scenarios with many decode requests and short per-step computation times. However, it introduces new trade-offs: coarser scheduling granularity means newly arrived requests may wait up to n steps before being included in a batch, and responses to cancellations, timeouts, and priority changes become slower. If n is too large, fairness and tail latency may suffer. Therefore, the value of n should be determined through load testing based on request arrival rates, per-step duration, SLOs, and CPU overhead proportions, with support for dynamic adjustments.
3. Chunked Prefill: Overlapping Compute-bound and Memory-bound Workloads
Chunked prefill splits the prefill process of long prompts into multiple chunks and allows prefill chunks and decode requests to form a batch together during scheduling. The key insight here is that prefill is compute-bound while decode is memory-bound; mixing them helps improve the utilization of both compute units and memory bandwidth, reducing the blocking of decode requests by long prefills.
The schematic process is as follows:
chunks = split_prompt(prompt, max_chunk_tokens)for chunk in chunks:batch = scheduler.mix(prefill_chunk=chunk, decode_requests=ready_decodes)model_step(batch)
Chunked prefill improves latency performance in long-prompt scenarios, particularly by reducing tail latency fluctuations caused by decode requests being blocked by long prefills, resulting in smoother TTFT and inter-token intervals. However, it is not without cost: the total prefill workload for long prompts does not decrease, and chunking introduces additional state management and scheduling complexity. If the chunk size is too small, scheduling frequency increases; if too large, the overlapping effect with decode requests is weakened. In engineering, it is necessary to set reasonable limits for tokens per chunk, total tokens per batch, and decode request protection strategies to prevent prefill chunks from consuming the latency budget of decode requests.
4. Combined Strategies and Scheduler Design
Multi-step scheduling and chunked prefill can be used together, but the combined scheduler requires finer control over the execution plan. Consider the following design dimensions:
- Phase-aware Scheduling: Identify prefill chunks and decode requests, prioritizing the steady progression of decode requests while reserving a controllable quota for prefill chunks.
- In-batch Token Budget: Simultaneously limit the number of prefill tokens and decode requests to prevent excessive batch sizes that could cause memory pressure or long-tail latency.
- Multi-step Limit: Set a maximum number of continuous decode steps for multi-step scheduling, and trigger early rescheduling upon new requests, cancellations, timeouts, or priority changes.
- Fairness and Priority: Use multi-queue or weighted strategies to prevent long requests from monopolizing batches; set stricter latency targets for interactive requests.
- Observable State: Record the phase, chunking progress, executed steps, waiting time, and rescheduling reasons for each request to facilitate troubleshooting.
5. Engineering Implementation Essentials
Implementation requires careful handling of the request state machine and cache management. Requests transition through states: waiting, prefill, decode, and completed. Chunked prefill requires tracking prompt chunking metadata, processed token ranges, and context cache allocation. Multi-step scheduling requires maintaining consistency of sampling states, output buffers, and cancellation flags within the execution plan. Exception paths are equally important: request cancellations, timeouts, client disconnections, out-of-memory events, and individual request failures within a batch must be handled without corrupting the states of other requests.
Furthermore, it is recommended to implement these two optimizations as configurable switches, supporting gradual rollout by model, business queue, or traffic proportion. Before going live, conduct mixed load tests covering short-prompt/short-output, long-prompt/short-output, short-prompt/long-output, and long-prompt/long-output combinations. Monitor metrics such as throughput, TTFT, inter-token latency, P99 latency, queue waiting time, batch size utilization, chunk utilization, per-step host overhead, and accelerator utilization.
6. Evaluation and Deployment Recommendations
When deploying, avoid enabling all optimizations at once. A more prudent path is: first establish a baseline to confirm the actual bottlenecks between CPU overhead and accelerator utilization; then incrementally enable multi-step scheduling to observe throughput improvements and tail latency changes; subsequently, introduce chunked prefill, focusing on whether the interference of long prompts with decode requests has decreased. Each step should retain rollback capabilities, and stability should be verified through gradual rollout. The ultimate goal is not to optimize a single metric, but to achieve a balance across throughput, latency, fairness, and implementation complexity that meets business SLOs.
