Skip to content
Inference Academy

Lab: profile a slow vLLM server and make it 30% faster

A hands-on engine-profiling lab. Start a vLLM server from a teammate's launch script that hides several real problems among harmless flags, drive it with a fixed workload, then find each bottleneck from evidence: engine metrics, a PyTorch profiler trace from vLLM's built-in profiler, and an Nsight Systems timeline. Fix one thing at a time, measure each change, and write up which fix bought what, aiming for at least 30% more goodput.

By

Key takeaways

  • Start from the metrics, not the profiler: waiting requests, prefix cache hits and tokens per step often name the bottleneck before any trace does.
  • Use the profiler to confirm a hypothesis and to size it, not to go fishing. Capture a few steps with vLLM's built-in profiler and read them.
  • Different bottlenecks leave different fingerprints: a full running queue, zero cache hits, prefill split into many short steps, gaps between kernels.
  • Change one thing at a time and measure each, or you cannot say which fix bought the gain.
  • Some flags in a slow config do nothing. Proving that is part of the job.
120 min · verified 2026-111 animated diagramHands-on labPro
Share

Goal: given a slow vLLM server and a fixed workload, find every bottleneck from evidence, fix them one at a time, and prove a gain of at least 30% in goodput with a report that attributes it.

You need:

Honest limits. We wrote this lab against vLLM v0.34.0 and checked every flag, metric name and profiler option in its source and documentation. We have not run it on a GPU for this page, so it shows no results and promises no particular speed-up: the predictions below are arithmetic, and the numbers are yours to measure. How much each fix buys depends on your GPU. Different hardware can change which problem is the biggest, which is part of the lesson.

#The situation

A teammate's chat assistant "feels slow", and they hand you their launch script. Every request starts with one of four long system prompts (2,048 tokens) followed by a short user message (128 tokens), and asks for 128 tokens back. The product needs TTFT under 1 s and time per output token under 50 ms.

bash
# slow.sh: the teammate's launch script
vllm serve Qwen/Qwen2.5-1.5B-Instruct \
  --port 8000 \
  --max-model-len 8192 \
  --enforce-eager \
  --no-enable-prefix-caching \
  --max-num-batched-tokens 512 \
  --max-num-seqs 8 \
  --seed 0 \
  --profiler-config '{"profiler": "torch", "torch_profiler_dir": "/tmp/vllm_prof"}'

Some of these flags hurt this workload. Some do nothing. Your job is to prove which is which, not to guess. (The last line only enables vLLM's built-in profiler; it does nothing until you call /start_profile.)

#The workload and the baseline

Use vllm bench serve's built-in shared-prefix dataset, so every run sends the same requests:

bash
vllm bench serve --model Qwen/Qwen2.5-1.5B-Instruct --port 8000 \
  --dataset-name prefix_repetition \
  --prefix-repetition-prefix-len 2048 --prefix-repetition-suffix-len 128 \
  --prefix-repetition-num-prefixes 4 --prefix-repetition-output-len 128 \
  --num-prompts 400 --request-rate 4 --seed 0 \
  --goodput ttft:1000 tpot:50 \
  --percentile-metrics ttft,tpot,e2el --metric-percentiles 50,99 \
  --save-result --result-filename baseline-1.json

Run it three times against slow.sh and record the median of each metric: request throughput, output tokens per second, goodput, TTFT p50 and p99, TPOT p50 and p99. Goodput (requests per second that meet both targets) is the number to improve by 30%.

If the baseline is so overloaded that goodput is near zero on your GPU, lower --request-rate until it is clearly above zero and use that rate for every run. Write the rate down.

#Step 1: predict, before you profile

Write down what each suspicious flag should do to this workload. Some arithmetic to start:

  • Prefill work. Without prefix caching, each request prefills 2048+128=21762048 + 128 = 2176 tokens. With it, after the four prefixes are cached, each prefills about 128 (rounded to whole blocks). At 4 requests per second, that is roughly 8,700 against about 500 prefill tokens per second.
  • Prefill compute. A 1.5B-parameter model needs about 2×1.5×109=32 \times 1.5 \times 10^9 = 3 GFLOP per token, so 8,700 tokens per second is about 26 TFLOP/s. Compare that with your GPU's float16 tensor throughput and a realistic utilisation; on some GPUs this alone saturates the server.
  • Chunking. With a budget of 512 tokens per step, one uncached prompt needs ⌈2176/512⌉=5\lceil 2176 / 512 \rceil = 5 steps before its first token.
  • Sequences. With max_num_seqs 8, at most 8 requests run at once. By Little's law, the number in the system is the arrival rate times the time each spends there; if each request takes longer than 2 s end to end at 4 per second, more than 8 are in the system and the rest wait.
  • Eager mode. Without CUDA graphs, each decode step launches every kernel from Python. For a small model at small batches, launch overhead can be a large share of the step.
  • --max-model-len 8192 and --seed 0. Predict whether they matter here.

Rank the suspects by the effect you expect. You will check the ranking at the end.

The rest is Pro

Keep reading this full lab

Pro unlocks this full lab, including 1 animated diagram, every advanced lesson, the hands-on labs and completion certificates.

One year

$25

365 days, no auto-renewal

Lifetime Best value

$75

pay once, keep it forever

7-day refund, no questions asked. One payment, no auto-renewal.Compare plansHave a licence key?

Sandip MaityBuilt by Sandip Maity, who runs self-hosted LLM inference in production.

Not ready? Keep learning free

Or follow the free roadmap →

Not ready? Take the free 5-day email course

One short email a day for five days, each built on a free lesson, then the occasional new lesson or offer. Unsubscribe in one click.

Still to come in this lab

  1. Step 2: read the engine's metrics
  2. Step 3: capture a profile
  3. Step 4: fix one thing at a time
  4. Step 5: the report
  5. Rubric
  6. Checklist
  7. Going deeper

You will be able to answer

  • vllm:num_requests_running sits at exactly 8 while vllm:num_requests_waiting keeps growing, and the KV cache is a third full. What is the most likely limit?
  • Every request shares a 2,048-token system prompt, yet vllm:prefix_cache_hits stays at zero. What does that tell you?
  • In a PyTorch profiler trace of a decode step, the GPU row shows many short kernels with idle gaps between them, and the CPU row is busy launching them. What does this suggest?
  • Your four changes together give a 2.4x gain. Why measure each one on its own as well?