-
Notifications
You must be signed in to change notification settings - Fork 4.5k
resolver_wrapper: add early return in addChannelzTraceEvent #7437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resolver_wrapper: add early return in addChannelzTraceEvent #7437
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7437 +/- ##
==========================================
- Coverage 81.33% 81.31% -0.03%
==========================================
Files 352 354 +2
Lines 26919 27080 +161
==========================================
+ Hits 21895 22020 +125
- Misses 3824 3844 +20
- Partials 1200 1216 +16
|
Note: this is a degradation introduced in this PR: #5192 Which used to wrap calls to |
Hi @jsm, thanks for reporting the issue and contributing the fix! grpc-go/internal/channelz/trace.go Lines 182 to 204 in 0b33bfe
AddTraceEvent logs the event even if channelz is disabled. To retain the same behaviour, you should combine the conditions from both the PRs: |
…&& !channelz.IsOn() Large and frequent calls to this method in UpdateState can cause an extremely high usage of CPU time and Memory due to underlying json.Marshal calls that are not used or needed if channelz is not on and were not Info level logging as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, adding another reviewer for a second approval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging is typically enabled. Maybe we should also be looking to remove the use of pretty.ToJSON
for the purpose of printing this struct? Would %+v
or %#v
not work just as well?
I looked into this. The format call is still made before any checks to the log level or if channelz is on. We would have to refactor how channelz works for it to return before doing any format calls. It could prevent the json Marshalling expense, but I'm not sure if |
I suspect |
Note: this is a degradation introduced in this PR: #5192
Which used to wrap calls to
addChannelzTraceEvent
in aif channelz.IsOn() {
Problem
Large and frequent calls to this method in UpdateState can cause an extremely high usage of CPU time and Memory due to underlying json.Marshal calls that are not used or needed if were not Info level logging as it is.
Alternative approach to: #7436
Pprofs
RELEASE NOTES: none