mcpField
V
vllm-bench-random-synthetic

vllm-bench-random-synthetic

github.com/vllm-project测试与质量103170 次安装30 周前更新
代码仓库

关于 vllm-bench-random-synthetic

使用自动生成的随机提示对 vLLM 服务进行基准测试的 Skill。它报告请求与 Token 吞吐量,以及首 Token 时间、每输出 Token 时间和 Token 间延迟。

主要功能

  1. 01随机合成负载
  2. 02请求与 Token 吞吐量指标
  3. 03TTFT、TPOT 和 Token 间延迟
  4. 04保存基准测试结果

适用场景

  1. 01快速评估 vLLM 服务
  2. 02建立模型服务性能基线
  3. 03比较不同并发设置下的延迟

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/vllm-project/vllm-skills --skill vllm-bench-random-synthetic

安装后在 Claude Code 中输入/vllm-bench-random-synthetic确认已加载。

详细介绍

使用随机合成数据进行 vLLM 基准测试

使用随机合成数据,在 vLLM 服务上快速运行性能基准测试。此技能可测量核心服务指标,包括请求吞吐量、令牌吞吐量、TTFT(首令牌时间)、TPOT(每个输出令牌的耗时)和令牌间延迟。

适用场景

  • 用户想要快速测试 vLLM 的服务性能
  • 用户想要测量吞吐量和延迟指标,而无需下载数据集
  • 用户想要使用合成工作负载测试 vLLM 部署
  • 用户想要了解特定模型的基准性能数据

前置条件

  • 必须已安装 vLLM(pip install vllm)
  • 必须有正在运行的 vLLM 服务(也可以在基准测试过程中启动)
  • 对于 GPU 模型,必须有配备适当驱动程序的 NVIDIA GPU

快速开始

运行基准测试的最简单方法:

# Start vLLM server (in background or separate terminal)
vllm serve Qwen/Qwen2.5-1.5B-Instruct

# Run benchmark with random synthetic data
vllm bench serve \
  --backend openai-chat \
  --model Qwen/Qwen2.5-1.5B-Instruct \
  --endpoint /v1/chat/completions \
  --dataset-name random \
  --num-prompts 10

注意:

  • 在线基准测试请使用 --backend openai-chat,端点为 /v1/chat/completions。

参数

参数描述默认值
--backend后端类型:vllm、openai、openai-chatvllm
--model模型名称(必须与服务端一致)必填
--endpointAPI 端点路径/v1/completions 或 /v1/chat/completions
--dataset-name要使用的数据集random(合成数据)
--num-prompts要发送的请求数10
--port服务端口8000
--max-concurrency最大并发请求数自动
--save-result将结果保存到文件关闭
--result-dir保存结果的目录./

预期输出

成功时,你会看到类似如下的输出:

============ Serving Benchmark Result ============
Successful requests:                     10
Benchmark duration (s):                  5.78
Total input tokens:                      1369
Total generated tokens:                  2212
Request throughput (req/s):              1.73
Output token throughput (tok/s):         382.89
Total token throughput (tok/s):          619.85
---------------Time to First Token----------------
Mean TTFT (ms):                          71.54
Median TTFT (ms):                        73.88
P99 TTFT (ms):                           79.49
-----Time per Output Token (excl. 1st token)------
Mean TPOT (ms):                          7.91
Median TPOT (ms):                        7.96
P99 TPOT (ms):                           8.03
---------------Inter-token Latency----------------
Mean ITL (ms):                           7.74
Median ITL (ms):                         7.70
P99 ITL (ms):                            8.39
==================================================

高级用法

增加提示词数量以获得更可靠的统计数据
vllm bench serve \
  --backend openai-chat \
  --model Qwen/Qwen2.5-1.5B-Instruct \
  --endpoint /v1/chat/completions \
  --dataset-name random \
  --num-prompts 100
将结果保存到文件
vllm bench serve \
  --backend openai-chat \
  --model Qwen/Qwen2.5-1.5B-Instruct \
  --endpoint /v1/chat/completions \
  --dataset-name random \
  --num-prompts 50 \
  --save-result \
  --result-dir ./benchmark-results/
自定义端口和并发数
vllm bench serve \
  --backend openai-chat \
  --model meta-llama/Llama-3.1-8B-Instruct \
  --endpoint /v1/chat/completions \
  --dataset-name random \
  --num-prompts 100 \
  --port 8001 \
  --max-concurrency 4

模型推荐

用于快速测试(小型模型,速度快):

  • Qwen/Qwen2.5-1.5B-Instruct(推荐用于快速测试)
  • facebook/opt-125m
  • facebook/opt-350m

用于真实场景基准测试(中型模型):

  • Qwen/Qwen2.5-7B-Instruct
  • meta-llama/Llama-3.1-8B-Instruct
  • mistralai/Mistral-7B-Instruct-v0.3

工作流

  1. 检查是否已安装 vLLM:运行 vllm --version 进行确认
  2. 检查服务是否已在运行:运行 curl http://localhost:8000/health 进行检查
  3. 如有需要,启动 vLLM 服务:运行 vllm serve <model-name>(等待出现 “Application startup complete”)
  4. 运行基准测试:使用适当的参数执行 vllm bench serve
  5. 查看结果:检查吞吐量和延迟指标
  6. 清理:如果 Agent 技能启动了 vLLM 服务(而非使用已存在的服务),请在基准测试完成后使用 kill <PID> 停止服务

故障排除

服务无响应:

  • 检查服务是否正在运行:curl http://localhost:8000/health
  • 确认端口是否匹配:如果服务使用了其他端口,请使用 --port 标志

找不到模型:

  • 确保服务端和基准测试使用的模型名称完全一致
  • 检查 HuggingFace 访问权限:如有需要,运行 export HF_TOKEN=<your_token>

内存不足:

  • 使用更小的模型(例如 Qwen2.5-1.5B-Instruct)
  • 减少 --num-prompts 或 --max-concurrency

连接被拒绝:

  • 服务可能仍在启动(等待出现 “Application startup complete”)
  • 检查防火墙或网络设置

注意事项

  • random 数据集会自动生成合成提示词
  • 基准测试时长会随 --num-prompts 增加而延长
  • 生产环境基准测试至少应使用 100 个提示词,以获得稳定的统计数据
  • 结果可能因硬件、模型大小和系统负载而异
  • 首次运行可能较慢,因为需要加载和编译模型
  • 重要:如果 Agent 技能为基准测试启动了 vLLM 服务,必须在基准测试完成后停止服务以释放资源。不要停止基准测试前已经运行的服务。

评论

支持 Markdown