Skip to content

Inside the LLM Scheduler: How Modern Inference Engines Balance Tokens, KV Cache, Latency, and GPU Utilization

A large language model can have plenty of GPU capacity available and still feel slow. A production LLM server isn’t just calling generate() — it is continuously deciding which requests should run, how many tokens each should consume, whether KV-cache memory exists, and whether new work can be admitted without destroying latency. Modern inference engines like vLLM and TensorRT-LLM are schedulers and memory managers as much as model runtimes.

Published
Reading time
11 min
Topics
llm, inference, scheduler, kv-cache
Cover illustration for "Inside the LLM Scheduler: How Modern Inference Engines Balance Tokens, KV Cache, Latency, and GPU Utilization"

A large language model can have plenty of GPU capacity available and still feel slow.

That sounds contradictory until you look at what the inference engine is actually scheduling.

A production LLM server isn’t simply taking requests, putting them into a batch, and calling generate(). It is continuously deciding which requests should run, how many tokens each request should consume, whether enough KV-cache memory exists, and whether new work should be admitted without destroying the latency of requests that are already generating.

This is why modern inference systems such as vLLM and TensorRT-LLM increasingly look like schedulers and memory managers as much as model runtimes. Current vLLM exposes explicit controls for token budgets, sequence limits, chunked prefill, scheduling policy, KV-cache reservation, watermarks, and asynchronous scheduling. TensorRT-LLM similarly implements in-flight batching that mixes context and generation work at iteration boundaries.

The interesting engineering problem is not “how do I run an LLM?”

It’s:

How do I keep expensive GPUs busy without allowing one workload to destroy everyone else’s latency?

The request is not the unit of work

Traditional API infrastructure often thinks in requests:

request A
request B
request C

LLM inference needs a different mental model.

Consider:

A → 100 input tokens, 20 output tokens
B → 8,000 input tokens, 100 output tokens
C → 500 input tokens, 2,000 output tokens

Those three requests have radically different resource requirements.

A scheduler that treats every request as one unit of work has already thrown away useful information.

Modern inference engines therefore reason about tokens per iteration as well as the number of active sequences. vLLM, for example, exposes both max_num_batched_tokens and max_num_seqs; the former limits tokens processed in one iteration, while the latter limits sequences.

Conceptually:

[ \sum_i tokens_i \leq T_{max} ]and:[ N_{sequences} \leq S_{max} ]

The scheduler is effectively solving a constrained packing problem every GPU iteration.

Prefill and decode are different workloads

The distinction between prefill and decode is central.

During prefill, the model processes the user’s existing context. A 10,000-token prompt can be processed with substantial parallelism.

During decode, the model repeatedly generates the next token:

token 1
→ token 2
→ token 3
→ token 4
→ ...

The workloads have different characteristics.

Prefill is generally more compute-heavy. Decode repeatedly operates against the model weights and KV cache and is much more sensitive to memory behavior and inter-token latency.

That creates a scheduling conflict.

A large prefill can consume substantial GPU compute while an already-running conversational request is waiting for its next token.

TensorRT-LLM explicitly addresses this with in-flight batching, allowing sequences in the context phase to execute alongside sequences in the generation phase.

Why continuous batching matters

Static batching looks like this:

Batch
├── Request A
├── Request B
├── Request C
└── Request D

The problem is that requests finish at different times.

If A finishes early, its slot is effectively wasted until the batch is rebuilt.

Continuous batching changes the model:

Iteration 1:
A B C D
Iteration 2:
A B C E
Iteration 3:
A C E F

Completed requests leave. New requests enter.

The batch becomes a continuously changing set of work rather than a fixed group.

This improves utilization, but it also means the scheduler is now making decisions every iteration.

That scheduler becomes part of the critical path.

Chunked prefill: preventing one prompt from taking over

Consider a 20,000-token prompt and a scheduler with a 4,096-token budget.

Without chunking, the scheduler has an awkward choice:

  • process the entire prompt and potentially stall other work
  • or wait until enough capacity exists

Chunked prefill changes the problem.

Instead:

Iteration 1 → 4,096 tokens
Iteration 2 → 4,096 tokens
Iteration 3 → 4,096 tokens
Iteration 4 → 4,096 tokens
Iteration 5 → remaining tokens

The important part is what happens between those chunks.

The scheduler can combine prefill work with decode work:

Decode A → 1 token
Decode B → 1 token
Decode C → 1 token
Prefill  → 1,000 tokens

This is exactly the direction current vLLM and TensorRT-LLM documentation describes. vLLM’s current scheduling policy prioritizes pending decode work and uses remaining token budget for prefills; TensorRT-LLM’s context chunking similarly breaks large contexts across execution iterations.

The tradeoff is important.

A smaller token budget generally protects inter-token latency because less prefill work can interfere with decode. A larger budget can improve TTFT and throughput by allowing more prefill work per iteration. vLLM explicitly documents this tradeoff.

There is no universally correct value.

You tune it against your workload.

KV cache turns scheduling into memory management

There’s another constraint that makes LLM scheduling unusual: KV cache.

Every active sequence retains state needed for future decoding. That means admitting a request isn’t just a compute decision.

It is a memory decision.

A scheduler therefore has to reason about:

GPU compute capacity
KV-cache capacity
token budget
sequence budget
request priority

These resources interact.

A request may fit the current token budget but still be impossible to admit safely because its eventual KV-cache requirement would exhaust GPU memory.

This is one reason the scheduler and KV-cache manager cannot be treated as completely independent subsystems.

The original PagedAttention work identified KV-cache fragmentation and dynamic allocation as major bottlenecks in LLM serving and introduced a paging approach inspired by operating-system virtual memory.

The OS analogy is useful:

Virtual memory:
logical pages → physical frames
LLM serving:
logical KV blocks → GPU memory blocks

The scheduler needs to know whether those blocks are available before it commits to more work.

The dangerous case: KV-cache thrashing

Suppose the scheduler admits requests aggressively because the first chunk of each prompt fits.

Eventually the system reaches:

KV cache: 98% full

New requests arrive.

The engine starts preempting existing work, releasing KV blocks and later recomputing state.

Now the system enters a bad loop:

admit
→ allocate
→ evict
→ preempt
→ recompute
→ allocate
→ evict
→ recompute

GPU utilization can remain high while useful token throughput collapses.

This is classic memory thrashing, just at a different layer of the system.

Current vLLM explicitly exposes scheduler_reserve_full_isl to check whether a request's full input sequence can fit in KV cache before admission, rather than considering only the first chunk. It also exposes a KV-cache watermark that can reserve headroom to reduce eviction and repeated preemption under memory pressure.

That is an important production lesson:

Running at maximum memory utilization is not automatically optimal.

A little headroom can prevent a nonlinear failure mode.

FCFS sounds fair. It isn’t always fair.

The simplest scheduling policy is FCFS:

first request in
→ first request served

Current vLLM supports both FCFS and priority scheduling. In its documented priority policy, lower priority values are handled first, with arrival time breaking ties.

FCFS is easy to reason about, but request size makes it deceptive.

Imagine:

A → 50,000-token prompt
B → 300-token prompt
C → 200-token prompt
D → 100-token prompt

Strictly serving A first may be fair by arrival order while being terrible for latency.

That’s the broader lesson:

Fairness in an LLM system should be defined in terms of resource consumption and service guarantees, not merely queue position.

For a multi-tenant platform, one request is not one unit of cost.

A 20,000-token request can consume substantially more GPU and memory resources than a 200-token request.

Priority without quotas is dangerous

Suppose you have:

Enterprise → high priority
Standard   → normal priority
Batch      → low priority

Priority is useful, but it isn’t enough.

A high-priority tenant should not be allowed to consume the entire GPU fleet simply because every request has a better queue position.

You need multiple controls:

priority
+
token quota
+
concurrency limit
+
rate limit
+
KV capacity
+
workload isolation

For large systems, I’d rather think in terms of resource shares than request counts.

For example:

Enterprise → 50% of token/GPU budget
Standard   → 30%
Batch      → 20%

Those percentages are illustrative, not universal configuration values.

The important part is the unit being measured.

The scheduler is a feedback controller

A production scheduler isn’t just a queue implementation.

It continuously observes:

queue depth
GPU utilization
KV utilization
TTFT
TPOT
active sequences
preemptions
token throughput

and changes what it admits and schedules.

That makes the system look like a feedback controller:

    Traffic --> Scheduler
    Scheduler --> GPU
    GPU --> Metrics
    Metrics --> Scheduler
    Scheduler --> KV[KV Cache]
    KV --> Scheduler

This is why static “GPU utilization targets” are insufficient.

Suppose GPU utilization is 95%, but P99 TTFT has climbed from 300 ms to 4 seconds.

The system is busy.

It is not healthy.

Overload is where the architecture gets tested

Eventually traffic exceeds capacity.

If the system can sustainably generate:

10,000 output tokens/sec

and demand suddenly becomes:

20,000 output tokens/sec

no scheduler can solve the underlying capacity deficit.

The queue grows.

Latency grows.

Memory pressure grows.

Eventually everything gets worse.

The correct response is admission control.

Before accepting a request, the system should ask:

Can this request reasonably be served within its workload’s SLA?

If not, possible actions include:

  • reject with 429 or 503
  • apply backpressure
  • route to another pool
  • downgrade to a cheaper model
  • reduce concurrency
  • queue for batch processing

The exact policy depends on the product.

For a real-time voice agent, dropping or degrading a request may be preferable to allowing queue latency to destroy every active conversation.

Why voice AI changes the scheduler

This is particularly important for conversational systems.

A document-generation workload might care primarily about:

tokens/sec
cost/token

A voice agent cares much more about:

TTFT
inter-token latency
P95/P99 jitter

A scheduler optimized purely for throughput can therefore produce a worse voice product.

You may deliberately leave GPU capacity unused to preserve latency headroom.

That isn’t waste.

It is capacity reserved for a product-level SLA.

A production scheduler architecture

For a serious multi-tenant inference platform, I’d separate the control decisions:

   Request --> Admission
   Admission --> TenantQueues
   TenantQueues --> Policy
   Policy --> Scheduler
   Scheduler --> KVManager
   Scheduler --> TokenBudget
   Scheduler --> SequenceBudget
   KVManager --> BatchBuilder
   TokenBudget --> BatchBuilder
   SequenceBudget --> BatchBuilder
   BatchBuilder --> GPU
   GPU --> Completion
   Completion --> RequestState
   Completion --> KVManager
   RequestState --> Scheduler

The hot scheduling loop should be intentionally boring.

No database queries.

No remote RPCs.

No expensive policy evaluation.

No LLM calls.

The scheduler needs to construct the next GPU workload quickly enough that the GPU doesn’t sit idle waiting for the control plane.

Current vLLM even exposes asynchronous scheduling to reduce CPU-side scheduling overhead and GPU bubbles.

That is a subtle bottleneck that is easy to miss when profiling only GPU kernels.

What I would actually build

I would not start by writing a new inference engine.

I’d use a mature runtime such as vLLM or TensorRT-LLM and build the platform around it.

The differentiated layer should handle:

tenant routing
admission control
quotas
SLA classes
model routing
capacity management
observability
billing
deployment

The runtime should handle the hard GPU work:

continuous batching
KV management
optimized kernels
model execution
tensor/pipeline parallelism

Only replace the runtime when profiling demonstrates a workload-specific bottleneck that justifies the cost.

That’s an important Staff-level engineering decision:

Don’t own infrastructure that doesn’t create product differentiation unless you have a measurable reason to own it.

Performance tuning is a workload problem

There is no magic value for:

max_num_batched_tokens

A smaller value can protect inter-token latency.

A larger value can improve TTFT and throughput.

NVIDIA’s TensorRT-LLM documentation makes the same point around max_num_tokens: larger batches can improve GPU utilization, but pushing the value too far can hurt TTFT and end-to-end latency.

So benchmark using the workload distribution you actually expect.

Don’t benchmark:

1,000 requests
all with 512-token prompts

and assume the result represents production.

Benchmark distributions:

short prompts
long prompts
short outputs
long outputs
bursty arrivals
concurrent streaming
mixed tenants

Then measure:

TTFT P50/P95/P99
TPOT P50/P95/P99
queue time
tokens/sec
KV utilization
GPU utilization
preemptions
cost/token

The deeper systems lesson

LLM scheduling looks like an AI-infrastructure problem, but most of the interesting engineering ideas are familiar from operating systems and distributed systems.

You have:

CPU scheduler
→ who runs next?
LLM scheduler
→ which tokens run next?
Virtual memory
→ where does this memory live?
KV cache
→ where does this sequence state live?
Admission control
→ can this workload enter?
Backpressure
→ what happens when capacity is exhausted?
Fair scheduling
→ who gets scarce resources?
Memory thrashing
→ what happens when we operate too close to capacity?

The implementation details are different.

The systems thinking is remarkably similar.

Final takeaway

A modern LLM inference server is not a text-generation function.

It is a resource-management system.

The scheduler is continuously balancing four competing forces:

GPU compute
KV memory
latency
fairness

Continuous batching keeps work flowing.

Chunked prefill prevents long prompts from monopolizing iterations.

KV-aware admission prevents memory thrashing.

Priority and fairness policies protect important workloads.

Admission control protects the system when demand exceeds capacity.

And observability tells you which constraint is actually limiting the system.

The most important architectural lesson is simple:

Optimize the scheduler around the workload you actually have, not the benchmark you wish you had.

For real-time agents, that usually means protecting latency.

For batch inference, it may mean maximizing throughput.

For a multi-tenant SaaS platform, it means doing both while making resource consumption predictable.

That’s the point where LLM serving stops being “model inference” and becomes what it really is: distributed resource scheduling on expensive accelerators.

References

  • vLLM scheduler configuration and current scheduling controls.
  • vLLM chunked-prefill optimization guidance.
  • TensorRT-LLM in-flight batching, token budgets, and context chunking.
  • Efficient Memory Management for Large Language Model Serving with PagedAttention.

Reactions

Comments

Leave a comment