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