vegeta命令速查
安装与版本、目标文件构造、attack 参数、速率与并发、协议与 TLS、report 解读、plot/encode、CI 门禁与报错排查等 120 条命令
共 120 条命令 · 10 类场景 · 点击右侧图标可复制
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
vegeta -version | 查看版本,v12 起模块路径带 /v12 | |
vegeta -h | 查看子命令与全局参数 | |
vegeta attack -h | 查看 attack 的全部参数,版本差异以它为准确 | |
go install github.com/tsenart/vegeta/v12@latest | Go 环境安装,产物在 $GOPATH/bin | |
brew install vegeta | macOS 安装 | |
dnf install vegeta | RHEL/Fedora 系安装 | |
apt install vegeta | Debian/Ubuntu,部分版本需自行加源 | |
docker run --rm -i peterevans/vegeta sh -c "cat > /tmp/t.txt && vegeta attack -targets=/tmp/t.txt" | 容器运行,注意 stdin 与文件挂载方式 | |
GOMAXPROCS=4 vegeta attack ... | 限制 Go 运行时使用的核数,避免压测机把 CPU 打满 | |
vegeta 是恒定速率工具 | 与 wrk2 同属开环,天然规避协调遗漏带来的乐观延迟 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
GET http://example.com/ | 最小目标:方法 + 空格的 URL | |
GET http://example.com/
X-Env: test
Authorization: Bearer xxx | 第一行后紧跟请求头,每行一个 | |
POST http://example.com/api
Content-Type: application/json
@body.json | @ 开头表示从文件读取请求体 | |
GET http://example.com/a
GET http://example.com/b | 空行分隔多个目标,vegeta 会轮询使用 | |
POST http://example.com/api
Content-Type: application/json
{"k":"v"} | 请求体也可直接内联,但要注意 shell 与换行 | |
echo "GET http://example.com/" | vegeta attack -duration=5s | 不写文件,直接用标准输入传单个目标 | |
vegeta attack -targets=targets.txt ... | 最常用方式:把目标写进文件纳入版本管理 | |
PUT http://example.com/item/1
Content-Type: application/json
@put.json | PUT 请求同样只改首行方法 | |
DELETE http://example.com/item/1 | 无请求体的方法直接一行即可 | |
目标文件里不能有注释行 | 写错格式会报 bad target,建议先用 1 个目标试跑 | |
URL 必须是绝对地址 | 缺 scheme 会解析失败 | |
echo -n "GET http://example.com/" | vegeta attack -rate=10 -duration=5s | echo 记得 -n,避免多余换行影响解析 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
vegeta attack -targets=t.txt -rate=50 -duration=30s | vegeta report | 最经典的管道组合:压测并直接出报告 | |
vegeta attack -targets=t.txt -duration=10s -output=results.bin | 结果写二进制文件,便于多次分析 | |
vegeta attack -targets=t.txt -rate=100 -duration=30s | tee results.bin | vegeta report | 边压测边落盘,中断也保留已有结果 | |
echo "GET http://example.com/" | vegeta attack -rate=5 -duration=5s | vegeta report | 一条命令完成冒烟,验证环境与参数 | |
vegeta attack -targets=t.txt -rate=100 -duration=1m -name=api-v1 | 给本次攻击命名,便于在报告中区分 | |
vegeta attack -targets=t.txt -rate=0 -duration=30s | rate=0 让 vegeta 以最大能力发压(懒模式) | |
vegeta attack -targets=t.txt -rate=50 -duration=30s -lazy | 懒模式,不强求恒定速率,适合找最大吞吐 | |
vegeta attack -targets=t.txt -rate=100 -duration=30s -header "X-Trace: bench" | 命令行追加请求头,会覆盖目标文件里的同名头 | |
vegeta attack -targets=t.txt -body=payload.json -rate=20 -duration=10s | 统一替换请求体,配合简单目标文件使用 | |
vegeta attack -targets=t.txt -rate=100 -duration=30s 2>/dev/null > results.bin | 分离日志与数据,结果文件更干净 | |
attack 必须给 -duration 或持续有输入 | 只给 duration 会按时长结束,不给则一直跑 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
-rate=100 | 每秒 100 个请求,最简写法 | |
-rate=100/1s | 显式指定时间单位,等价上一条 | |
-rate=10/500ms | 每 500ms 发 10 个请求 | |
-rate=5/1m | 低频场景,做长周期可用性验证 | |
-workers=10 | 并发 worker 数,决定能同时处理多少请求 | |
-max-workers=100 | worker 上限,rate 高时自动扩容到该值 | |
-connections=10000 | 每个目标的空闲连接池上限 | |
-timeout=5s | 单请求超时,慢接口要放宽 | |
workers 要按 Little 定律估 | workers ≈ rate × 目标延迟(秒),给少了会拖慢实际速率 | |
-keepalive=false | 关闭连接复用,测短连接与握手开销 | |
-redirects=0 | 不跟随重定向,避免把跳转耗时算进业务耗时 | |
-max-body=0 | 只读响应头不读 body,减少客户端开销 | |
rate 越高越要核对实际速率 | 看 report 里的 Rate 是否达到设定值,没达到说明客户端不够 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
vegeta attack -targets=https.txt -rate=50 -duration=10s | 目标写 https 地址即走 TLS | |
-insecure | 跳过证书校验,压自签或内网 HTTPS 必加 | |
-root-certs=/etc/ssl/certs/ca.pem | 指定自建 CA 根证书,比 -insecure 更严谨 | |
-cert=client.crt -key=client.key | mTLS 双向认证场景 | |
-http2 | 启用 HTTP/2 压测 | |
-format=http/2 | 显式指定协议格式,等价于 -http2 | |
-h2c | 明文 HTTP/2(h2c),内网 gRPC 前置网关常用 | |
-resolvers=8.8.8.8:53 | 指定 DNS 解析器,排除内网 DNS 干扰 | |
-laddr=10.0.0.5 | 绑定源地址,多网卡机器可分流 | |
-unix-socket=/var/run/app.sock | 通过 unix socket 压测本机服务,绕过网络 | |
-proxy-header="Proxy-Authorization: Basic xxx" | 走代理时补充代理认证头 | |
HTTPS 场景先确认 ALPN | 用 openssl s_client -alpn h2 验证服务端是否真的支持 HTTP/2 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
vegeta report results.bin | 默认 text 报告,最常用 | |
cat results.bin | vegeta report | 管道输入同样支持 | |
Requests [total, rate, throughput] | 总请求数、目标速率与实际吞吐,三者对照看是否达成 | |
Duration [total, attack, wait] | 总耗时、攻击时长与等待结果的时间 | |
Latency [mean, 50, 90, 95, 99, max] | 延迟分位,长尾看 99 与 max | |
Bytes In / Bytes Out | 收发字节数,用于评估带宽占用 | |
Success [ratio] | 成功率,低于预期先看 Status Codes 与 Errors | |
Status Codes [code:count] | 各状态码计数,快速识别 4xx/5xx 集中出现的原因 | |
Errors [count] | 网络层错误汇总,常见 timeout、connection refused | |
vegeta report -type=json results.bin | JSON 输出,便于脚本断言与入库 | |
vegeta report -type="hist[0,100ms,200ms,500ms]" results.bin | 直方图分桶,看延迟分布形态 | |
vegeta report -every=1s results.bin | 流式输出周期报告,观察压测过程变化 | |
vegeta report -type=json results.bin | jq .latency | 提取延迟对象,做门禁判断 | |
throughput 明显低于 rate | 客户端 worker 不足或服务端处理不过来,先排查再采信延迟 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
vegeta plot results.bin > plot.html | 生成交互式 HTML 图表,直接发给同事 | |
vegeta plot -title="api-v1 100rps" results.bin > plot.html | 给图表加标题,便于归档区分 | |
vegeta plot -threshold=500ms results.bin > plot.html | 以延迟阈值着色,快速看超线比例 | |
vegeta plot -downsampling-threshold=1000 results.bin > plot.html | 点数过多时先降采样,避免浏览器卡死 | |
vegeta encode results.bin > results.json | 二进制结果转 JSON,默认 to=json | |
vegeta encode -to csv results.bin > results.csv | 转 CSV,方便 Excel 或 BI 分析 | |
vegeta encode -to gob results.bin > results.gob | 转 gob,便于 Go 程序直接解码 | |
vegeta encode results.json -to bin > results.bin | 反向转换,把文本结果还原为二进制 | |
vegeta plot <(vegeta encode results.bin) | 管道方式喂 JSON 数据作图 | |
报告产物与原始 bin 一起归档 | 原始数据能重新出图,比只存截图更有价值 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
vegeta attack -targets=t.txt -rate=100 -duration=30s -output=results.bin | 标准做法:结果落盘再分析,避免管道丢失 | |
vegeta report -type=json results.bin > report.json | JSON 报告落盘,随构建产物归档 | |
jq -e ".success > 0.99" report.json | 成功率门禁,不满足时 jq 返回非零 | |
jq -e ".latency.p99 < 500" report.json | P99 延迟门禁(单位纳秒,注意换算) | |
jq ".latency.p99 / 1000000" report.json | 纳秒转毫秒,避免误判数量级 | |
jq -e ".throughput > 95" report.json | 吞吐下限门禁,防止压不出量也算通过 | |
grep -E "Success|Latency" report.txt | 文本报告里快速提取关键行 | |
vegeta attack ... | tee results.bin | vegeta report > report.txt | 一次运行同时保留数据与报告 | |
set -o pipefail | 管道中任一段失败即整体失败,CI 里必加 | |
把 rate、成功率、P99 写入构建摘要 | 每次构建都能看到性能趋势 | |
基线结果纳入版本库或对象存储 | 便于回归对比与历史追溯 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
for r in 50 100 200 400; do vegeta attack -targets=t.txt -rate=$r -duration=30s -output=r$r.bin; done | 速率阶梯,逐级观察成功率与延迟拐点 | |
vegeta report -every=5s results.bin | 长时压测中观察指标漂移,识别资源泄漏 | |
低速率起步预热 | 避开连接建立、缓存冷启动与 JIT 干扰 | |
达成率优先于延迟 | throughput 明显低于 rate 时,延迟数字已失真 | |
固定变量再对比 | 版本、规格、缓存状态、网络路径都要记录 | |
随机参数绕过缓存 | 目标文件里写多个 URL 轮询,减少缓存命中 | |
同时观察服务端 CPU 与连接数 | 只看报告容易把客户端瓶颈当成服务端问题 | |
多目标轮询更接近真实 | 混合读写接口的比例要贴近线上流量模型 | |
生产环境默认不压测 | 必须压测时走审批、限流与回滚预案 | |
结论要可复现 | 同参数重跑一次,指标偏差应在可接受范围 |
| 命令 / 片段 | 说明 | 复制 |
|---|---|---|
vegeta: command not found | 未安装或 $GOPATH/bin 不在 PATH | |
bad target: ... | 目标文件格式错误,检查方法、空格与 URL scheme | |
no targets provided | 既没给 -targets 也没从 stdin 输入 | |
unknown flag: -xxx | 参数名写错或当前版本不支持 | |
x509: certificate signed by unknown authority | 自签证书加 -insecure 或指定 -root-certs | |
dial tcp 10.0.0.5:443: connect: connection refused | 端口未监听或被防火墙拦截 | |
context deadline exceeded | 请求超时,调大 -timeout 并排查慢接口 | |
unexpected EOF | results.bin 不完整,压测被中断或管道提前关闭 | |
rate: parse error | 速率写法有误,正确格式为 100 或 100/1s | |
attack 卡住无输出 | 从 stdin 读目标但没喂数据,补 echo 或 -targets | |
Success 随 rate 上升快速下降 | 已过载,降低速率重新找拐点 | |
Errors 中大量 timeout | 连接数或 worker 不足,也可能是服务端排队 | |
Status Codes 集中 429 | 触发限流,需与业务确认限流阈值后再压 | |
plot 生成空白图 | 数据点太少或时长为 0,延长 -duration 重跑 | |
report 数值单位混乱 | JSON 里延迟是纳秒,展示前记得除以 1e6 | |
压测机 CPU 100% | 客户端瓶颈,减少 worker、用 GOMAXPROCS 限制或多机分散 | |
结果与网关统计不一致 | 中间有 CDN、限流或采样,核对口径与时间窗 |
运维常用组合
echo -n "GET http://example.com/" | vegeta attack -rate=5 -duration=5s | vegeta reportvegeta attack -targets=t.txt -rate=100 -duration=30s -output=results.bin → vegeta report results.bin → vegeta plot results.bin > plot.htmlfor r in 50 100 200 400 800; do vegeta attack -targets=t.txt -rate=$r -duration=30s -output=r$r.bin; vegeta report r$r.bin | grep -E "Requests|Success|99"; donevegeta attack -targets=t.txt -rate=100 -duration=30s -output=r.bin → report -type=json > report.json → jq -e ".success > 0.99 and (.latency.p99/1000000) < 500" report.jsonvegeta attack -targets=https.txt -rate=100 -duration=30s -insecure -http2 -output=r.bin → report → plot默认跑一轮 → 加 -keepalive=false 再跑一轮 → 对比 Latency mean 与 throughput,量化握手开销实战要点
1. 恒定速率即开环
vegeta 按 -rate 匀速发压,不受响应快慢影响,延迟统计更接近真实
2. 先看 throughput
实际吞吐远低于目标 rate 时,延迟与成功率都不能作为容量结论
3. workers 按延迟估
workers ≈ rate × 目标延迟(秒),估小了会被客户端卡住
4. 结果先落盘再分析
用 -output 存 bin,失败中断也能保留已有数据并反复出报告
5. JSON 延迟是纳秒
门禁脚本里务必换算成毫秒,否则判断会差三个数量级
6. 目标文件纳入版本管理
压测目标和参数同样需要评审与追溯,避免"随手一压"
相关工具
Linux命令速查
文件、文本、权限、进程、网络、磁盘、systemd与防火墙等 Linux 常用命令速查手册
Docker命令速查
镜像、容器、网络、数据卷、Compose、Swarm、清理与排障等 Docker 常用命令速查手册
Nginx命令速查
服务管理、配置指令、反向代理、HTTPS、限流缓存、日志排查等 Nginx 常用命令速查手册
K8S命令速查
集群上下文、Pod调试、工作负载、Service与Ingress、存储、权限、排障等 kubectl 常用命令速查手册
Windows CMD命令速查
文件目录、网络诊断、进程服务、系统信息、用户权限、注册表、批处理等 Windows CMD 常用命令速查手册
systemctl服务管理速查
服务启停、开机自启、unit文件编写、日志查看、定时器、依赖分析与排障等 systemctl 命令速查手册
关于vegeta命令速查
在线 vegeta 命令速查手册,按安装与版本、目标文件与请求构造、attack 基础用法、速率与并发控制、协议 TLS 与网络选项、report 结果解读、plot 与 encode、输出采集与 CI 集成、压测方法与容量评估、常见报错与排查等 10 类场景整理 120 条常用命令与参数组合,每条附中文说明与可直接复制的写法,支持关键词搜索、分类折叠和一键复制,打开网页即可查阅。涵盖 go install github.com/tsenart/vegeta/v12@latest 与 brew/dnf/docker 安装、vegeta -version、targets 文件格式(METHOD URL、请求头、@body 文件、空行分隔多个目标)、attack 的 -targets 与 -rate 与 -duration 与 -output 与 -name 与 -workers 与 -max-workers 与 -connections 与 -timeout 与 -lazy 与 -keepalive 与 -redirects 与 -max-body 与 -header 与 -body 与 -cert/-key/-root-certs 与 -insecure 与 -http2/-format=http/2/-h2c 与 -resolvers 与 -laddr 与 -unix-socket、速率写法 50、100/1s、10/500ms 与 rate=0 懒模式、report 的 -type=text|json|hist[0,100ms,10ms] 与 -every 1s 流式输出与 Latency 的 mean/50/90/95/99/max 与 Success 与 Status Codes 与 Errors 与 Bytes In/Out 与 Throughput 逐项含义、plot 生成 HTML 图与 -threshold/-downsampling-threshold、encode 的 -to json|csv|gob 格式转换,以及 grep/jq 提取成功率达到 CI 门禁、结果文件归档与基线对比,还有 command not found、bad target、no targets provided、unknown flag、x509 certificate signed by unknown authority(-insecure)、connection refused、context deadline exceeded、unexpected EOF(结果文件不完整)、rate 解析失败、stdin 无数据挂起、高 rate 下 Success 下降等报错排查。适用于恒定到达率接口压测、SLA 与容量验证、压测结果可视化与回归对比、CI 性能门禁、HTTPS 与 HTTP/2 场景测试,以及运维、测试与后端工程师面试复习。
核心能力
- 涵盖 go install github.com/tsenart/vegeta/v12@latest 与 brew/dnf/docker 安装、vegeta -version、targets 文件格式(METHOD URL、请求头、@body 文件、空行分隔多个目标)、attack 的 -targets 与 -rate 与 -duration 与 -output 与 -name 与 -workers 与 -max-workers 与 -connections 与 -timeout 与 -lazy 与 -keepalive 与 -redirects 与 -max-body 与 -header 与 -body 与 -cert/-key/-root-certs 与 -insecure 与 -http2/-format=http/2/-h2c 与 -resolvers 与 -laddr 与 -unix-socket、速率写法 50、100/1s、10/500ms 与 rate=0 懒模式、report 的 -type=text|json|hist[0,100ms,10ms] 与 -every 1s 流式输出与 Latency 的 mean/50/90/95/99/max 与 Success 与 Status Codes 与 Errors 与 Bytes In/Out 与 Throughput 逐项含义、plot 生成 HTML 图与 -threshold/-downsampling-threshold、encode 的 -to json|csv|gob 格式转换,以及 grep/jq 提取成功率达到 CI 门禁、结果文件归档与基线对比,还有 command not found、bad target、no targets provided、unknown flag、x509 certificate signed by unknown authority(-insecure)、connection refused、context deadline exceeded、unexpected EOF(结果文件不完整)、rate 解析失败、stdin 无数据挂起、高 rate 下 Success 下降等报错排查
适用场景
适用于恒定到达率接口压测、SLA 与容量验证、压测结果可视化与回归对比、CI 性能门禁、HTTPS 与 HTTP/2 场景测试,以及运维、测试与后端工程师面试复习。vegeta命令速查全程在浏览器中完成,无需安装插件,可放心用于日常办公与排障。
常见问题
- vegeta命令速查是免费的吗?需要注册或安装吗?
- vegeta命令速查完全免费,无需注册、无需下载安装任何软件,用浏览器打开网页即可直接使用,也不限制使用次数。
- vegeta命令速查支持哪些功能?
- 涵盖 go install github.com/tsenart/vegeta/v12@latest 与 brew/dnf/docker 安装、vegeta -version、targets 文件格式(METHOD URL、请求头、@body 文件、空行分隔多个目标)、attack 的 -targets 与 -rate 与 -duration 与 -output 与 -name 与 -workers 与 -max-workers 与 -connections 与 -timeout 与 -lazy 与 -keepalive 与 -redirects 与 -max-body 与 -header 与 -body 与 -cert/-key/-root-certs 与 -insecure 与 -http2/-format=http/2/-h2c 与 -resolvers 与 -laddr 与 -unix-socket、速率写法 50、100/1s、10/500ms 与 rate=0 懒模式、report 的 -type=text|json|hist[0,100ms,10ms] 与 -every 1s 流式输出与 Latency 的 mean/50/90/95/99/max 与 Success 与 Status Codes 与 Errors 与 Bytes In/Out 与 Throughput 逐项含义、plot 生成 HTML 图与 -threshold/-downsampling-threshold、encode 的 -to json|csv|gob 格式转换,以及 grep/jq 提取成功率达到 CI 门禁、结果文件归档与基线对比,还有 command not found、bad target、no targets provided、unknown flag、x509 certificate signed by unknown authority(-insecure)、connection refused、context deadline exceeded、unexpected EOF(结果文件不完整)、rate 解析失败、stdin 无数据挂起、高 rate 下 Success 下降等报错排查。
- vegeta命令速查适合哪些场景使用?
- 适用于恒定到达率接口压测、SLA 与容量验证、压测结果可视化与回归对比、CI 性能门禁、HTTPS 与 HTTP/2 场景测试,以及运维、测试与后端工程师面试复习。