【测试工具】01_wrk基本用法
开发环境
-
CentOS Linux release 7.6.1810 (Core) gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44) wrk 4.2.0 [epoll] Copyright (C) 2012 Will Glozer
安装步骤
yum install -y git git clone https://github.com/wg/wrk.git cd wrk make cp wrk /usr/local/bin
基本概念
笔者理解的wrk是一款适用于开发人员使用的性能测试工具,安装方便易于使用。 wrk具体参数信息,参看 wrk线程与连接数量用法,查看
使用案例
- GET请求案例 wrk -t8 -c200 -d30s --latency http://www.bing.com
Running 30s test @ http://www.bing.com (压测时间30s) 8 threads and 200 connections (共8个测试线程,200个连接) Thread Stats Avg Stdev Max +/- Stdev (平均值) (标准差)(最大值)(正负一个标准差所占比例) Latency 46.67ms 215.38ms 1.67s 95.59% (延迟) Req/Sec 7.91k 1.15k 10.26k 70.77% (处理中的请求数) Latency Distribution (延迟分布) 50% 2.93ms 75% 3.78ms 90% 4.73ms 99% 1.35s (99分位的延迟) 1790465 requests in 30.01s, 684.08MB read (30.01秒内共处理完成了1790465个请求,读取了684.08MB数据) Requests/sec: 59658.29 (平均每秒处理完成59658.29个请求) Transfer/sec: 22.79MB (平均每秒读取数据22.79MB)
- POST请求插入数据案例 wrk -t50 -c50 -d10s -s xx.lua --latency http://localhost:9095/deviceTypeInfo/create
wrk.method = "POST" wrk.headers["Content-Type"] = "application/json" wrk.headers["Accept"] = "application/json" wrk.headers["token"] = "e4c29ab78bffabab12d6e8e9b2ee73d6" local cnt = 0 cnt = cnt +1 function request() local body = {"deviceTypeName": "string%s","deviceTypeNameCn":"string%s"} body = string.format(body, cnt, cnt) return wrk.format(nil, nil, nil, body) end
- 发送POST请求查询数据案例 wrk -t1 -c1 -d30s -s xx.lua --latency http://localhost:9095/list
wrk.method = "POST" wrk.headers["Content-Type"] = "application/json" wrk.headers["Accept"] = "application/json" wrk.headers["token"] = "04a29fab3b5f55781fbdca56b90f9d88" wrk.headers["requestHeaderMap"] = "{"yyId":"cf3cf97889744922beec2c25c98132c8","xxId":"e83bd1e7d00c4b46b714403cf7dbc4b5","xxType":"10"}" function request() local body = {} body = string.format(body) return wrk.format(nil, nil, nil, body) end
引用
https://github.com/wg/wrk https://juejin.cn/post/6844904094054744072 https://www.cnblogs.com/liulinghua90/p/9257548.html https://k6.io/blog/comparing-best-open-source-load-testing-tools/
上一篇:
Python 安装包管理工具 pip
下一篇:
推荐5个很牛的开源项目