Serving systems · Advanced

KV Cache Under LLM Load: Testing PagedAttention and vLLM

KV-кэш LLM под нагрузкой: проверяем PagedAttention и vLLM
Temporary fallback cover; replace in editorial pass.

15 min read · Updated November 24, 2026

When a language-model service accepts several users at once, the first resource to fail is often neither the GPU’s arithmetic throughput nor its raw allocation limit. It is the space and scheduling behavior of the KV cache: the attention state retained for tokens that are already in context. This guide builds a repeatable experiment around PagedAttention and vLLM, then shows how to measure throughput, time to first token, inter-token latency, and request preemption without inventing performance claims.

The concrete problem

Imagine an inference endpoint serving chat requests with different prompt lengths and different generation lengths. A short request may finish quickly; another may keep thousands of tokens resident while it generates. Under concurrency, each request needs space for key and value tensors. If the service reserves memory in large contiguous regions, variable-length requests can leave unusable gaps. The GPU can have free bytes in aggregate while a new request still cannot obtain the shape or block it needs.

The practical symptom is a service that appears compute-capable but becomes unstable as concurrency rises: queueing increases, first-token latency becomes erratic, requests are paused or evicted, and the reported KV-cache utilization approaches its limit. The experiment below is designed to reveal that transition rather than hide it behind one average latency number.

What the experiment isolates

PagedAttention stores KV-cache data in fixed-size blocks and lets the serving engine map a sequence’s logical positions to physical blocks. The intended benefit is operational: allocation can follow the actual sequence length, and completed or paused sequences can release or move blocks without requiring one large contiguous region for every request. That mechanism does not make the model’s attention computation free, and it does not remove the finite capacity of GPU memory.

The test therefore compares behavior across controlled load levels. It should answer four questions:

  • How does aggregate generated-token throughput change as concurrency increases?
  • How does time to first token change independently of generation speed?
  • How stable is inter-token latency while requests share the GPU?
  • At what load does the scheduler preempt, pause, or reject requests?

Record the environment before starting

Reproducibility starts with an inventory. Save the exact model identifier, revision or digest, quantization mode, tokenizer, GPU model, available memory, CUDA and driver versions, container image, vLLM version, Python version, and server arguments. Also record whether the GPU is shared with another process.

nvidia-smi
python --version
python -c "import vllm; print(vllm.__version__)"
python -c "import torch; print(torch.__version__, torch.version.cuda)"

Treat the output as part of the benchmark artifact. If a command is unavailable in your image, note that explicitly and use the corresponding platform-specific inspection method. Do not compare results from different model revisions or quantization settings as if they were one run.

Start a minimal vLLM server

The following example uses a placeholder model name. Replace it with a model you are authorized to download and run. The command is intentionally explicit so that another operator can reproduce the serving configuration.

export MODEL_ID="your-org/your-model"
export PORT="8000"

vllm serve "$MODEL_ID" \
  --host 0.0.0.0 \
  --port "$PORT" \
  --dtype auto \
  --max-model-len 4096 \
  --gpu-memory-utilization 0.90 \
  --max-num-seqs 64 \
  --enable-prefix-caching

Prefix caching is workload-dependent. Keep it enabled only if your production-like workload reuses prompt prefixes. For a clean KV-cache allocation experiment, run a second series with it disabled and label the series separately. The important rule is to keep every server argument constant inside one comparison.

Check that the process is ready before sending load. The endpoint and response shape can vary by vLLM release, so use the health or model endpoint documented for the installed version and verify that the model identifier matches the requested one.

curl -sS "http://127.0.0.1:${PORT}/v1/models"

Build a controlled request set

A useful first workload has three prompt classes and two generation targets:

  • Short prompt: roughly 128 input tokens.
  • Medium prompt: roughly 1,024 input tokens.
  • Long prompt: close to the configured context limit, while leaving room for output.
  • Short generation: roughly 64 output tokens.
  • Long generation: roughly 512 output tokens.

These values are examples, not measured facts or universal requirements. Tokenize the actual prompts with the exact tokenizer used by the server and report the resulting input and output lengths. Use deterministic prompt fixtures stored in a file; do not generate new random text for every run unless randomness is the variable being studied.

Warm the server with a small number of requests before collecting measurements. Exclude warm-up requests from the report, and state how many were sent. Keep the request order reproducible, or randomize it with a recorded seed.

Measure the four required dimensions

1. Throughput

Measure both request throughput and generated-token throughput. For a window from the first admitted request to the last completed request:

request_throughput = completed_requests / elapsed_seconds
token_throughput = sum(generated_tokens) / elapsed_seconds

Report the measurement window, concurrency, prompt-token distribution, generated-token distribution, and whether queued time is included. A server that produces many tokens per second but delays admission can still be poor for interactive traffic.

2. Time to first token

Time to first token (TTFT) is the elapsed time from request submission until the first streamed output token is received. Measure it at the client boundary, using a monotonic clock. Keep connection setup separate if possible; otherwise state that connection setup is included.

ttft = timestamp(first_output_token) - timestamp(request_submission)

Report median and tail percentiles such as p95 and p99 when the sample size supports them. Averages alone can conceal the queueing spikes caused by cache pressure.

3. Inter-token latency

Inter-token latency (ITL) is the interval between successive streamed output tokens. For one request, calculate the intervals after the first token, then summarize them across requests. Distinguish the first interval from later intervals; the first interval contains prompt processing and scheduling effects that later decode steps do not.

itl[i] = timestamp(token[i]) - timestamp(token[i - 1])

Record whether the client measures network arrival time or server-side token production time. Network buffering, proxies, and client event-loop scheduling can alter observed ITL.

4. Request preemption

Request preemption means the scheduler pauses a request and later resumes it, or otherwise reclaims its execution opportunity to admit or progress other work. Identify it from the server’s documented metrics or logs for your release. Do not infer preemption solely from a slow request: queueing, synchronization, memory allocation, and transport delays can look similar at the client.

Capture preemption counters or log events per interval and correlate them with KV-cache utilization, queue depth, TTFT, and ITL. The result should say exactly what signal was counted and what it means in that version.

A simple load sweep

Run the same request mix at increasing offered concurrency, for example 1, 2, 4, 8, 16, 32, and 64 clients. These levels are a starting sequence; stop or adjust them when the server cannot maintain the intended test duration. Use several repetitions per level and allow the system to return to a comparable idle state between repetitions.

for concurrency in 1 2 4 8 16 32 64; do
  ./run_benchmark \
    --base-url http://127.0.0.1:8000 \
    --model "$MODEL_ID" \
    --workload workloads/mixed-prompts.jsonl \
    --concurrency "$concurrency" \
    --duration 120 \
    --output "results/c${concurrency}.jsonl"
done

The executable above is a placeholder for your benchmark client. It must emit per-request submission time, first-token time, every token arrival time or an equivalent ITL summary, completion time, input-token count, output-token count, status, and an error or preemption field when available.

Keep offered concurrency and active concurrency separate. If requests queue outside the server, the client may report the former while the server is operating at a different active level.

Verification checklist

Before interpreting the results, verify the following:

  • The model, tokenizer, server version, and server flags are identical across compared runs.
  • Input and output token counts are measured, not assumed from character counts.
  • Warm-up samples are excluded and the exclusion rule is recorded.
  • Client clocks use a monotonic timer and timestamps are written with sufficient precision.
  • HTTP errors, cancellations, timeouts, and incomplete streams are retained in the raw output.
  • GPU memory and server metrics are sampled at a known interval with synchronized run identifiers.
  • Results include repetitions or confidence intervals appropriate to the workload duration.

A minimal result table should contain: run ID, server configuration hash, concurrency, completed requests, input tokens, output tokens, throughput, TTFT p50/p95/p99, ITL p50/p95/p99, preemption count, error count, peak memory, and notes.

Failure cases and how to interpret them

Out-of-memory during model startup

This is a model-footprint or reservation problem before the intended load test begins. Confirm the model, tensor parallel configuration, dtype, maximum context, and GPU assignment. Lowering the context limit may reduce the KV-cache reservation, but it changes the experiment and must be recorded.

Out-of-memory only under concurrency

Check whether the workload exceeds the configured context length, whether output limits are enforced, and whether another process is consuming memory. Inspect server logs and cache metrics before attributing the failure to fragmentation. A single client retry loop can also create an artificial load multiplier.

High TTFT with normal ITL

This pattern commonly points toward admission queueing or prompt processing rather than slow decode. Compare TTFT with queue depth, prompt length, and active sequences. Do not collapse TTFT and ITL into one latency metric.

High ITL with low TTFT

This can indicate decode contention, a scheduling bottleneck, or a client-side streaming issue. Compare server-side timing with packet or client arrival timing, and test a local client on the same host to reduce transport uncertainty.

Preemption appears without an obvious memory failure

Preemption can be a normal scheduling response near a resource limit. Confirm the exact event definition in the installed release, then correlate the event with active sequence count, cache utilization, request lengths, and latency tails. A preemption counter without workload context is not enough to establish a regression.

Results change between repetitions

Investigate prompt order, prefix reuse, background GPU work, model compilation or kernel caches, temperature or power throttling, and client-side rate limiting. Preserve the anomalous run instead of silently dropping it.

Limitations

This method evaluates one serving stack and one workload definition at a time. It does not prove that PagedAttention is faster for every model, GPU, context length, quantization format, or traffic pattern. It also does not isolate every source of memory fragmentation: allocator behavior, CUDA workspace requirements, model weights, activation buffers, and external processes can all affect available memory.

Client-observed latency is an end-to-end signal. It includes queueing and transport, and it may include buffering in the HTTP stack. For a deeper study, collect server-side traces or metrics with the same run IDs and compare them to client timestamps.

Finally, a benchmark that uses only uniform prompts and uniform output lengths can miss the allocation churn seen in production. Include mixed lengths and realistic cancellation behavior before using the result for capacity planning.

What a defensible conclusion looks like

A defensible report names the exact configuration, shows the raw workload and measurement definitions, and identifies the point at which latency tails, preemption, errors, or cache utilization change materially. It can say, for example, that a particular configuration sustained a specified token rate at a specified concurrency under a named workload, or that preemption began above a recorded load. It should not generalize that observation to all vLLM deployments.

The useful outcome is a capacity envelope: a range of concurrency and token lengths in which throughput and latency remain acceptable, plus a documented failure boundary. That envelope is more actionable than a single peak-throughput number because it connects memory pressure to the user-visible behavior of the service.

We publish what works for us—and implement the same solutions for your business. We design AI automation, Telegram bots, chats, and AI agents for real-world processes. Discuss your project →