点击蓝字关注这个神奇的公众号~
一、Hey介绍
这是个简单的命令行工具,向Web应用程序发送一些负载,同时返回统计结果
项目地址:
二、性能测试
性能测试是通过自动化的测试工具模拟多种正常、峰值以及异常负载条件来对系统的各项性能指标进行测试。
负载测试和压力测试都属于性能测试,两者可以结合进行。
1、通过负载测试,确定在各种工作负载下系统的性能,目标是测试当负载逐渐增加时,系统各项性能指标的变化情况 2、压力测试是通过确定一个系统的瓶颈或者不能接受的性能点,来获得系统能提供的最大服务级别的测试。
三、下载Linux 64位二进制文件(举例)
优点:不用配置go环境,下载下来直接上传到环境上,修改文件权限就可以使用了
1、打开步骤一链接,选择linux64位
Linux 64位:Mac 64位:Windows 64位:
2、打开步骤一链接,选择linux安装包
修改文件权限:
chmod 777 hey_linux_amd64
使用方法,下文的举例命令hey替换成./hey_linux_amd64执行即可
五、【举例并发50,1000个请求】,请求结果返回,可用于性能测试结果分析
#并发50,1000个请求访问网址 [root@localhost tools]# ./hey_linux_amd64 -n 1000 -c 50 https://www.baidu.com/ Summary: Total: 2.0508 secs Slowest: 1.1289 secs Fastest: 0.0132 secs Average: 0.1005 secs Requests/sec: 487.6142 Total data: 227000 bytes Size/request: 227 bytes Response time 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] |■■ Latency distribution: 10% in 0.0215 secs 25% in 0.0279 secs 50% in 0.0394 secs 75% in 0.0655 secs 90% in 0.1226 secs 95% in 0.7304 secs 99% in 1.0857 secs Details (average, fastest, slowest): DNS+dialup: 0.0246 secs, 0.0132 secs, 1.1289 secs DNS-lookup: 0.0051 secs, 0.0000 secs, 0.3947 secs req write: 0.0000 secs, 0.0000 secs, 0.0012 secs resp wait: 0.0631 secs, 0.0129 secs, 0.4412 secs resp read: 0.0001 secs, 0.0000 secs, 0.0010 secs Status code distribution: [200] 1000 responses
翻译如下:
[root@localhosttools]# ./hey_linux_amd64 -n 1000 -c 50 https://www.baidu.com/ 简介: 总: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...] <url> Options: # -n 指定运行的总请求数。默认值为200。 -n Number of requests to run. Default is 200. # -c 客户端并发执行的请求数,默认为50。总请求数不能小于并发数。 -c Number of workers to run concurrently. Total number of requests cannot be smaller than the concurrency level. Default is 50. # -q 客户端发送请求的速度限制,以每秒响应数QPS为单位,默认没有限制。 -q Rate limit, in queries per second (QPS) per worker. Default is no rate limit. # -z 发送请求的持续时长,超时后程序停止并退出。若指定了持续时间,则忽略总请求数(-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. # -o 输出类型。若没有提供,则打印摘要。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. # -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 specify as many as needed by repeating the flag. For example, -H "Accept: text/html" -H "Content-Type: application/xml" . # -t 每个请求的超时时间(以秒为单位)。默认值为20s,数值0代表永不超时。 -t Timeout for each request in seconds. Default is 20, use 0 for infinite. # -A 代表HTTP响应头 -A HTTP Accept header. # -d代表HTTP请求正文 -d HTTP request body. # -D代表HTTP请求正文文件 -D HTTP request body from file. 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 HTTP Proxy address as host: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-use of TCP connections between different HTTP requests. # -disable-redirects 禁用HTTP重定向 -disable-redirects Disable following of HTTP redirects # -cpus 使用的cpu内核数。当前计算机的默认值为8核。 -cpus Number of used cpu cores. (default for current machine is 8 cores)
四、使用示例参考
指定时长的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), 客户端发送请求的速度为128QPS, 请求头用-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
回复【干货】获取精选干货视频教程
回复【加群】加入疑难问题攻坚交流群
回复【mat】获取内存溢出问题分析详细文档教程
回复【赚钱】获取用java写一个能赚钱的微信机器人
回复【副业】获取程序员副业攻略一份
点个“在看”表示朕
已阅