wrk介绍
wrk是一款现代化的HTTP性能测试工具,即使运行在单核CPU上也能产生显著的压力。它融合了一种多线程设计,并使用了一些可扩展事件通知机制,例如epoll and kqueue。一个可选的LuaJIT脚本能产生HTTP请求,响应处理和自定义报告,更详细的脚本内容可以参考scripts目录下的一些例子。
wrk下载和安装
-
先安装git
sudo apt install git -y
-
下载wrk文件
git clone https://github.com/wg/wrk.git cd wrk make
-
编译成功后,会生成wrk文件,如果编译过程中出现gcc:command not found 或者openssl报错,则需要安装相应库
sudo apt-get install gcc sudo apt-get install libssl-dev sudo apt-get install openssl-devel
简单例子
```bash
./wrk -t12 -c400 -d30s http://127.0.0.1:8080/index.html
```
> 它将会产生如下测试,12个线程(threads),保持400个HTTP连接(connections)开启,测试时间30秒(seconds)。
-
详细的命令行参数如下:
-c, --connections(连接数): total number of HTTP connections to keep open with each thread handling N = connections/threads -d, --duration(测试持续时间): duration of the test, e.g. 2s, 2m, 2h -t, --threads(线程): total number of threads to use -s, --script(脚本): LuaJIT script, see SCRIPTING -H, --header(头信息): HTTP header to add to request, e.g. "User-Agent: wrk" --latency(响应信息): print detailed latency statistics --timeout(超时时间): record a timeout if a response is not received within this amount of time.
-
下面是输出结果
Running 30s test @ http://127.0.0.1:8080/index.html 12 threads and 400 connections Thread Stats Avg Stdev Max +/- Stdev Latency 635.91us 0.89ms 12.92ms 93.69% Req/Sec 56.20k 8.07k 62.00k 86.54% 22464657 requests in 30.00s, 17.76GB read Requests/sec: 748868.53 Transfer/sec: 606.33MB
Latency: 响应信息, 包括平均值, 标准偏差, 最大值, 正负一个标准差占比。
Req/Sec: 每个线程每秒钟的完成的请求数,同样有平均值,标准偏差,最大值,正负一个标准差占比。
30秒钟总共完成请求数为22464657,读取数据量为17.76GB。
线程总共平均每秒钟处理748868.53个请求(QPS),每秒钟读取606.33MB数据量。