目录

wrk系列教程(2)简单使用

简单起见,建议大家可以先安装python。

在本机启动被测服务

创建一个index.html文件

echo '<h3>It works</h3>' > index.html

index.html里面文件内容很简单,一句话

<h3>It works</h3>'

使用下面命令启动web服务。

python -m SimpleHTTPServer #python2

python -m http.server #python3

预期结果应该是下面这个样子

Serving HTTP on 0.0.0.0 port 8000 ...

验证web服务

新开1个terminal窗口,使用下面命令

curl localhost:8000/index.html

这时候命令行应该显示正确的返回

<h3>It works</h3>

开始压测

使用命令 wrk -c200 -t10 -d30s http://127.0.0.1:8000/index.html

解释一下主要参数

  • c: connections 表示一共起多少个链接
  • t: 表示用多少个

结果展示

在我的机器上结果是这个样子的

Running 30s test @ http://127.0.0.1:8000/index.html
  10 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     3.24ms    6.54ms 154.00ms   95.36%
    Req/Sec   167.54    227.05     1.81k    84.83%
  16145 requests in 30.08s, 3.13MB read
  Socket errors: connect 0, read 1208, write 31, timeout 0
Requests/sec:    536.78
Transfer/sec:    106.41KB

对我们来说最重要的1个数据就是倒数第二行的Requests/sec: 536.78。这说明我们测出的服务的QPS是536。

原始封面

https://images.unsplash.com/photo-1487214626629-b7eaa70441b2?w=300