http压测工具wrk

安装

wrk支持大多数类UNIX系统,不支持windows。需要操作系统支持LuaJIT和OpenSSL,不过不用担心,大多数类Unix系统都支持。安装wrk非常简单,只要从github上下载wrk源码,在项目路径下执行make命令即可。

  git clone https://github.com/wg/wrk

  cd 安装目录

  make

make之后,会在项目路径下生成可执行文件wrk,随后就可以用其进行HTTP压测了。可以把这个可执行文件拷贝到某个已在path中的路径,比如/usr/local/bin,这样就可以在任何路径直接使用wrk了。

基本使用

1.命令行敲下wrk,可以看到使用帮助

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 <选项> <被测试的 http  url>                            
  Options:                                            
    -c, --connections <N>跟服务器建立并保持TCP连接数据
    -d, --duration    <T>压测时间     
    -t, --threads     <N>使用多多少个线程进行压测                                                     
    -s, --script      <S>指定Lua脚本路径
    -H, --header      <H>为每一个HTTP请求添加HTTP头
        --latency    在压测结束后,打印延迟统计信息
        --timeout     <T>超时时间
    -v, --version    打印正在使用的wrk的详细版本信息

<N>代表数字参数,支持国际单位(1k, 1M, 1G

<T>代表时间参数,支持时间单位(2s, 2m, 2h)

2.查看版本

  wrk -v
  输出:
  wrk 4.1.0 [epoll] Copyright (C) 2012 Will Glozer

3.简单实例

  wrk -t8 -c200 -d30s --lattency "http://www.baidu.com"

输出:

Running 30s test @ http://www.baidu.com

  8 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    42.80ms   51.12ms   1.12s    75.42%
    Req/Sec   596.69    132.39     0.99k    77.04%
  Latency Distribution
     50%    5.14ms
     75%   93.38ms
     90%  117.97ms
     99%  136.72ms
  98400 requests in 30.04s, 1.41GB read
  Socket errors: connect 0, read 154331, write 0, timeout 0
Requests/sec:   3275.15
Transfer/sec:     48.06MB

以上使用8个线程200个连接,对bing首页进行了30秒的压测,并要求在压测结果中输出响应延迟信息。以下对压测结果进行简单注释:

Running 30s test @ http://www.baidu.com(辱没时间30s)
8 threads and 200 connections(共8个测试线程,200个连接)
Thread Stats   Avg      Stdev     Max   +/- Stdev

       (平均值)  (标准差)  (最大值)  (正负一个标准差所占比例)

  Latency    42.80ms   51.12ms   1.12s    75.42%

   (延迟)

   Req/Sec   596.69    132.39     0.99k    77.04%

(处理的请求数)

  Latency Distribution(延迟分布)
     50%    5.14ms
     75%   93.38ms
     90%  117.97ms
     99%  136.72ms(99分位的延迟)
  98400 requests in 30.04s, 1.41GB read(30.04秒内处理完成了98499个请求,读取了1.41GB的数据)

Socket errors: connect 0, read 154331, write 0, timeout 0
Requests/sec:   3275.15(平均每秒处理完成了3275.15个请求)
Transfer/sec:     48.06MB(平均每秒读取数据48.06MB)

猜你喜欢

转载自www.cnblogs.com/syhshare/p/10712095.html
今日推荐