安装wrk
先从github上下载源码
git clone https://github.com/wg/wrk
然后cd到wrk目录,make安装
make
之后即可直接使用,并且再可执行目录下创建了软连接 /usr/local/bin/wrk -> /usr/local/src/wrk/wrk
wrk的基本使用
先看一下wrk的帮助
wrk --help
Usage: wrk <options> <url>
Options:
-c, --connections <N> Connections to keep open #跟服务器建立并保持TCP连接数量,设置压测并发连接数
-d, --duration <T> Duration of test ##压测时间
-t, --threads <N> Number of threads to use ##指定压测的线程数
-s, --script <S> Load Lua script file ##可指定Lua脚本进行http压测,待详细研究
-H, --header <H> Add header to request ##为每一个HTTP请求添加HTTP头,???怎么加呢
--latency Print latency statistics ##打印出延时分布的概率:Latency Distribution
50% 1.10ms
75% 2.23ms
90% 83.63ms
99% 482.18ms
--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)
<N>表示数值参数,支持国际单位(1k, 1M, 1G)
<T> 表示时间参数,支持时间单位(2s, 2m, 2h)
查看wrk版本,可发现wrk使用epoll机制
wrk -v
wrk 4.1.0 [epoll] Copyright (C) 2012 Will Glozer
压测一个内网HTTP服务
设置5个线程1000个连接测试,并在压测结果中输出响应延迟的信息
wrk -c1000 -t5 http://192.168.0.105:80 --latency --timeout 1s
Running 10s test @ http://192.168.0.105:80
5 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 26.28ms 84.56ms 839.47ms 91.76%
(延迟时间)
Req/Sec 7.52k 3.56k 30.09k 76.06%
(每秒处理的请求数)
Latency Distribution
50% 1.31ms (50%请求子啊1.31ms返回)
75% 2.63ms (75%请求子啊2.63ms返回)
90% 51.78ms (90%请求子啊51.78ms返回)
99% 407.39ms(99%请求子啊407.39ms返回)
369586 requests in 10.03s, 299.23MB read (10.03s内处理369586个请求,读取684.08MB数据)
Socket errors: connect 0, read 19, write 0, timeout 139(请求异常数量)
Requests/sec: 36858.65 (平均每秒处理完成请求数)
Transfer/sec: 29.84MB (平均每秒传输数据大小)
wrk通过简单的命令行可以压测简单的GET请求,但要压测PUT、POST等更复杂的http服务,还可通过Lua脚本定制压测过程,待实践后补充。