轻量级压测工具hey
项目Hub地址
二进制安装
Linux 64-bit: https://storage.googleapis.com/hey-release/hey_linux_amd64 Mac 64-bit: https://storage.googleapis.com/hey-release/hey_darwin_amd64 Windows 64-bit: https://storage.googleapis.com/hey-release/hey_windows_amd64
源码安装
需要提交安装GO语言环境https://www.runoob.com/go/go-environment.html
git clone https://github.com/rakyll/hey.git go get -u github.com/rakyll/hey go install github.com/rakyll/hey go build
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=2020&month=1&day=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
Hey结果解析
使用方法
Usage: hey [options...] <url> Options: // 指定运行的总请求数。默认值为200。 -n Number of requests to run. Default is 200. // 客户端并发执行的请求数,默认为50。总请求数不能小于并发数。 -c Number of workers to run concurrently. Total number of requests cannot be smaller than the concurrency level. Default is 50. // 客户端发送请求的速度限制,以每秒响应数QPS为单位,默认没有限制。 -q Rate limit, in queries per second (QPS) per worker. Default is no rate limit. // 发送请求的持续时长,超时后程序停止并退出。若指定了持续时间,则忽略总请求数(-n),例如-z 10s,-z 3m -z Duration of application to send requests. When duration is reached, application stops and exits. If duration is specified, n is ignored. Examples: -z 10s -z 3m. // 输出类型。若没有提供,则打印摘要。CSV是唯一支持的格式,结果以逗号分隔各个指标项。 -o Output type. If none provided, a summary is printed. "csv" is the only supported alternative. Dumps the response metrics in comma-separated values format. // HTTP方法,例如GET,POST,PUT,DELETE,HEAD,OPTIONS方法 -m HTTP method, one of GET, POST, PUT, DELETE, HEAD, OPTIONS. // HTTP请求头,可以用-H连续添加多个请求头。 -H Custom HTTP header. You can specify as many as needed by repeating the flag. For example, -H "Accept: text/html" -H "Content-Type: application/xml" . // 每个请求的超时时间(以秒为单位)。默认值为20s,数值0代表永不超时。 -t Timeout for each request in seconds. Default is 20, use 0 for infinite. // HTTP响应头 -A HTTP Accept header. // HTTP请求正文 -d HTTP request body. // HTTP请求正文文件 -D HTTP request body from file. For example, /home/user/file.txt or ./file.txt. // 内容类型,默认为“ text / html”。 -T Content-type, defaults to "text/html". // 基本身份验证,用户名:密码。 -a Basic authentication, username:password. // HTTP代理地址作, 使用host:port格式。 -x HTTP Proxy address as host:port. // 启用HTTP / 2 -h2 Enable HTTP/2. // HTTP主机头 -host HTTP Host header. // 禁用压缩。 -disable-compression Disable compression. // 禁用保持活动状态,防止重新使用不同的HTTP请求之间的TCP连接。 -disable-keepalive Disable keep-alive, prevents re-use of TCP connections between different HTTP requests. // 禁用HTTP重定向 -disable-redirects Disable following of HTTP redirects // 使用的cpu内核数。当前计算机的默认值为8核。 -cpus Number of used cpu cores. (default for current machine is 8 cores)