-
Notifications
You must be signed in to change notification settings - Fork 905
GODRIVER-2627 optimize latency selector #1108
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
Conversation
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.
@isopov thank you for the PR!
mongo/description/selector_test.go
Outdated
@@ -230,6 +230,67 @@ func TestSelector_Sharded(t *testing.T) { | |||
require.Equal([]Server{s}, result) | |||
} | |||
|
|||
func BenchmarkLatencySelector(b *testing.B) { | |||
bench := func(b *testing.B, serversHook func(servers []Server)) { |
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.
Instead of using a closure and constructing sub-benchmarks for each case, can we iterate over the benchmark cases? Something like this:
for _, bcase := range []struct {
name string
serversHook func(servers []description.Server)
}{
{
"AllFit",
func(servers []description.Server) {},
},
{
"AllButOneFit",
func(servers []description.Server) {
servers[0].AverageRTT = 2 * time.Second
},
},
// Continue test cases
} {
bcase := bcase
b.Run(bcase.name, func(b *testing.B) {
// your benchmark logic
})
}
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.
Changed benchmark this way
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
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.
@isopov thanks for the improvements! Looks good 👍
Summary
Optimize allocations in latency server selector.
Background & Motivation
Similar to #1107 i try to optimize allocations in latency server selector. Benchmark provided without changes:
And with proposed optimization: