alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.32k stars 8k forks source link

[Benchmark] 1.8.5版本 benchmark性能损耗严重 | performance not well in Sentinel 1.8.5 compared with 1.7.x #2902

Open xiaomiusa87 opened 1 year ago

xiaomiusa87 commented 1 year ago

测试场景:在4C8G机器下跑com.alibaba.csp.sentinel.benchmark.SentinelEntryBenchmark的testSingleThreadDirectly、testSingleThreadSingleEntry 对比1.8.5和1.7.0,发现1.8.5性能损耗较严重

组长度 | 1.8.5 Baseline (QPS) | 1.8.5 With Sentinel (QPS) | 1.8.5 性能损耗 | 1.7.0 Baseline (QPS) | 1.7.0 With Sentinel (QPS) | 1.7.0 性能损耗 | 官方 Baseline (QPS) | 官方 With Sentinel (QPS) | 官方 性能损耗 -- | -- | -- | -- | -- | -- | -- | -- | -- | -- length=25 | 524112.631 | 277096.821 | 47.13% | 551245.089 | 364269.65 | 33.92% | 604589.916 | 401687.765 | 33.56% length=50 | 205371.625 | 151465.386 | 26.25% | 213939.277 | 179810.663 | 15.95% | 221307.617 | 192407.832 | 13.06% length=100 | 89676.053 | 78605.025 | 12.35% | 92361.784 | 85894.033 | 7.00% | 97673.228 | 91535.146 | 6.28% length=200 | 40003.392 | 37519.764 | 6.20% | 41446.589 | 39917.156 | 3.69% | 43742.96 | 42711.129 | 2.36% length=500 | 13942.424 | 13677.998 | 1.90% | 14563.868 | 14378.434 | 1.27% | 15332.924 | 15171.024 | 1.06% length=1000 | 6392.317 | 6282.31 | 1.72% | 6624.78 | 6588.871 | 0.54% | 7012.848 | 6984.036 | 0.41%
icodening commented 1 year ago

大概看了一下1.8.5的损耗更大是因为com.alibaba.csp.sentinel.util.TimeUtil获取时间戳导致的,这项改动是在1.8.2的时候改的,pr #1746 . 1.8.2之前单线程定时获取时间戳,逻辑简单损耗小。本地尝试退回低版本逻辑后,损耗与1.7.0相近都是30%左右.

baseline 
Iteration   1: 827715.314 ops/s
Iteration   2: 833483.394 ops/s
Iteration   3: 862953.880 ops/s
Iteration   4: 838244.698 ops/s
Iteration   5: 844601.165 ops/s
本地回退后
Iteration   1: 619276.191 ops/s
Iteration   2: 605762.269 ops/s
Iteration   3: 604013.370 ops/s
Iteration   4: 616744.857 ops/s
Iteration   5: 600452.212 ops/s
1.8.5
Iteration   1: 486989.339 ops/s
Iteration   2: 456925.205 ops/s
Iteration   3: 472775.531 ops/s
Iteration   4: 486847.351 ops/s
Iteration   5: 474700.233 ops/s
yanxianchao commented 1 year ago

减少2次对volatile变量的读取,减少一次原子递增(去掉writes,只有记录日志的时候会用到),可以提高一些性能 image 测试结果 修改前: Iteration 1: 389147.172 ops/ms Iteration 2: 389936.648 ops/ms Iteration 3: 389672.101 ops/ms Iteration 4: 391088.041 ops/ms Iteration 5: 390817.670 ops/ms 修改后: Iteration 1: 473274.648 ops/ms Iteration 2: 473249.861 ops/ms Iteration 3: 473374.149 ops/ms Iteration 4: 473110.630 ops/ms Iteration 5: 471155.953 ops/ms

sczyh30 commented 1 year ago

cc @jasonjoo2010

yanxianchao commented 1 year ago

刚开始研究sentinel,关于这个类(TimeUtil)是不是可以进一步优化一下,看一下是否可行 1、调用量的统计是否可以使用Constants.ENTRY_NODE中的统计结果,这样获取时间戳的时候就不用单独统计了 2、获取时间戳的代码进一步优化,对volatile变量只做必要的读取。