Skip to content
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

Fixed the searchRing function for consistentHash #2460

Merged
merged 5 commits into from
Aug 2, 2023

Conversation

RomanZavodskikh
Copy link
Member

@RomanZavodskikh RomanZavodskikh commented Jul 14, 2023

This fix is needed to comply the requirements of input for binary search https://pkg.go.dev/sort#Search

Search uses binary search to find and return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. That is, Search requires that f is false for some (possibly empty) prefix of the input range [0, n) and then true for the (possibly empty) remainder

This requirement is not satisfied before this PR, because skipEndpoint(idx int) may return false for every specific index regardless of other indicies. So, even if skipEndpoint(i) is true, nothing can stop skipEndpoint(i+1) being false.

  • Added test for even load between not fading in endpoints
  • Fixed the searchRing function for consistentHash
  • Added test that LBAlgorithm.Apply finishes with all endpoints fading

@RomanZavodskikh
Copy link
Member Author

RomanZavodskikh commented Jul 14, 2023

Attaching two pair graphs to show that this change really makes sense. Here are results of 'TestFadeIn_consistent-hash,_4', the first one before fix, the second if after. This test introduces three "old" nodes and one "fading in" one. As we can see, fix makes load between three "old" nodes more even.
TestFadeIn_consistent-hash,_4
TestFadeIn_consistent-hash,_4

@RomanZavodskikh
Copy link
Member Author

RomanZavodskikh commented Jul 14, 2023

Something similar in 'TestFadeIn/consistent-hash,_5'. Three "old" nodes, three "fading in" ones. Before fix, one of three "old" nodes get less load, after fix all three get the same load.
TestFadeIn_consistent-hash,_5
TestFadeIn_consistent-hash,_5

@RomanZavodskikh
Copy link
Member Author

CI failed because of #2457 (comment)

@AlexanderYastrebov
Copy link
Member

consistentHash fadeIn support was introduced by #2087
@herojan FYI

@AlexanderYastrebov
Copy link
Member

@RomanZavodskikh Please update commit message (and PR description) with the description of the problem and why this is the proper fix.

@AlexanderYastrebov
Copy link
Member

Attaching two pair graphs to show that this change really makes sense.

It is not obvious how to interpret the graphs tbh. We should think how to make it easier to eyeball sanity check, maybe color-code datapoints according to endpoint.

@AlexanderYastrebov
Copy link
Member

@RomanZavodskikh Would it be possible to craft a specific test that fails before the fix and passes after?

@RomanZavodskikh
Copy link
Member Author

@AlexanderYastrebov FYI:

  • added commit to make graphs colourful
  • reuploaded all graphs in previous comment, all endpoints have different color now

@szuecs
Copy link
Member

szuecs commented Jul 22, 2023

Great work!

@szuecs
Copy link
Member

szuecs commented Jul 22, 2023

👍

@herojan
Copy link
Contributor

herojan commented Jul 22, 2023

Nice find, makes sense!

@RomanZavodskikh RomanZavodskikh force-pushed the fixSearchRing branch 2 times, most recently from 187043d to 696fdf5 Compare July 31, 2023 08:42
@RomanZavodskikh
Copy link
Member Author

By the way, I've added the legend. Now figures look like this.

TestFadeIn_consistent-hash,_4

@RomanZavodskikh RomanZavodskikh force-pushed the fixSearchRing branch 2 times, most recently from 2c72a3d to 8f94d9e Compare August 2, 2023 13:57
Roman Zavodskikh added 3 commits August 2, 2023 16:05
This fix is needed to comply the requirements of input
for binary search https://pkg.go.dev/sort#Search

Search uses binary search to find and return the smallest index i
in [0, n) at which f(i) is true, assuming that on the range
[0, n), f(i) == true implies f(i+1) == true.
That is, Search requires that f is false for some (possibly empty)
prefix of the input range [0, n) and then true for
the (possibly empty) remainder

Signed-off-by: Roman Zavodskikh <[email protected]>
Signed-off-by: Roman Zavodskikh <[email protected]>
@AlexanderYastrebov
Copy link
Member

👍

1 similar comment
@RomanZavodskikh
Copy link
Member Author

👍

@RomanZavodskikh RomanZavodskikh merged commit 6ea4968 into master Aug 2, 2023
6 checks passed
@RomanZavodskikh RomanZavodskikh deleted the fixSearchRing branch August 2, 2023 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants