天天看点

http性能测试工具wrk

wrk能用很少的线程压出很大的并发量,原因它使用了一些操作系统特定的高性能I/O机制, 比如select, epoll, kqueue等。 其实它是复用redis的ae异步事件驱动框架。确切的说 ae 事件驱动框架并不是 redis 发明的,它来至于Tcl的解释器 jim,这个小巧高效的框架,因为被 redis 采用而更多的被大家所熟知。

wrk GitHub 源码: https://github.com/wg/wrk

wrk只能运行于 Unix 类的系统上,linux下安装

git clone https://github.com/wg/wrk
cd wrk-master
make
           

参数说明:

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)
           

测试:

wrk -c100 -t30 -d30s http://www.baidu.com
30个线程,100个连接,执行30s,超时时间默认1s
           

返回:

Running 30s test @ http://www.baidu.com
  30 threads and 100 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    19.41ms   49.76ms   1.57s    95.20%
    Req/Sec   206.96     62.96   380.00     62.71%
  48899 requests in 30.05s, 726.27MB read
  Socket errors: connect 0, read 375176, write 0, timeout 0
Requests/sec:   1627.38
Transfer/sec:     24.17MB

           

其中:

说明
Latency 延迟时间
Req/Sec 单个线程每秒完成的请求数
avg stdev max 平均值 标准差 最大值
48899 requests in 30.05s, 726.27MB read 30秒内共有48899 个请求,总共读取726.27MB数据
Socket errors: connect 0, read 375176, write 0, timeout 0 共0个连接错误,375176个读错误,0个写错误,0个超时
Requests/sec 所有线程平均每秒完成请求数
Transfer/sec 所有线程平均每秒读取数据量

除此之外,还可以操作lua脚本,丰富的设置header信息等。

继续阅读