wrk
wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CPU. It combines a multithreaded design with scalable event notification systems such as epoll and kqueue.
wrk使用了epoll(linux)和kqueue(mac)
安装
基本使用 1.使用帮助:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 Usage : wrk <options> <url> Options : -c, --connections <N> Connections to keep open -d, --duration <T> Duration of test -t, --threads <N> Number of threads to use -s, --script <S> Load Lua script file -H, --header <H> Add header to request --latency Print latency statistics --timeout <T> Socket /request timeout -v, --version Print version details Numeric arguments may include a SI unit (1k, 1M, 1G) Time arguments may include a time unit (2s, 2m, 2h)
中文:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 使用方法: wrk <选项> <被测HTTP 服务的URL > Options : -c, --connections <N> 跟服务器建立并保持的TCP 连接数量 -d, --duration <T> 压测时间 -t, --threads <N> 使用多少个线程进行压测 -s, --script <S> 指定Lua 脚本路径 -H, --header <H> 为每一个HTTP 请求添加HTTP 头 --latency 在压测结束后,打印延迟统计信息 --timeout <T> 超时时间 -v, --version 打印正在使用的wrk的详细版本信息 <N>代表数字参数,支持国际单位 (1k, 1M, 1G) <T>代表时间参数,支持时间单位 (2s, 2m, 2h)
版本查看 1 2 3 brew info wrk wrk : stable 4.1 .0 (bottled), HEAD
压测 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 wrk -t12 -c400 -d30s --latency http : 输出: Running 30s test @ http : 12 threads and 400 connections(共12 个测试线程,400 个连接) Thread Stats Avg Stdev Max +/- Stdev (平均值) (标准差)(最大值)(正负一个标准差所占比例) Latency 933. 14ms 415. 00ms 2. 00s 77.56 % (延迟) Req /Sec 24.77 15.65 121.00 70.04 % (处理中的请求数) Latency Distribution (延迟分布) 50 % 711. 85ms 75 % 1. 24s 90 % 1. 56s 99 % 1. 90s (99 分位的延迟) 8181 requests in 30. 10s, 121. 83MB read(30.10 秒内共处理完成了8181 个请求,读取了121. 83MB数据) Socket errors : connect 0 , read 0 , write 0 , timeout 1545 Requests /sec : 271.82 (平均每秒处理完成271.82 个请求)Transfer /sec : 4. 05MB (平均每秒读取数据4. 05MB)
以上使用12个线程400个连接,对baidu首页进行了30秒的压测,并要求在压测结果中输出响应延迟信息。
Post 接口测试 首先需要准备一个lua文件
1 2 3 wrk.method = "POST" wrk.body = "foo=bar&baz=quux" wrk.headers ["Content-Type" ] = "application/x-www-form-urlencoded"
可参照github 上的示例
如测试:
1 2 3 4 5 wrk.method = "POST" wrk.body = '{"act":"v2/user/get","args":{"corp_id":"5c0f3633eb30ea2416a","auth":"WNwI1DePAf7ANU2hfDsOxUA4CsHxGee8J1hz0b0GdVpGhB/jrleUO1EqB76w+QMMFzMgV1ma1tycQx"}}' wrk -t4 -c2000 -d60s -T5s --script=post.lua --latency http :
这样就是模拟4个线程,2000个连接,在60s内,间隔5s 执行 post.lua 的请求
本文引自这里