hey是一款使用Golang开发的HTTP压力测试工具,可作为ApacheBench (ab)替代品。
安装hey
以下使用Linux 64位系统,如果您是其它操作系统,请自行前往hey项目地址下载对应客户端。
作者已经提供编译好的二进制包,可直接下载使用。
#下载hey wget https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64 #如果下载速度较慢,可使用xiaoz软件库链接 wget http://soft.xiaoz.org/linux/hey_linux_amd64 #赋予执行权限 chmod +x hey_linux_amd64 #移动文件到sbin目录 mv hey_linux_amd64 /usr/sbin/hey

如果是其它操作系统,请对号入座:
- Linux 64-bit: https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64
- Mac 64-bit: https://hey-release.s3.us-east-2.amazonaws.com/hey_darwin_amd64
- Windows 64-bit: https://hey-release.s3.us-east-2.amazonaws.com/hey_windows_amd64
hey的使用
以指定的访问速率(QPS为10)来访问指定的地址,
hey -z 1m -c 2 -q 5 https://www.baidu.com/
指定时长的get请求:客户端(-c)并发为2, 持续发送请求2s (-c) hey -z 5s -c 2 https://www.baidu.com/ 指定请求总数的get请求:运行2000次(-n),客户端并发为50(-c) hey -n 2000 -c 50 https://www.baidu.com/ 指定host的get请求:使用的cpu核数为2 (-cpus), 压测时长为5s(-z), 并发数为2 hey -z 5s -c 2 -cpus 2 -host "baidu.com" https://220.181.38.148 请求带header的get接口:压测时长为5s (-z), 客户端发送请求的速度为128 QPS, 请求头用-H添加 hey -z 5s -q 128 -H "client-ip:0.0.0.0" -H "X-Up-Calling-Line-Id:X.L.Xia" https://www.baidu.com/ 请求post请求 hey -z 5s -c 50 -m POST -H "info:firstname=xiuli; familyname=xia" -d "year=2020month=1day=21" https://www.baidu.com/ 代理模式,需额外配置proxy:因部分ip频繁发请求有风险,故可用-x设置白名单代理向服务器发请求 hey -z 5s -c 10 -x "http://127.0.0.1:8001" http://baidu.com/ shell for循环实现压测 for i in `seq 10`; do curl -v http://baidu.com; done