天天看点

Coordinated Omission 问题 造成 wrk 压测结果不准症状原因更好的解决参考

症状

在使用 wrk 等压测工具对服务进行压测时,经常会发现 P99 和 P90 之间的差异很大,而且 wrk 得出的 P99 可能会比 prometheus 统计出的 P99 更高。

比如wrk可能得到如下结果:

Latency Distribution  
 50.000%    2.76ms
 75.000%    5.91ms
 90.000%    9.42ms
 99.000%   48.00ms
 99.900%   70.01ms
 99.990%  183.04ms
 99.999%  317.44ms
100.000%  396.80ms
           

但实际上 prometheus 统计出的 P99 只有 20ms。

原因

举个🌰

设想如下场景:

地铁闸机,每个人通过需要耗费 10s ,A、B、C、D、E 五人按顺序排队过闸机。

对于 A 来说,消耗的时间为 10s,

对于 E 来说,消耗的时间为 50s(40s 排队 + 10s 通过)。

现在要描述地铁闸机的平均通过耗时,

如果不计算排队时间,则应该是 10s,

如果计算排队时间,则应该是 30s,

哪个对?

为了便于理解,后边会成这种现象叫 「排队现象」,应**「排队现象」造成的耗时称为「排队耗时」。**

类比到服务器

服务器处理一条请求需要耗费 1s,使用 1 个线程和 5 个连接,每秒发送 5 个请求。

对于第一个请求,耗时毫无疑问是 1s,

但是对于后边的请求,则可能出现排队的情况*( 比如对于第 2 个请求,其耗时就是 1s 排队 + 1s 处理 )。*

如果程序保持这个请求速率连续运行 1 分钟,那应该怎么描述服务器的 latency ?

Coordinated Omission 问题

当压测工具的线程数量设置不合理时,可能会遇到上边说的类似于排队的情况,最开始压测工具是不会将“排队时间“加入 latency 统计的,后来 Gil Tene 觉得忽略“排队时间”的情况不能完整的体现压测性能,并称这种情况叫做 Coordinated Omission,有些地方也翻译为 协调遗漏 。

针对 Coordinated Omission 问题,wrk 做了校正功能,将 “排队时间” 加入了 latency 统计。

但实际上我们压测时很避免压测工具和服务器之间的排队现象,因此 latency 统计 中的 max 耗时可能有时会显得不可思议。

更好的解决

wrk2

校正 Coordinated Omission ***的压测结果和 未校正 Coordinated Omission 的压测结果对我们了解服务器性能都是有意义的,但是 wrk 简单粗暴(只用了10行代码)*的将 Coordinated Omission 进行了校正,我们只能通过不断地调整 线程数量 来达到一个满意的测试结果。

后来提出 Coordinated Omission 问题 的 Gil Tene 专门开发了一个 wrk2 来更好的解决这个问题。

wrk2 vs wrk

wrk2 与 wrk 的主要区别有三个

  • -R

    : 以指定的 rps 去请求服务器
  • --u_latency

    :不修正 Coordinated Omission 问题 的 latency 统计
  • 更详细的 latency 分布统计

当然,当使用 wrk2 以指定的 rps 去请求服务器时,受 操作系统睡眠时间行为 等情况的影响,wrk2 的 latency 准确度低于 wrk,这也是 wrk2 无法取代 wrk 的重要原因。

我们应该将 wrk2 作为 wrk 的一个补充,当然也不能过度迷信 wrk ,这些压测工具都是只能反映出服务器的一个大致性能,更重要的还是要结合多方的日志、监控甚至是 systemtap 等工具来综合评估服务器的性能,在做性能评估时,也应该预留出足够的性能冗余。

wrk2 结果示例

Running 1m test @ http://xxxxxx
  10 threads and 200 connections
  Thread calibration: mean lat.: 19.755ms, rate sampling interval: 32ms
  Thread calibration: mean lat.: 24.679ms, rate sampling interval: 47ms
  Thread calibration: mean lat.: 37.411ms, rate sampling interval: 70ms
  Thread calibration: mean lat.: 24.097ms, rate sampling interval: 51ms
  Thread calibration: mean lat.: 67.573ms, rate sampling interval: 422ms
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    42.55ms  116.43ms   1.18s    92.78%
    Req/Sec     2.07k   379.69     3.70k    72.59%
  Latency Distribution (HdrHistogram - Recorded Latency)
 50.000%    9.11ms
 75.000%   17.25ms
 90.000%   66.30ms
 99.000%  655.36ms
 99.900%  982.53ms
 99.990%    1.16s
 99.999%    1.18s
100.000%    1.19s

  Detailed Percentile spectrum:
       Value   Percentile   TotalCount 1/(1-Percentile)

       1.164     0.000000            1         1.00
       3.957     0.100000        77014         1.11
       5.079     0.200000       154070         1.25
       6.215     0.300000       230963         1.43
       7.443     0.400000       307822         1.67
       9.111     0.500000       384870         2.00
      10.119     0.550000       423237         2.22
      11.295     0.600000       461637         2.50
      12.743     0.650000       500203         2.86
      14.543     0.700000       538682         3.33
      17.247     0.750000       577124         4.00
      19.263     0.775000       596393         4.44
      21.871     0.800000       615515         5.00
      25.583     0.825000       634779         5.71
      31.183     0.850000       654004         6.67
      41.311     0.875000       673258         8.00
      50.431     0.887500       682839         8.89
      66.303     0.900000       692471        10.00
      95.999     0.912500       702086        11.43
     146.047     0.925000       711688        13.33
     199.551     0.937500       721308        16.00
     222.847     0.943750       726126        17.78
     256.639     0.950000       730930        20.00
     306.687     0.956250       735740        22.86
     356.863     0.962500       740548        26.67
     403.967     0.968750       745373        32.00
     423.935     0.971875       747765        35.56
     447.743     0.975000       750187        40.00
     472.575     0.978125       752580        45.71
     505.343     0.981250       754972        53.33
     542.207     0.984375       757382        64.00
     565.247     0.985938       758586        71.11
     597.503     0.987500       759783        80.00
     631.295     0.989062       760988        91.43
     670.719     0.990625       762187       106.67
     709.119     0.992188       763388       128.00
     728.063     0.992969       763988       142.22
     743.423     0.993750       764590       160.00
     759.807     0.994531       765205       182.86
     772.095     0.995313       765800       213.33
     785.919     0.996094       766394       256.00
     793.087     0.996484       766696       284.44
     799.231     0.996875       766989       320.00
     807.935     0.997266       767301       365.71
     822.783     0.997656       767589       426.67
     857.599     0.998047       767890       512.00
     887.295     0.998242       768040       568.89
     908.287     0.998437       768193       640.00
     930.815     0.998633       768342       731.43
     954.879     0.998828       768491       853.33
     985.087     0.999023       768642      1024.00
     999.423     0.999121       768717      1137.78
    1014.783     0.999219       768791      1280.00
    1025.023     0.999316       768868      1462.86
    1034.751     0.999414       768942      1706.67
    1050.623     0.999512       769021      2048.00
    1056.767     0.999561       769055      2275.56
    1064.959     0.999609       769102      2560.00
    1070.079     0.999658       769135      2925.71
    1077.247     0.999707       769167      3413.33
    1083.391     0.999756       769206      4096.00
    1096.703     0.999780       769226      4551.11
    1103.871     0.999805       769242      5120.00
    1120.255     0.999829       769262      5851.43
    1134.591     0.999854       769280      6826.67
    1154.047     0.999878       769299      8192.00
    1160.191     0.999890       769309      9102.22
    1163.263     0.999902       769320     10240.00
    1167.359     0.999915       769327     11702.86
    1169.407     0.999927       769339     13653.33
    1171.455     0.999939       769346     16384.00
    1173.503     0.999945       769356     18204.44
    1173.503     0.999951       769356     20480.00
    1174.527     0.999957       769360     23405.71
    1175.551     0.999963       769366     27306.67
    1176.575     0.999969       769373     32768.00
    1176.575     0.999973       769373     36408.89
    1177.599     0.999976       769376     40960.00
    1177.599     0.999979       769376     46811.43
    1178.623     0.999982       769378     54613.33
    1180.671     0.999985       769382     65536.00
    1180.671     0.999986       769382     72817.78
    1181.695     0.999988       769387     81920.00
    1181.695     0.999989       769387     93622.86
    1181.695     0.999991       769387    109226.67
    1181.695     0.999992       769387    131072.00
    1181.695     0.999993       769387    145635.56
    1182.719     0.999994       769388    163840.00
    1182.719     0.999995       769388    187245.71
    1183.743     0.999995       769390    218453.33
    1183.743     0.999996       769390    262144.00
    1183.743     0.999997       769390    291271.11
    1183.743     0.999997       769390    327680.00
    1183.743     0.999997       769390    374491.43
    1185.791     0.999998       769392    436906.67
    1185.791     1.000000       769392          inf
#[Mean    =       42.551, StdDeviation   =      116.429]
#[Max     =     1184.768, Total count    =       769392]
#[Buckets =           27, SubBuckets     =         2048]
----------------------------------------------------------

  Latency Distribution (HdrHistogram - Uncorrected Latency (measured without taking delayed starts into account))
 50.000%    6.49ms
 75.000%    9.41ms
 90.000%   12.18ms
 99.000%   17.38ms
 99.900%   42.65ms
 99.990%  399.61ms
 99.999%  601.09ms
100.000%  607.23ms

  Detailed Percentile spectrum:
       Value   Percentile   TotalCount 1/(1-Percentile)

       1.030     0.000000            1         1.00
       3.033     0.100000        77058         1.11
       3.985     0.200000       153908         1.25
       4.875     0.300000       230983         1.43
       5.679     0.400000       307777         1.67
       6.495     0.500000       384949         2.00
       6.947     0.550000       423265         2.22
       7.451     0.600000       461789         2.50
       8.023     0.650000       500133         2.86
       8.679     0.700000       538647         3.33
       9.415     0.750000       577236         4.00
       9.807     0.775000       596475         4.44
      10.223     0.800000       615833         5.00
      10.655     0.825000       635061         5.71
      11.111     0.850000       654213         6.67
      11.615     0.875000       673390         8.00
      11.887     0.887500       682958         8.89
      12.175     0.900000       692461        10.00
      12.495     0.912500       702089        11.43
      12.847     0.925000       711712        13.33
      13.239     0.937500       721427        16.00
      13.455     0.943750       726245        17.78
      13.687     0.950000       730957        20.00
      13.959     0.956250       735800        22.86
      14.255     0.962500       740596        26.67
      14.607     0.968750       745357        32.00
      14.823     0.971875       747804        35.56
      15.063     0.975000       750182        40.00
      15.335     0.978125       752613        45.71
      15.671     0.981250       754988        53.33
      16.103     0.984375       757372        64.00
      16.375     0.985938       758585        71.11
      16.703     0.987500       759806        80.00
      17.087     0.989062       760983        91.43
      17.599     0.990625       762207       106.67
      18.287     0.992188       763394       128.00
      18.751     0.992969       763990       142.22
      19.279     0.993750       764586       160.00
      20.031     0.994531       765200       182.86
      20.911     0.995313       765788       213.33
      22.015     0.996094       766390       256.00
      22.671     0.996484       766690       284.44
      23.439     0.996875       766991       320.00
      24.463     0.997266       767294       365.71
      25.679     0.997656       767592       426.67
      27.311     0.998047       767890       512.00
      28.863     0.998242       768041       568.89
      31.199     0.998437       768191       640.00
      34.367     0.998633       768341       731.43
      38.431     0.998828       768491       853.33
      43.263     0.999023       768642      1024.00
      45.631     0.999121       768716      1137.78
      48.703     0.999219       768791      1280.00
      52.575     0.999316       768868      1462.86
      74.879     0.999414       768942      1706.67
     199.551     0.999512       769017      2048.00
     204.543     0.999561       769054      2275.56
     207.487     0.999609       769092      2560.00
     211.327     0.999658       769130      2925.71
     223.487     0.999707       769168      3413.33
     266.239     0.999756       769206      4096.00
     344.575     0.999780       769223      4551.11
     356.351     0.999805       769242      5120.00
     362.239     0.999829       769261      5851.43
     367.359     0.999854       769280      6826.67
     382.975     0.999878       769300      8192.00
     386.303     0.999890       769308      9102.22
     401.407     0.999902       769317     10240.00
     406.783     0.999915       769327     11702.86
     481.791     0.999927       769336     13653.33
     570.879     0.999939       769346     16384.00
     574.463     0.999945       769350     18204.44
     578.559     0.999951       769356     20480.00
     583.167     0.999957       769361     23405.71
     584.191     0.999963       769365     27306.67
     585.727     0.999969       769369     32768.00
     592.895     0.999973       769372     36408.89
     595.455     0.999976       769374     40960.00
     596.991     0.999979       769376     46811.43
     598.527     0.999982       769378     54613.33
     599.551     0.999985       769381     65536.00
     600.063     0.999986       769382     72817.78
     600.575     0.999988       769383     81920.00
     601.087     0.999989       769384     93622.86
     602.111     0.999991       769385    109226.67
     602.623     0.999992       769387    131072.00
     602.623     0.999993       769387    145635.56
     603.647     0.999994       769388    163840.00
     603.647     0.999995       769388    187245.71
     604.159     0.999995       769389    218453.33
     605.695     0.999996       769390    262144.00
     605.695     0.999997       769390    291271.11
     605.695     0.999997       769390    327680.00
     605.695     0.999997       769390    374491.43
     607.231     0.999998       769392    436906.67
     607.231     1.000000       769392          inf
#[Mean    =        7.352, StdDeviation   =        8.518]
#[Max     =      606.720, Total count    =       769392]
#[Buckets =           27, SubBuckets     =         2048]
----------------------------------------------------------
  969485 requests in 38.67s, 278.96MB read
Requests/sec:  25068.07
Transfer/sec:      7.21MB
           

参考

  1. https://github.com/giltene/wrk2/issues/54
  2. https://mp.weixin.qq.com/s/n8a4wzmf6I8kUc-T47PylA
  3. http://highscalability.com/blog/2015/10/5/your-load-generator-is-probably-lying-to-you-take-the-red-pi.html
  4. https://medium.com/@siddontang/the-coordinated-omission-problem-in-the-benchmark-tools-5d9abef79279
  5. https://www.jianshu.com/p/bfb2b0f50edd
  6. https://momeis.net/post-7362.html

继续阅读