一、Hey介绍
这是个简单的命令行工具,向Web应用程序发送一些负载,同时返回统计结果项目地址:二、性能测试
性能测试是通过自动化的测试工具模拟多种正常、峰值以及异常负载条件来对系统的各项性能指标进行测试。负载测试和压力测试都属于性能测试,两者可以结合进行。1、通过负载测试,确定在各种工作负载下系统的性能,目标是测试当负载逐渐增加时,系统各项性能指标的变化情况 2、压力测试是通过确定一个系统的瓶颈或者不能接受的性能点,来获得系统能提供的最大服务级别的测试。三、下载Linux 64位二进制文件(举例)
优点:不用配置go环境,下载下来直接上传到环境上,修改文件权限就可以使用了1、打开步骤一链接,选择linux64位
Linux 64位:Mac 64位:Windows 64位:2、打开步骤一链接,选择linux安装包
修改文件权限:chmod777hey_linux_amd64
使用方法,下文的举例命令hey替换成./hey_linux_amd64执行即可
五、【举例并发50,1000个请求】,请求结果返回,可用于性能测试结果分析
#并发50,1000个请求访问网址
[root@localhost tools]# ./hey_linux_amd64 -n 1000 -c 50 http://www.baidu.com/
Summary:
Total: 2.0508secs
Slowest: 1.1289secs
Fastest: 0.0132secs
Average: 0.1005secs
Requests/sec: 487.6142
Totaldata:227000bytes
Size/request: 227 bytes
Responsetime histogram:
0.013 [1] |
0.125 [910] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.236 [30] |■
0.348 [1] |
0.459 [8] |
0.571 [0] |
0.683 [0] |
0.794 [5] |
0.906 [4] |
1.017 [0] |
1.129 [41] |■■
Latencydistribution:
10%in0.0215 secs
25%in0.0279 secs
50%in0.0394 secs
75%in0.0655 secs
90%in0.1226 secs
95%in0.7304 secs
99%in1.0857 secs
Details(average, fastest, slowest):
DNS+dialup: 0.0246secs, 0.0132secs, 1.1289secs
DNS-lookup: 0.0051secs, 0.0000secs, 0.3947secs
reqwrite: 0.0000secs, 0.0000secs, 0.0012secs
respwait: 0.0631secs, 0.0129secs, 0.4412secs
respread: 0.0001secs, 0.0000secs, 0.0010secs
Statuscode distribution:
[200]1000responses
翻译如下:
[root@localhosttools]
简介:
总:2.0508秒
最低:1.1289秒
最快:0.0132秒
平均:0.1005秒
请求/秒:487.6142
总数据:227000字节
尺寸/要求:227字节
响应时间柱状图:
0.013 [1] |
0.125[910] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.236[30] |■
0.348 [1] |
0.459 [8] |
0.571 [0] |
0.683 [0] |
0.794 [5] |
0.906 [4] |
1.017 [0] |
1.129[41] |■■
延迟分配:
0.0215秒的10%
0.0279秒25%
50%在0.0394秒内
75%在0.0655秒
90%在0.1226秒
95%在0。7304秒
99%在1.0857秒
详细信息(平均,最快,最慢):
DNS+拨号:0.0246秒,0.0132秒,1.1289秒
查找时间:0.0051秒、0.0000秒、0.3947秒
要求写入:0.0000秒,0.0000秒,0.0012秒
resp等待:0.0631秒,0.0129秒,0.4412秒
resp读数:0.0001秒,0.0000秒,0.0010秒
状态码地理分布:
[200]1000响应
六、用法
Usage: hey [options...]
Options:
# -n 指定运行的总请求数。默认值为200。
-n Numberofrequests to run. Defaultis200.
# -c 客户端并发执行的请求数,默认为50。总请求数不能小于并发数。
-cNumberofworkers to run concurrently. Total numberofrequests cannot
be smaller than the concurrency level. Defaultis50.
# -q 客户端发送请求的速度限制,以每秒响应数QPS为单位,默认没有限制。
-q Rate limit,inqueries per second (QPS) per worker. Defaultisnorate limit.
# -z 发送请求的持续时长,超时后程序停止并退出。若指定了持续时间,则忽略总请求数(-n),例如-z 10s,-z 3m
-z Durationofapplication to send requests. When durationisreached,
application stopsandexits. If durationisspecified, nisignored.
Examples: -z 10s -z 3m.
# -o 输出类型。若没有提供,则打印摘要。CSV是唯一支持的格式,结果以逗号分隔各个指标项。
-o Output type. If none provided, a summaryisprinted.
"csv"isthe only supported alternative. Dumps the response
metrics in comma-separatedvaluesformat.
# -m 是HTTP方法,例GET,POST,PUT,DELETE,HEAD,OPTIONS方法
-m HTTP method, one of GET, POST, PUT,DELETE,HEAD, OPTIONS.
# -H 代表HTTP请求头,可以用-H连续添加多个请求头。
-H Custom HTTP header. You can specifyasmanyasneeded by repeating the flag.
Forexample, -H"Accept: text/html"-H"Content-Type: application/xml".
# -t 每个请求的超时时间(以秒为单位)。默认值为20s,数值0代表永不超时。
-t Timeoutforeach requestinseconds. Defaultis20, use0forinfinite.
# -A 代表HTTP响应头
-A HTTP Accept header.
# -d代表HTTP请求正文
-d HTTP request body.
# -D代表HTTP请求正文文件
-D HTTP request bodyfromfile. For example,/home/user/file.txt or ./file.txt.
# -T内容类型,默认为“ text / html”。
-T Content-type, defaults to"text/html".
# -a代表基本身份验证,用户名:密码。
-a Basic authentication, username:password.
#-x代表HTTP代理地址作, 使用host:port格式。
-x HTTPProxyaddressashost:port.
# -h2启用HTTP / 2
-h2 Enable HTTP/2.
# -host http主机头
-host HTTP Host header.
# -disable-compression 禁用压缩。
-disable-compression Disable compression.
# -disable-keepalive禁用保持活动状态,防止重新使用不同的HTTP请求之间的TCP连接。
-disable-keepalive Disable keep-alive, prevents re-useofTCP
connectionsbetween different HTTP requests.
# -disable-redirects 禁用HTTP重定向
-disable-redirects Disable followingofHTTP redirects
# -cpus 使用的cpu内核数。当前计算机的默认值为8核。
-cpusNumberofused cpu cores.
(defaultforcurrent machineis8cores)
四、使用示例参考
指定时长的get请求:客户端(-c)并发为2, 持续发送请求2s (-c)
hey -z5s -c2http://www.baidu.com/
指定请求总数的get请求:运行2000次(-n),客户端并发为50(-c)
hey -n2000-c50http://www.baidu.com/
指定host的get请求:使用的cpu核数为2(-cpus), 压测时长为5s(-z), 并发数为2
hey -z5s -c2-cpus2-host"baidu.com"http://220.181.38.148
请求带header的get接口:压测时长为5s (-z), 客户端发送请求的速度为128QPS, 请求头用-H添加
hey -z5s -q128-H"client-ip:0.0.0.0"-H"X-Up-Calling-Line-Id:X.L.Xia"http://www.baidu.com/
post请求
hey -z 5s -c 50 -m POST -H"info:firstname=xiuli; familyname=xia"-d"year=2020&month=1&day=21"http://www.baidu.com/
代理模式,需额外配置proxy:因部分ip频繁发请求有风险,故可用-x设置白名单代理向服务器发请求
hey -z5s -c10-x"http://127.0.0.1:8001"http://baidu.com/
shellfor循环实现压测
foriin`seq 10`;docurl -v http://baidu.com; done
侠梦的开发笔记记录开发历程,分享工具资源。长路漫漫,未来可期,愿不忘初心,砥砺前行。
56篇原创内容
Official Account
回复【干货】获取精选干货视频教程 |