Skip to content
代码片段 群组 项目
未验证 提交 bce06174 编辑于 作者: David Mao's avatar David Mao 提交者: GitHub
浏览文件

KCFUN-138: ClientRequestQuotaManager jmh benchmark (#4594)

What
Quota manager code has non-insignificant overhead on clusters with high request rate, we should benchmark and fix this~. Profiles of both prod clusters and profiles of local benchmarks show that most of the overhead is in string generation to retrieve sensors.

Approach:
ThreadUsageSensors
We currently generate a sensor name to look up/create ThreadUsageSensors when recording values. This adds some amount of overhead in both the request handler thread and the network threads. These sensors are also created with an expiration time, which doesn't make sense because the number of these sensors is fixed and usually small (3 * (1 for request threads + # of listeners). Instead of generating these sensors lazily, we can just keep the thread usage sensors in-sync with the configured listeners.

NetworkThreadCallback
If we change the ordering in ClientRequestQuotaManager.record() and grab a reference to the recorded sensors, we can avoid performing the expensive sensor name creation in the network thread callback.

Before:
Benchmark                                                                                  Mode  Cnt     Score     Error   Units
ClientRequestQuotaManagerBench.testNetworkThreadCallback                                   avgt   15   940.726 ±  15.790   ns/op
ClientRequestQuotaManagerBench.testNetworkThreadCallback:·async                            avgt            NaN               ---
ClientRequestQuotaManagerBench.testNetworkThreadCallback:·gc.alloc.rate                    avgt   15  2764.859 ±  75.832  MB/sec
ClientRequestQuotaManagerBench.testNetworkThreadCallback:·gc.alloc.rate.norm               avgt   15  2880.003 ±   0.010    B/op
ClientRequestQuotaManagerBench.testNetworkThreadCallback:·gc.count                         avgt   15   997.000            counts
ClientRequestQuotaManagerBench.testNetworkThreadCallback:·gc.time                          avgt   15  1253.000                ms
ClientRequestQuotaManagerBench.testRecord                                                  avgt   15  1240.281 ±  36.303   ns/op
ClientRequestQuotaManagerBench.testRecord:·async                                           avgt            NaN               ---
ClientRequestQuotaManagerBench.testRecord:·gc.alloc.rate                                   avgt   15  2452.718 ± 104.847  MB/sec
ClientRequestQuotaManagerBench.testRecord:·gc.alloc.rate.norm                              avgt   15  3368.004 ±   0.014    B/op B/op
ClientRequestQuotaManagerBench.testRecord:·gc.count                                        avgt   15  1022.000            counts
ClientRequestQuotaManagerBench.testRecord:·gc.time                                         avgt   15  1224.000                ms
JMH benchmarks done

After:
Benchmark                                                                     Mode  Cnt     Score     Error   Units
ClientRequestQuotaManagerBench.testNetworkThreadCallback                      avgt   15    54.259 ±  12.669   ns/op
ClientRequestQuotaManagerBench.testNetworkThreadCallback:·async               avgt            NaN               ---
ClientRequestQuotaManagerBench.testNetworkThreadCallback:·gc.alloc.rate       avgt   15     0.004 ±   0.014  MB/sec
ClientRequestQuotaManagerBench.testNetworkThreadCallback:·gc.alloc.rate.norm  avgt   15    ≈ 10⁻⁴              B/op
ClientRequestQuotaManagerBench.testNetworkThreadCallback:·gc.count            avgt   15       ≈ 0            counts
ClientRequestQuotaManagerBench.testRecord                                     avgt   15   548.622 ±  40.003   ns/op
ClientRequestQuotaManagerBench.testRecord:·async                              avgt            NaN               ---
ClientRequestQuotaManagerBench.testRecord:·gc.alloc.rate                      avgt   15  1489.022 ± 106.025  MB/sec
ClientRequestQuotaManagerBench.testRecord:·gc.alloc.rate.norm                 avgt   15   896.077 ±   0.009    B/op
ClientRequestQuotaManagerBench.testRecord:·gc.count                           avgt   15   864.000            counts
ClientRequestQuotaManagerBench.testRecord:·gc.time                            avgt   15   855.000                ms
JMH benchmarks done
上级 88459048
No related branches found
No related tags found
无相关合并请求
显示
356 个添加148 个删除
加载中
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册