stats: Re-use objects while calling multiple Handlers#8639
stats: Re-use objects while calling multiple Handlers#8639arjan-bal merged 5 commits intogrpc:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8639 +/- ##
==========================================
+ Coverage 81.28% 82.00% +0.72%
==========================================
Files 415 417 +2
Lines 40888 40793 -95
==========================================
+ Hits 33234 33452 +218
+ Misses 6162 5981 -181
+ Partials 1492 1360 -132
🚀 New features to boost your workflow:
|
a36c3d1 to
88fb8c2
Compare
88fb8c2 to
38cc04a
Compare
|
Do you have any benchmark numbers for this change? |
There was a problem hiding this comment.
Also, I was wondering what if you exported the combinedHandler and used it as a concrete type instead of as stats.Handler? The grpc server and the channel could use this concrete type, and any other internal type could as well. For external facing APIs that are expecting a stats.Handler, it should still continue to work if the caller has the concrete type. But again, I don't know if this will have any bearing on the performance. So, if this is going to increase the scope of the PR, please push back. Thanks.
This reverts commit 36ba616.
I had to temporarily modify the benchmarks to register stats handlers on the client and server. I've added the results in the PR description. |
I considered exporting
|
This PR improves performance by eliminating heap allocations when multiple stats handlers are configured.
Previously, iterating through a list of handlers caused one heap allocation per handler for each RPC. This change introduces a Handler that combines multiple Handlers and implements the
Handlerinterface. The combined handler delegates calls to the handlers it contains.This approach allows gRPC clients and servers to operate as if there were only a single
Handlerregistered, simplifying the internal logic and removing the per-RPC allocation overhead. To avoid any performance impact when stats are disabled, the combinedHandleris only created when at least one handler is registered.Tested
Since existing benchmarks don't register stats handler, I modified the benchmark to add 2 stats handlers each on the server and client (36ba616).
RELEASE NOTES: