Hypothetical scenario. Northwind’s workflow makes several model calls. Maya reports a long wait before an answer starts and occasional pauses afterward. Dev has one total latency number; Priya asks which portion of the request it describes.
Maya: “Starting late and pausing midway feel like different problems.”
Dev: “Queueing and prefill happen before later decode intervals.”
Priya: “Measure the request path before choosing which work to optimize.”
You will follow prefill and decode through TTFT and inter-token latency, then relate them to workload-specific memory and execution assumptions. A bottleneck description is a hypothesis to test under the actual request mix.
Where in the request does the reader wait?
Time to first token (TTFT) includes the path before the first visible token, which may contain queueing, preprocessing and prefill. Inter-token latency (ITL) describes gaps during streaming decode. Prefill often has substantial parallel compute, while decode can be constrained by moving weights and KV state, but actual bottlenecks depend on batching, hardware and workload. Treat “compute-bound prefill, bandwidth-bound decode” as a hypothesis to test, not an unconditional hardware law.
Hypothetical scenario. Choose 100 ms queueing, 200 ms prefill and 20 ms to expose the first token: TTFT is 100 + 200 + 20 = 320 ms. Four further tokens arrive 25 ms apart, adding 4 × 25 = 100 ms. Five tokens finish in 420 ms under this simplified path. Reducing the later gaps does not remove the original queue delay. Record percentile distributions on actual workloads before sizing capacity.
Loading the model is only the first test
Hypothetical scenario. A library runs a model on its own accelerator. A short demonstration works, so the team admits many simultaneous questions. Some readers submit longer documents. Memory usage rises, requests wait, and a process eventually runs out of available memory even though the model's weight files have not changed.
A serving runtime does more than load parameters. It must tokenize inputs, schedule work, keep state for active sequences, produce output, and release resources when requests finish or stop. It also needs an application boundary for permissions, deadlines, and accepted results.
This chapter uses a deliberately hypothetical dense decoder to derive weight and key/value-cache payloads. You will distinguish those payloads from complete memory use, explain prefill and decoding, and choose what to measure before declaring a safe concurrency limit.
Measure prefill and decode with the request clock
Hypothetical scenario. Choose 100 ms of queueing, 200 ms of prefill to first-token readiness and 50 ms to deliver that token in a deliberately simplified serial model. Time to first visible token is 100 + 200 + 50 = 350 ms. Decode intervals belong after that first-token boundary.
| Artifact | Concrete evidence | Decision boundary |
|---|---|---|
| Request clock | queue, prefill, first delivery | TTFT boundary |
| Decode evidence | visible token intervals, stop reason | Streaming experience |
| Resource shape | prompt/output caps, active state | Admission and cancellation |
Record prompt length, generated length, concurrency and cancellation with each latency observation. A fast first token can coexist with poor total completion time, and a low mean decode interval can hide a bad tail for long requests. Weight fit excludes active KV state and runtime overhead. Admission needs the actual request shape and survivor serving-group capacity, not only model parameter count.
Parameter count is not a serving budget
Multiplying parameter count by bytes per stored parameter estimates one payload. It omits active-sequence state, intermediate buffers, runtime allocations, metadata, and any additional copies used by the implementation. A configuration that loads successfully can still fail when requests arrive.
Smaller stored weights may help a memory constraint, but they do not automatically improve latency or preserve task behavior. Quantized formats can require extra scaling metadata and specific kernels. Their actual memory and quality effects need their own measurement; a bit count alone is not a complete deployment recommendation.
Nor does running on an owned machine automatically establish privacy. Inspect network calls, artifact downloads, logging, caches, and who may submit or inspect requests. “Local” describes placement; the security properties come from the actual boundaries and controls.
Prefill and decoding compete for resources
For the decoder considered here, prefill processes the supplied input and builds the cached keys and values used by later attention steps. Decoding then generates additional tokens incrementally, retaining state for the sequence. The cache grows with retained sequence length under the architecture and assumptions used below.
Batching combines work from multiple requests. A continuous scheduler can admit or remove sequences as execution progresses rather than waiting for every member of a fixed batch to finish. The benefit and cost depend on the runtime and workload: packing more work together can improve aggregate utilization while changing individual waiting times.
A long prefill and a short decoding step place different demands on the service. Scheduling them is a resource and latency decision, not simply a count of active HTTP requests. Track queue time, time to first output, time between outputs, and completion time separately.
The vLLM paged-attention documentation explains block-managed key/value storage. The values still occupy memory; allocation efficiency and payload size are separate constraints.
Work the weight and cache payloads
Hypothetical scenario. Choose a decoder with 2,000,000,000 stored parameters at two bytes each. Weight payload is 2,000,000,000 × 2 = 4,000,000,000 bytes: 4 decimal GB. In binary units it is 4,000,000,000/1,073,741,824 ≈ 3.7253 GiB.
Independently declare the cache architecture: 16 layers, four key/value heads per layer, head dimension 64, two bytes per cached element, and no sharing or compression between sequences. Both a key and a value are stored. For B equally long active sequences retaining T tokens, payload is 2 × 16 × B × T × 4 × 64 × 2 bytes.
For B = 1 and T = 2,048, the calculation gives 33,554,432 bytes, exactly 32 MiB. For B = 32 at that length, it gives 32 × 32 MiB = 1,024 MiB = 1 GiB. Retained length includes the input and generated tokens whose state is kept; it is not just the latest output token.
| Hypothetical configuration | Cache payload | Weights + cache + chosen 1 GiB workspace reserve |
|---|---|---|
| 32 sequences, 2,048 retained tokens each | 1 GiB | Approximately 5.7253 GiB |
| 32 sequences, 8,192 retained tokens each | 4 GiB | Approximately 8.7253 GiB |
The second row has four times the retained tokens, so its cache has four times the payload. On a hypothetical device with 8 GiB available, that row already exceeds the allowance before additional allocations. In the first row, 8 − 5.7253 ≈ 2.2747 GiB remains after the listed items. That remainder is not proof that the configuration is operationally safe.
The 1 GiB workspace reserve is a chosen planning assumption, not a measured runtime requirement. Real kernels, temporary buffers, graph metadata, allocator behavior, and concurrent work can change the total. Different attention architectures, cache precision, retained-window policies, or sharing rules change the cache calculation. Use the actual model and runtime contract before applying it.
This calculation also does not give tokens per second. Memory capacity is one constraint; compute, memory traffic, scheduling, and request variation still determine observed performance. Measure the intended workload rather than translating spare bytes into an invented throughput number.
Admission needs more than a request count
Two active requests can have very different input lengths, output allowances, and remaining work. A fixed concurrent-request cap may be useful, but it does not by itself bound retained tokens or queue delay. Consider both a resource budget and a policy for how long work may wait.
Reserve or track resources according to the chosen scheduling design. If admission uses requested maximum lengths, it may be conservative; if it relies on current consumption alone, it needs a policy for later growth. Neither policy removes the need for a defined rejection or stopping behavior when capacity is exhausted.
Admission needs to preserve useful service under the declared deadline and memory allowance. Count rejected and expired work alongside accepted requests when evaluating a serving configuration.
Measure an operating point with representative short and long inputs, output lengths, bursts, and cancellations. Report both aggregate output rate and user-facing latency distributions. A single-request demonstration cannot establish behavior under mixed concurrent demand.
A fixed cap can fail when contexts grow
Hypothetical scenario. A service chooses its concurrency limit using only short prompts. Later, document questions require longer retained contexts. The request count remains unchanged, but cache payload increases as in the worked table. Failures appear despite an unchanged model file.
The repair is to revisit admission, length allowances, and the scheduling/resource model. Adding an unbounded queue merely moves the failure into waiting time and can waste work after callers have given up. Reducing a request's allowed length may be appropriate only if the application still supplies the evidence needed for a useful answer.
Test the changed policy under long-context bursts and during restart or cancellation. Record accepted, rejected, completed, and interrupted tasks separately. A lower failure count is not sufficient if it came from silently truncating every difficult request or never admitting it without telling the caller.
Four shortcuts that hide an operating requirement
“The weights fit, so the service fits.” Add per-sequence state and runtime allocations, then exercise the actual workload.
“Batching makes every request faster.” Aggregate efficiency and individual waiting time are different outcomes. Measure both.
“Paged allocation eliminates memory cost.” Better management can reduce waste and enable sharing under supported conditions. It does not remove the represented keys and values.
“A stopped client means resources are already free.” Cancellation and cleanup need an implemented path. Confirm when scheduling stops and state is released rather than inferring it from a disconnected socket.
Choose hosting for the task and the operating team
Local serving is a candidate when control over deployment, connectivity, or resource ownership matters and the team can operate the runtime. Verify the model artifact's provenance and applicable use conditions, supported hardware, update path, and the actual task quality. Control over a machine does not establish control over every artifact or dependency.
A managed endpoint may meet the requirement with less runtime maintenance, while retaining integration, permissions, evaluation, and failure-handling work in the application. Compare complete accepted-task behavior rather than a model file size against an endpoint's advertised throughput.
Start with the simplest serving configuration that lets you measure the intended task. Add distributed execution or a more elaborate scheduler when a demonstrated constraint justifies the complexity. Model loading, admission, observability, and recovery remain separate responsibilities even if one package provides several of them.
vLLM schedules a changing set of sequences
A serving engine must handle requests that enter and finish at different times. Continuous batching changes the active set between generation iterations, rather than waiting for every sequence in a fixed batch to finish. This can reuse available execution capacity, while requiring a scheduler to track per-sequence state and admit work within memory and deadline limits.
Prefill processes a request’s input tokens and builds attention state. Decode generates subsequent tokens using that state. A long prefill can compete with the decode work of existing conversations. The vLLM optimization guide describes chunked prefill, which divides input processing into smaller scheduled portions. The trade-off concerns scheduling and responsiveness; splitting the input does not remove the full input’s eventual computation.
PagedAttention manages key/value storage through blocks rather than requiring one contiguous maximum-length allocation per sequence. A mapping relates logical sequence positions to physical blocks. This reduces particular allocation waste and enables controlled sharing; the values for retained tokens still occupy memory. Weight quantization and KV-cache allocation are separate choices, and smaller weights do not imply that each conversation’s KV state shrank.
Calculate admission from the memory that remains
Hypothetical worked example: after reserving model weights and runtime overhead, choose a 4 GiB allowance exclusively for KV payload. Under the earlier illustrative configuration, a 4,096-token sequence uses 2 × 32 × 8 × 128 × 4,096 × 2 = 536,870,912 bytes, or 0.5 GiB. Four GiB / 0.5 GiB permits at most 8 such sequence payloads before block overhead and future growth.
If each sequence grows to 8,192 tokens, the payload doubles to 1 GiB per sequence. The same allowance then fits only 4 payloads. Admission based only on the current prompt length can therefore promise more concurrent work than the generation budget permits. Reserve output headroom or use a documented preemption policy rather than assuming every admitted chat stays short.
The limit is a component calculation, not a throughput benchmark. Scheduler overhead, block rounding, temporary activations and hardware bandwidth add constraints. Measure time to first token and time between tokens under the intended request mix, and report rejection and preemption as outcomes instead of excluding them from a successful-request average.
In the wild: allocation and scheduling need different evidence
The vLLM documentation describes paged attention and tuning choices for chunked prefill and memory pressure. These are concrete runtime mechanisms, not a universal speedup for Northwind’s workload. The project’s configuration should be pinned and evaluated with the selected model, sequence lengths and concurrency before any capacity promise is made.
For Northwind, Sam separates the weight footprint, KV allowance and queued-work deadline. Priya’s short policy questions should not wait indefinitely behind a long document upload. A bounded prefill schedule helps share execution, while admission and queue-age limits decide whether the service can still meet its user contract. None of those controls changes which policy evidence is authorized.
Northwind decision log
- Reserve headroom for growing sequences.
- Measure prefill and decode separately.
- Reject work before memory exhaustion spreads.
Go deeper into memory and scheduling
- Book chapter: LLMs in Production, chapter 6: Large language model services: A practical guide — Christopher Brousseau and Matthew Sharp. Read this chapter for the model lifecycle and resource trade-offs.
- Book chapter: Machine Learning Engineering in Action, chapter 16: Production infrastructure — Ben Wilson. Read this chapter for the model lifecycle and resource trade-offs.
- Video lecture: Memory & Disk I/O Management, CMU Fall 2024 — Andy Pavlo / CMU Database Group. Watch first for the memory hierarchy behind allocation.
- Primary documentation: vLLM paged attention. Explains paged allocation and scheduling settings; evaluate these mechanisms under the intended sequence workload.
- Primary documentation: vLLM optimization and tuning. Explains paged allocation and scheduling settings; evaluate these mechanisms under the intended sequence workload.
Test the request clock boundary
TTFT improves after requests are timed out earlier. Has serving quality improved?
Reveal the design reasoning
Check the full admitted population and useful completions. Excluding timed-out or cancelled requests can improve the chart while failing more users. Preserve output and task acceptance evidence.
Decision: Measure the promised client boundary and active resource lifetime together.
Check yourself: challenge the serving limit
Under the worked cache architecture, what happens when retained length doubles while active sequence count stays fixed?
Cache payload doubles because T appears as a linear factor. This says nothing by itself about an exact latency multiplier, and it assumes the same cache precision, retention, sharing, and attention architecture.
A demonstration reports high aggregate output tokens per second but long delays before short requests start. Has it proved the interactive service meets its goal?
No. Aggregate rate does not establish queue delay or time to first output for the relevant users. Inspect latency distributions and the scheduler's handling of mixed input lengths under the intended demand.
A two-byte parameter representation is replaced by a nominal one-byte format. Can the full deployment memory budget simply be halved?
No. Only the corresponding parameter payload would halve under that simplified storage assumption. Cache state, workspace, metadata, and implementation-specific allocations remain. Measure the actual format, kernels, and task quality before selecting a deployment.
Check the mechanism in this lesson
Why does reducing inter-token gaps fail to remove the chosen 100 ms queue delay?
Compare the explanation
The delay happens before the first token. TTFT and later decode intervals describe different portions of the request lifetime. Diagnose and budget both rather than assuming every latency change affects both.
Carry the decision forward
Northwind can distinguish stages of waiting. Page 31 examines how continuous batching and block-managed KV state change scheduling and memory admission without promising a fixed throughput gain.