# Playing Around with vLLM Scheduling Algorithms

By Ishaan Shah · Oct 19, 2026 · 9 min read

I changed how vLLM scheduled requests on two A100s. P99 first-token wait fell from 41 seconds to 6 seconds. Later tokens came more slowly. The queue and KV cache logs helped explain why.

> Previous post: [Testing How LLM Inference Scales Across GPUs](https://ishaan812.com/blog/what-a-4-gpu-llm-benchmark-taught-me-about-inference)
>
> My four-GPU test showed how first-token wait and output speed can change on their own.

In my last benchmark, I measured the wait for the first token and the speed of later tokens. Then I ran CodeLlama-34B on two A100s. Some requests waited more than **40 seconds** for a first token. The server continued to generate tokens for other requests. I wanted to find the cause of that wait.

I kept the model, GPUs, and request load the same. I changed how vLLM selected work. P99 time to first token fell from **41.3 seconds** to **6.35 seconds**. P99 time per output token rose from **64 to 263 milliseconds**. I used the queue and KV cache logs to explain both changes.

## How vLLM scheduled the requests

I used vLLM V0 and disabled chunked prefill. The server made a new batch at each scheduling step. It admitted waiting prompts in FCFS order when the limits allowed. Those limits covered tokens, sequences, and GPU KV cache space. A prefill step delayed active decodes.

Other steps moved running requests forward or resumed swapped requests. vLLM could move a decode’s KV data to CPU memory when GPU KV space was low. When the cache filled, new prompts waited. Admitted requests kept streaming.

## What I tried: CFS-inspired scheduling

I wanted a new prompt to start while older requests were still generating output. Linux’s Completely Fair Scheduler (CFS) tracks how much CPU time each task receives. I used its idea of tracking service. For this test, service meant generated output tokens. vLLM already counted them.

The scheduler ranked requests with fewer output tokens first. Arrival time broke ties. A new request started with zero output tokens. I ran this rule every Nth scheduling step. The regular FCFS steps let active requests continue.

![FCFS: new prompt B remains waiting while A continues decoding with GPU KV space full.](https://ishaan812.com/images/blog/scheduling-fcfs-flow.svg)

![CFS-inspired step: A swaps its KV blocks to CPU and new prompt B runs prefill on the GPU.](https://ishaan812.com/images/blog/scheduling-cfs-flow.svg)

When the GPU KV cache is full, FCFS keeps B waiting. On a selected fairness step, the CFS-inspired policy swaps A and admits B.

1. On a fairness step, rank waiting, swapped, and running requests by generated output tokens.
2. If a waiting prompt needs KV space, move lower-ranked running decodes to CPU memory until it fits.
3. Admit the prompt or resume swapped work when space is free. Use FCFS on the other steps.

Swapping pauses a request while another runs. vLLM moves its KV blocks to CPU memory. Later, vLLM moves them back to the GPU and continues generation.

## How priority could work in a service

A shared assistant might serve chat messages, editor completions, and background summaries. A front end can give each request a class or priority. It then sends the request to a model server. The server batches prefill and decode work within its token, sequence, and KV cache limits.

vLLM supports FCFS and a priority policy. The priority policy uses a supplied value, then arrival time to break ties. My experiment used generated token counts for scheduling. It had no user or workload priorities.

Source: [vLLM scheduling policy documentation](https://docs.vllm.ai/en/v0.10.1.1/configuration/engine_args.html#scheduling-policy)

FCFS gives a clear arrival order. In this run, it kept active responses streaming at a steady rate. A new chat waited when the GPU KV cache was full. My CFS-inspired step started new prompts sooner. Its swaps delayed later tokens in active streams and used CPU memory.

A live service could give chat requests priority over batch jobs. It would also need limits on swaps and space for active decodes. A batch service could favor throughput. I would test each policy with real traffic and latency targets.

![Illustrative timeline: with FCFS, A decodes while B waits for KV space; at a CFS-inspired fairness step, A pauses while B prefills and gets its first token sooner, then A resumes.](https://ishaan812.com/images/blog/scheduling-timeline.svg)

This diagram shows the order of work for two requests. The results below show the measured times.

## Experiment at a glance

- **Model and GPUs:** CodeLlama-34B architecture. Two NVIDIA A100-SXM4-40GB GPUs with tensor parallel size 2.
- **Load:** **50 synthetic requests**. Average arrival rate: **3 requests/s**.
- **Server:** vLLM V0. Chunked prefill off. Eager execution and swap preemption. **16 GiB** of CPU swap space per GPU.
- **Fixed cache limit:** **1,024 GPU KV blocks** with **16 tokens each**. Set with --num-gpu-blocks-override.
- **What changed:** CFS-inspired scheduling every 5, 10, 20, or 40 steps. FCFS used interval 0.
- **Important limit:** I loaded dummy weights. The test measures serving and scheduling behavior. It does not measure answer quality. I ran each interval once.

## Results from one run
| Configuration | P99 TTFT | P99 TPOT | Output tok/s |
| --- | --- | --- | --- |
| FCFS · 0 | 41.287 s | 64.35 ms | 193.63 |
| CFS · 5 | 3.266 s | 380.57 ms | 127.80 |
| CFS · 10 | 6.349 s | 262.57 ms | 157.99 |
| CFS · 20 | 13.238 s | 221.43 ms | 183.92 |
| CFS · 40 | 28.138 s | 153.62 ms | 199.57 |
Each run completed 50 requests. P99 values came from client summaries. Output throughput includes all generated tokens during the run. Each interval had one run.

![Per-request time to first token rises above 40 seconds with FCFS but stays below about 7 seconds at CFS interval 10](https://ishaan812.com/images/blog/scheduling-ttft.png)

The TTFT plot drew my attention first. Early requests started at a similar pace under both policies. Later requests waited much longer with FCFS. The interval-10 curve stayed nearly flat.

The x-axis shows the **48 requests** for which the client printed both TTFT and TPOT. It lists them in issue order. All **50 requests** finished. Two produced only one token, so the client could not calculate a later-token interval.

## The KV cache explained the wait

In my last post, I called the KV cache a request’s working memory. It stores attention keys and values. This lets the model continue without reading the full prompt again. KV use grows with request length.

I set the GPU limit to **1,024 blocks**. Each block held **16 tokens**. This gave active requests **16,384 token slots** in total. A new request needed free KV space before it could start.

- **One token, one GPU:** `2 × 48 layers × (8 / 2) KV heads × 128 × 2 bytes = 96 KiB`
- **GPU cache cap:** `1,024 blocks × 16 tokens × 96 KiB ≈ 1.5 GiB per GPU`

CodeLlama-34B has **48 layers** and eight KV heads. Tensor parallelism split the heads across two GPUs. One token used about **96 KiB** of KV space per GPU. The block limit gave each GPU about **1.5 GiB** of KV space.

In one FCFS log sample, the server used **99.4%** of that space. It had eight running requests and **11 waiting**. Each A100 had **40 GB** of memory. The configured cache limit controlled admission in this test.

![GPU KV cache usage approaches its configured limit during both FCFS and interval-10 runs](https://ishaan812.com/images/blog/scheduling-gpu-kv.png)

That log explained the long wait for a first token. The server generated tokens for active requests. A new prompt needed KV space before it could run. Under FCFS, it waited until space became free. The queue grew during the burst.

![The pending queue reaches 31 requests under FCFS and clears much earlier under interval-10 scheduling](https://ishaan812.com/images/blog/scheduling-waiting.png)

The queue plot shows how the waiting line changed. I measured the time between the first log sample with waiting requests and the next sample with none. FCFS took **60.56 seconds**. Interval 10 took **15.43 seconds**.

A zero queue means each request entered the active set at least once. Some requests were still running or swapped to CPU. These times measure admission only.

![CPU KV cache remains near zero under FCFS but rises to 31.1 percent during the interval-10 run](https://ishaan812.com/images/blog/scheduling-cpu-kv.png)

I then checked where the paused requests went. At one interval-10 sample, the server used **31.1%** of **10,922 CPU blocks**. That equals about **4.98 GiB** of KV data per GPU. Another sample showed a peak of **33 swapped requests**. The FCFS run used no measurable CPU KV cache in this sweep. The shorter queue came with this memory movement.

## Then I looked at the stream

I expected TPOT to rise. Each fairness step could pause an active decode and move its KV blocks between GPU and CPU memory. Those extra transfers seemed likely to delay the next token. Prefill work for a new prompt could add another delay.

The result matched the expected direction. At interval 10, P99 TPOT reached **262.57 ms**. FCFS measured **64.35 ms**. That is about **4.1 times** higher. Output throughput fell from **193.63** to **157.99 tokens/s**.

![Per-request time per output token is usually higher under CFS interval 10 than under FCFS](https://ishaan812.com/images/blog/scheduling-tpot.png)

The logs showed more swapped KV data and slower token delivery. They did not measure GPU idle time or the cost of each swap. KV transfers and delayed decode work likely contributed to the higher TPOT. I cannot assign a share of the increase to either cause from these logs. A profiler could measure each cost.

## How often should I make room?

I tested fairness intervals of 5, 10, 20, and 40 steps. At interval 5, P99 TTFT was lowest: **3.27 seconds**. P99 TPOT was highest: **380.57 ms**. At interval 40, P99 TPOT fell to **153.62 ms**. P99 TTFT rose to **28.14 seconds**.

If I needed TTFT below eight seconds, I would test interval 10 again. It gave **6.35 seconds** TTFT and a smoother stream than interval 5.

![Five-point scatter plot of P99 TTFT versus P99 TPOT showing the scheduling tradeoff across FCFS and four CFS intervals](https://ishaan812.com/images/blog/scheduling-tradeoff.png)

The tradeoff plot helped me compare settings. Moving from interval 5 to 10 added **3.08 seconds** to P99 TTFT. It saved **118 ms** of P99 TPOT. Moving from 20 to 40 added **14.90 seconds** to P99 TTFT. It saved only **67.81 ms** of P99 TPOT.

Throughput followed a different pattern from per-request TPOT. Each point came from one run with synthetic requests. I would repeat the test before choosing a setting.

## Where this might be useful

A shared chat endpoint or coding assistant could use a bounded fairness step. New questions often arrive while other users receive long answers. A shorter first-token wait could make the service feel faster during a burst. I would test that with realistic traffic and users.

This score applies to each request. It counts generated output tokens. It ignores prompt cost and user identity. A long new prompt starts at zero. Frequent new requests could keep interrupting long responses.

A service would need a swap limit, a CPU memory budget, and real traffic tests. For a background batch job, interval 10’s slower streams and lower throughput could be costly.

## What I learned

- TTFT includes the wait before admission. The server can generate tokens while a new request waits.
- KV space limits how many requests can run. A **1.5 GiB cap** caused a long queue on **40 GB** GPUs.
- Earlier first tokens came with slower later tokens in this test. I needed TTFT and TPOT to see both effects.
- The queue and CPU KV logs helped explain the client latency results.

The scheduler changed when users saw output, even with the same model and GPUs. In this test, the server kept generating tokens while new requests waited. Giving new requests an earlier turn reduced that wait. It also delayed tokens for requests already streaming.

Before I chose a production setting, I would repeat the sweep and change the cache limit and request mix. I would also profile the swaps. This test used dummy-loaded weights and one run per interval. Its results describe serving behavior for this workload.

## Sitemap

- [Markdown sitemap](https://ishaan812.com/sitemap.md)
- [Agent index](https://ishaan812.com/llms.txt)
