I recently benchmarked a vLLM server on Colab’s free T4 GPU to learn more about how LLM inference pipelines work.
From this experience I learned one key principle: tuning the workload of an inference server requires making a tradeoff between latency and throughput.
Contents# #
Setup# #
Colab Notebook#
All of the relevant code I used for this is in this Colab notebook.
Running the Inference Server#
In Colab I ran a vLLM inference server on a T4 GPU. I configured the inference server to serve requests using the Qwen/Qwen2.5-0.5B-Instruct model.
Because the notebook uses a Python runtime, you can run the server itself using a subprocess:
server = subprocess.Popen(
["vllm", "serve", "Qwen/Qwen2.5-0.5B-Instruct", "--dtype", "half", "--max-model-len", "4096"],
stdout=log, stderr=subprocess.STDOUT,
)
The model itself is about 1 GB in size. Since the GPU has 16 GB of VRAM, there’s plenty of headroom for the KV cache.
The vLLM CLI offers the vllm bench serve command, which you can use to run load testing on the inference server. It also provides metrics from the test results. Here’s an example of how the command is used:
vllm bench serve --model Qwen/Qwen2.5-0.5B-Instruct --dataset-name random \
--random-input-len 512 --random-output-len 128 --ignore-eos \
--num-prompts 32 --max-concurrency 1
Here’s what each flag does:
num-promptscontrols the number of requests.max-concurrencysets the maximum number of concurrent requests.random-input-lensets the number of tokens in the input prompts.random-output-lensets the length of the model’s output response.dataset-nameselects where the prompts come from. Using the argumentrandomwith this flag will generate synthetic input prompts to simulate user queries.ignore-eostells the server to keep generating past the end-of-sequence (EOS) token that a model emits when it’s finished, so every request produces exactly 128 output tokens.
The command above outputs something like this:
============ Serving Benchmark Result ============
Successful requests: 32
Failed requests: 0
Maximum request concurrency: 1
Benchmark duration (s): 27.34
Total input tokens: 16384
Total generated tokens: 4096
Request throughput (req/s): 1.17
Output token throughput (tok/s): 149.83
Peak output token throughput (tok/s): 160.00
Peak concurrent requests: 3.00
Total token throughput (tok/s): 749.14
---------------Time to First Token----------------
Mean TTFT (ms): 85.09
Median TTFT (ms): 51.49
P99 TTFT (ms): 792.99
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms): 6.05
Median TPOT (ms): 6.05
P99 TPOT (ms): 6.23
---------------Inter-token Latency----------------
Mean ITL (ms): 6.05
Median ITL (ms): 6.05
I’ll dig into what drives these metrics in the future. But for now these are the ones I’ll focus on:
- Output token throughput (tok/s), which measures the rate at which output tokens are generated
- Median TTFT, which measures the median time to first token (TTFT) across all requests
- Median TPOT, which is the median time per output token (TPOT) across all requests
Results# #
I did three separate runs using vllm bench serve to simulate three different loads. I used the same command I shared above:
vllm bench serve --model Qwen/Qwen2.5-0.5B-Instruct --dataset-name random \
--random-input-len 512 --random-output-len 128 --ignore-eos \
--num-prompts 32 --max-concurrency 1
The only things I varied between runs were max-concurrency and num-prompts, which correspond to the first two columns in the table below, respectively.
| No. of Concurrent Requests | Total No. of Requests | Output Tokens per Second | Mean TTFT (ms) | Median TTFT (ms) | Mean TPOT (ms) | Median TPOT (ms) |
|---|---|---|---|---|---|---|
| 1 | 32 | 149.83 | 85.09 | 51.49 | 6.05 | 6.05 |
| 8 | 128 | 626.16 | 595.38 | 250.86 | 8.18 | 8.03 |
| 32 | 256 | 1055.70 | 1657.45 | 332.55 | 17.45 | 16.31 |
From these results I learned that processing more requests concurrently improves the tokens-per-second throughput, as you’d expect. However, the throughput doesn’t scale linearly with the number of concurrent jobs. It jumped by only 7× when the number of concurrent requests moved from 1 to 32.
I was also surprised to see that both TTFT and TPOT increase significantly as you batch more requests. Going from handling requests serially up to batching 32 at once increased the median TTFT and TPOT by about 6.5× and 2.7×, respectively.
Based on this trend, I’d assume that as you increase the number of concurrent requests, you’d reach a point where both TTFT and TPOT are high enough to degrade the user experience for a chat application.
Takeaways and Future Work# #
For chat applications, I’ve learned that limiting the number of concurrent jobs is necessary to hit a sweet spot between latency and throughput. However, for long-running asynchronous tasks, maximizing throughput is the ideal target.
There is one thing I’d like to understand better in future work: What underlying mechanisms are driving the dynamics I observed here? I’d like to get to the root of how and why the performance metrics I measured scale the way they do.