- 
        Couldn't load subscription status. 
- Fork 4.6k
benchmark/client: add context for cancellation #8614
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
base: master
Are you sure you want to change the base?
Conversation
| Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@            Coverage Diff             @@
##           master    #8614      +/-   ##
==========================================
+ Coverage   82.05%   82.19%   +0.13%     
==========================================
  Files         417      417              
  Lines       40793    40793              
==========================================
+ Hits        33473    33530      +57     
+ Misses       5963     5919      -44     
+ Partials     1357     1344      -13     🚀 New features to boost your workflow:
 | 
| Could you please add "Type: Internal Cleanup" label? Thanks | 
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.
Apologies for the delayed review and thanks for the contribution!
A few main points:
- We should pass the context though function params.
- We should try to derive contexts from other contexts as much as possible instead of using context.Background.
- We can avoid a lot of the ctx.Err()checks by letting RPCs fail and handling the case when the error had a status of CANCELLED.
| Thank you very much for the review, it is very helpful! | 
| Everything is ready, review please @arjan-bal | 
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, thanks for the contribution! Adding a second reviewer. I'll also run the benchmarks once to verify there aren't any regressions.
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.
There's a significant drop in unary performance from 625k qps to 351k qps compared to the master branch. I'm investigating further.
Investigating performance regression in unary benchmark performance.
| 
 Using the cancellable context to make RPCs seems to be the reason for the performance drop. After reverting to using  | 
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.
Left some comments to avoid the performance cost of using a cancellable context for RPCs. The main changes are:
- We should continue to propagate the context until the point of making a stream or unary call.
- We should check for context expiry before making the unary call or stream request. In most cases this means replacing the following
select {
	case <-bc.stop:
		return
	default:
}with
if ctx.Err() != nil {
        return
}- Continue to use context.Background() for requests as before.
| Review please @arjan-bal | 
| Sorry, misclicked | 
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 a second reviewer.
Fixes: #8596
Added cancellation by context in benchmark/client instead of custom channel approach. Not sure about returning
ctx.Err()(as mentioned in the original issue under point 4), so please reviewRELEASE NOTES: None