TL;DR
This paper tackles the challenge of scheduling Large Language Model (LLM) requests when both input prompts and output responses vary drastically in length. The authors prove that this realistic setting makes the scheduling problem NP-hard and causes standard scheduling policies to fail catastrophically. To fix this, they introduce Sorted-F, a novel batching algorithm with a provable constant-factor performance guarantee that slashes end-to-end latency by balancing batch size against downstream memory costs.
What Problem Does This Paper Address?
In LLM serving, requests are processed in two distinct phases: Prefill (processing the input prompt) and Decode (generating the response token-by-token). During decoding, the system stores Key-Value (KV) caches for all tokens, meaning memory consumption grows linearly with every generated token. Modern serving systems use continuous batching and prefill/decode mixing to process multiple requests simultaneously to maximize hardware utilization.
Prior theoretical work assumed that all incoming prompts were of uniform length. However, real-world workloads are highly heterogeneous, mixing short chat queries with massive document summarization tasks. A request with a huge prompt but a tiny response hogs memory upfront but finishes quickly, whereas a small prompt with a long response occupies memory for an extended period. This paper addresses how to optimally schedule these mixed workloads under a fixed KV-cache memory budget to minimize total end-to-end latency.
Methods
The authors prove that variable prompt lengths make the scheduling problem NP-hard and show that standard policies like First-Come-First-Served (FCFS) or Shortest-Output-First can suffer from unbounded approximation ratios.
To solve this, they propose Sorted-F, which schedules requests using a novel batch-level quality metric called the F-metric:
$$F(\mathcal{X}) = \frac{\sum_{r_i \in \mathcal{X}} o_i}{|\mathcal{X}|^2}$$
where $\mathcal{X}$ is a candidate batch and $o_i$ is the output length of request $i$. Maximizing the reciprocal of this metric ($1/F(\mathcal{X})$) maximizes "throughput density"—the number of requests completed per unit of average decode time.
The algorithm operates in two phases:
- Batch Construction: Iteratively selects feasible batches that minimize the F-metric, sorting requests within each batch by their output lengths.
- Scheduling Execution: Dynamically admits requests into the processing pipeline based on the ordered list while continuously verifying memory capacity.
Because finding the absolute optimal batch is combinatorially difficult, the authors provide three practical subproblem solvers tailored to different deployment scales:
- Exact Dynamic Programming: $O(n^2M)$ complexity, optimal for small scales ($n \le 100$).
- Local Swap Search: An $O(n^2)$ heuristic that refines batches via pairwise request exchanges, ideal for moderate scales ($n \le 500$).
- Quantile Greedy Selection: An $O(n)$ lightweight heuristic using statistical sampling for massive scales ($n \ge 1000$).
They also introduce Sorted-F+$A_{min}$, an adaptive variant that gracefully handles prediction uncertainty in output lengths by starting with optimistic lower-bound estimates and evicting requests if memory overflows.
Datasets
To evaluate their approach on realistic, heterogeneous workloads, the authors combined two public datasets:
- LMSYS-Chat-1M: Short, interactive conversational data (mean input: 41.84 tokens, mean output: 85.35 tokens).
- Arxiv Long-Document Summarization: Long academic paper tasks (mean input: 2546.39 tokens, mean output: 296.08 tokens).
They sampled and mixed these datasets (typically in an 80% short / 20% long ratio) to create a benchmark of 2,000 requests exhibiting high dispersion in prompt and response sizes.
Key Insights and Ideas
- The Flaw of Myopic Rules: Standard heuristics fail because they ignore the global interaction between immediate memory consumption (prefill) and long-term memory growth (decode).
- Throughput Density is Key: Prioritizing batches based on the F-metric acts as a batch-level analogue to the classical shortest-processing-time rule in scheduling theory, naturally preventing long-decode "stragglers" from blocking the pipeline.
- Decode-Centric Dominance: The authors found that explicitly factoring in parallel prefill compute costs into the scheduling metric yields almost no benefit. Because prefill compute happens efficiently in parallel, sequential decode memory occupancy is the true bottleneck that schedulers must optimize.
Key Results
In experiments simulating a LLaMA2-70B deployment on two A100 GPUs ($n = 2000$ requests, 80/20 mixed workload):
- Latency Reduction: Sorted-F with Local Swap Search achieved the lowest average end-to-end latency at 154.1 seconds, vastly outperforming FCFS (750.0s) and Shortest-Output-First (321.5s).
- Near-Optimal Performance: On smaller tractable workloads, Sorted-F stayed within 1.03x to 1.09x of the theoretical Linear Programming (LP) relaxation lower bound.
- Tail Latency Improvements: Sorted-F significantly reduced p95 tail latency to 953.2 seconds compared to 1413.9 seconds for FCFS.
- Low Overhead: The Local Swap Search heuristic took only 0.073 seconds to compute the scheduling order for 2,000 requests, making it highly practical for real-time deployment.
Limitations and Future Work
The primary limitation is that Sorted-F's constant-factor approximation guarantee ($< 48$) is proven strictly for the offline setting where all requests are backlogged at time $t=0$. While the authors designed a receding-horizon online variant (Sorted-F-Online) that performs exceptionally well under simulated Poisson arrivals, a formal online competitive-ratio analysis remains an open theoretical challenge. Additionally, the theoretical bounds assume the Phase 1 batch problem is solved exactly via Dynamic Programming, which is too slow for very large-scale real-time systems.
Summary updated