Avoid the per-request rotation copy in round-robin address selection#2230
Open
pavel-ptashyts wants to merge 2 commits into
Open
Avoid the per-request rotation copy in round-robin address selection#2230pavel-ptashyts wants to merge 2 commits into
pavel-ptashyts wants to merge 2 commits into
Conversation
RoundRobinAddressSelector.rotateBy allocated a fresh ArrayList (backing array of size n) plus two subList views on every multi-IP round-robin request whose selected index != 0 — i.e. (n-1)/n of requests for an n-IP host — just to present the resolved addresses in round-robin failover order. Return a lightweight read-only view (RotatedView, one small wrapper over the resolved list + a start index) instead of copying: element i maps to resolved.get((index + i) mod size). All consumers only read the result (get/size/iteration — NettyChannelConnector's failover loop and deprioritizeCooling), and the resolved list is not mutated after being wrapped, so no copy is needed. index == 0 and single-IP hosts still return the resolved list unchanged (no allocation), as before. Only affects the opt-in LoadBalance.ROUND_ROBIN path. Existing selector tests (rotation order/evenness/failover completeness) pass unchanged; adds tests asserting the full element-by-element rotation order and that the returned view is read-only. No API change: rotateBy and RotatedView are private; rotate()'s signature is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RoundRobinAddressSelector.rotateBy allocated a fresh ArrayList (backing array of size n) plus two subList views on every multi-IP round-robin request whose selected index != 0 — i.e. (n-1)/n of requests for an n-IP host — just to present the resolved addresses in round-robin failover order.
Return a lightweight read-only view (RotatedView, one small wrapper over the resolved list + a start index) instead of copying: element i maps to resolved.get((index + i) mod size). All consumers only read the result (get/size/iteration — NettyChannelConnector's failover loop and deprioritizeCooling), and the resolved list is not mutated after being wrapped, so no copy is needed. index == 0 and single-IP hosts still return the resolved list unchanged (no allocation), as before.
Only affects the opt-in LoadBalance.ROUND_ROBIN path. Existing selector tests (rotation order/evenness/failover completeness) pass unchanged; adds tests asserting the full element-by-element rotation order and that the returned view is read-only.
No API change: rotateBy and RotatedView are private; rotate()'s signature is unchanged.