V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
mentalidade
V2EX  ›  程序员

为什么 wrk 和 ab, locust 压测的结果差异这么大?

  •  
  •   mentalidade · 2018-01-16 19:56:31 +08:00 · 6121 次点击
    这是一个创建于 2263 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本地使用 wrk 压测 nginx 的一个 hello,world!接口。wrk 的 qps 是 20 多万,全部 200 状态吗,无异常。ab 结果是 1 万多的 qps,locust 只有 6 千多的 qps。本机 32 核 CPU,结果差异这么大,请问该相信哪个呢?

    下面是压测过程:

    • wrk
    ./wrk -c 10000 -d 20  http://localhost:8080/status
    Running 20s test @ http://localhost:8080/status
      2 threads and 10000 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     2.51ms  654.52us  14.36ms   90.56%
        Req/Sec   105.08k     6.58k  133.08k    72.08%
      4150775 requests in 20.10s, 783.58MB read
      Socket errors: connect 8981, read 0, write 0, timeout 0
    Requests/sec: 206509.01
    Transfer/sec:     38.98MB
    
    

    查看请求数量cat access.log|wc -l,结果4089174,打开检查都是 200 状态吗,无错误。 ab 压测-c 10000 报错,为了一致,使用 wrk 压测-c 1000,qps 的值为216547.69

    • ab
    ab -c 1000 -n 200000 http://localhost:8080/status
    This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
    Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
    Licensed to The Apache Software Foundation, http://www.apache.org/
    
    Benchmarking localhost (be patient)
    Completed 20000 requests
    Completed 40000 requests
    Completed 60000 requests
    Completed 80000 requests
    Completed 100000 requests
    Completed 120000 requests
    Completed 140000 requests
    Completed 160000 requests
    Completed 180000 requests
    Completed 200000 requests
    Finished 200000 requests
    
    
    Server Software:        openresty/1.13.6.1
    Server Hostname:        localhost
    Server Port:            8080
    
    Document Path:          /status
    Document Length:        12 bytes
    
    Concurrency Level:      1000
    Time taken for tests:   18.040 seconds
    Complete requests:      200000
    Failed requests:        0
    Total transferred:      31000000 bytes
    HTML transferred:       2400000 bytes
    Requests per second:    11086.72 [#/sec] (mean)
    Time per request:       90.198 [ms] (mean)
    Time per request:       0.090 [ms] (mean, across all concurrent requests)
    Transfer rate:          1678.17 [Kbytes/sec] received
    
    Connection Times (ms)
                  min  mean[+/-sd] median   max
    Connect:        0   40  51.9     37    1048
    Processing:     1   50  11.8     49     243
    Waiting:        1   37  13.2     33     221
    Total:          2   90  52.7     89    1104
    
    Percentage of the requests served within a certain time (ms)
      50%     89
      66%     91
      75%     93
      80%     94
      90%     99
      95%    104
      98%    113
      99%    129
     100%   1104 (longest request)
    
    

    加上 -k参数 qps 就只有 9800。

    • locust

    启动了一个 master,28 个 slave,结果 qps 只有 6700 左右,请问哪个比较接近真实?

    接口就是直接安装 openresty,无优化,配置里面 echo "hello,world!"

    5 条回复    2018-12-29 10:12:12 +08:00
    kimown
        1
    kimown  
       2018-01-16 20:35:07 +08:00 via Android   ❤️ 1
    不要单机压测,结果不准,肯定不准
    wwek
        2
    wwek  
       2018-01-16 21:34:29 +08:00   ❤️ 1
    不能本机压测本机。压测软件本身的消耗资源情况不一样的
    hyhy01
        3
    hyhy01  
       2018-08-29 13:03:37 +08:00
    我也用 wrk 了,太强。性能最低的肯定是 jmeter(不过我就输出个 304 都只有 10 万)
    HorizonZy
        4
    HorizonZy  
       2018-12-29 09:59:05 +08:00
    wrk 默认是 http1.1 协议,自带长连接,每次请求不需要再去三次握手建立 tcp 连接。
    而你使用的 ab 测试没有使用-k 参数,ab -k 会在请求头加长 Connection: Keop-Alive 的。
    两个压测数据其实相差不大。
    在单个请求传输的数据比较小时 wrk 测试的 qps 要比 ab 高,数据多的时候 ab 的 qps 比 wrk 高一点。(自己测试的数据)
    mentalidade
        5
    mentalidade  
    OP
       2018-12-29 10:12:12 +08:00
    @HorizonZy #4 谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3008 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 11:05 · PVG 19:05 · LAX 04:05 · JFK 07:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.