wrk 安装使用

==================== 安装 ====================
https://github.com/wg/wrk/wiki

sudo yum -y groupinstall 'Development Tools'
sudo yum install -y openssl-devel git
git clone https://github.com/wg/wrk.git wrk
cd wrk
make
sudo cp wrk /usr/bin

==================== 使用 ====================

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 -t4 -d100s http://localhost:9981/api/test

test.lua

wrk.method="POST"

wrk.body=[[ {"jsonKey": "jsonValue"} ]]

wrk.headers["Content-Type"]="application/json; charset=utf-8"

wrk -c100 -t4 -d100s -stest.lua --latency http://localhost:9981/api/test

==================== 测试结果 ====================

Running 10s test @ http://localhost:9981/api/test
  4 threads and 1000 connections                    // 线程数设置为cpu核心数或其2倍,设置不同的连接数以观察吞吐量及响应时间情况
  Thread Stats   Avg      Stdev     Max   +/- Stdev // 每条线程的状态
    Latency    70.08ms    8.76ms 127.28ms   81.70%  // 完成一个请求所需要的响应时间
    Req/Sec     3.55k   581.40     4.91k    68.50%  // 每秒完成的请求数
  Latency Distribution
     50%   68.65ms
     75%   72.67ms
     90%   80.40ms
     99%   99.73ms                                  // 99%的请求完成一个请求所需要的响应时间
  141270 requests in 10.05s, 265.27MB read          // 规定时间内总请求数及传送数据量
Requests/sec:  14053.75                             // 每秒总共可以完成的请求数
Transfer/sec:     26.39MB                           // 每秒总共传送数据量

 

wrk -c100 -t4 -d100s -stest.lua --latency http://localhost:9981/api/test

posted @ 2018-09-14 11:50  多彩泰坦  阅读(1391)  评论(0编辑  收藏  举报