wrk做基准压力测试

参考资料

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)

-c :模拟的连接数
-d :压测时间
-t :在施压机上开启的线程数,例如:用-c指定了80个连接,-t指定了8个线程(CPU核心的两倍,根据自己的机器实际情况来,我的是4核8线程的),则说明每个线程要负责80/8=10个连接。这里很多小伙伴会认为是一共模拟了80*8=640,这是不对的,是相除的关系,而不是相乘。
-s :指定外部的lua脚本
–latency :延时分布,加上此项可以查看50% 75% 99%的请求延时情况

示例
$ wrk -c80 -t8 -d20s --latency -s ./post.lua http://192.168.92.38:8080/user/addUser
Running 20s test @ http://192.168.92.38:8080/user/addUser
  8 threads and 80 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   541.09ms  204.82ms   1.98s    82.61%
    Req/Sec    19.92     12.16    70.00     81.66%
  Latency Distribution
     50%  523.46ms
     75%  578.50ms
     90%  768.16ms
     99%    1.24s
  2944 requests in 20.04s, 209.88KB read
  Socket errors: connect 0, read 0, write 0, timeout 1
Requests/sec:    146.92
Transfer/sec:     10.47KB

上边模拟了80个并发,可以看到美妙的吞吐量QPS是146.92,这当然不是最大的吞吐,想获取最大吞吐亮可以固定线程数以后,不断的增加连接数,直到超时的请求过多,或者时延无法接受

猜你喜欢

转载自blog.csdn.net/chen462488588/article/details/114579357