-
Notifications
You must be signed in to change notification settings - Fork 184
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
Multi-address client: optimize client selection #2979
Conversation
A benchmark that sneaks into `DefaultMultiAddressUrlHttpClientBuilder` internals to isolate `selectClient` logic and skips modifications to requestTarget and headers.
This reverts commit 01fabce.
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.
I like the simplification, that alone is worth it for me.
I am curious about the benchmarks: are they already committed somewhere or are they local? I'm specifically curious whether a lot of the benefit comes from the port being the first thing checked if the ports are set as random numbers vs the most common 80/443.
...p-netty/src/main/java/io/servicetalk/http/netty/DefaultMultiAddressUrlHttpClientBuilder.java
Outdated
Show resolved
Hide resolved
See commits in this PR. I added the benchmark and removed it later because it required some internal changes for multi-address client builder.
I used a fixed port bcz int check seems trivial to make any difference. |
...p-netty/src/main/java/io/servicetalk/http/netty/DefaultMultiAddressUrlHttpClientBuilder.java
Show resolved
Hide resolved
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.
Looks good after you address the spotbugs complaints regarding the omission of the type and null checking in UrlKey.equals(..)
. (I don't care if they're ignored or added back.)
Verified with the benchmark that it doesn't make any difference, added them back |
Motivation:
selectClient
attracted my attention after I saw it can take up to 10% on the flame graph.Modifications:
CachingKeyFactory
toUrlKeyFactory
;UrlKey
s;UrlKey.hashCode
because it's used >1 time;HostAndPort
from the hot path because it's required only to create a new client once;Result:
Client selection reduced from
63.788 ± 1.268 ns/op
to14.512 ± 0.233 ns/op
.I tried a few different approaches. All of them are shown here as independent commits.