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

Implementing Spread Minimizing Token Generator #5855

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

alanprot
Copy link
Member

What this PR does:
This PR implements the Spread Minimize Token Generator algorithm based on grafana/dskit#321 by GL (thank you), but the implementation is slightly different.

The algorithm implemented in the DSKit package creates tokens in "order", and so, all the tokens need to be created using this algorithm and require a reshard for existing clusters.

The proposal in this PR is slightly different. Here, we create tokens based on the state of the ring right at a given moment, and so, we can achieve similar benefits as soon as new ingesters join the ring (no need to reshard all existing ingesters).
Screenshot 2024-04-10 at 9 23 28 AM

The algorithm is basically as follows:
When registering a new ingester, we first:

  • Determine the expected ownership of the new ingester based on the existing ingesters.
  • Determine the expected ownership of each token of this new ingester:
    • Look at all ingesters present in the same AZ and sort them (heap) based on their ownership.
    • For each new token that needs to be generated, we:
      • Pick the existing ingester with the higher ownership in the same AZ.
      • Pick a token of this ingester that has a distance greater than the expected distance (ED) for each new token.
      • Split that token, creating a new token with the expected distance ED.
      • Decrement the distance of the existing ingester by ED.

One edge case to be aware of is if we are scaling multiple ingesters at the same time, we could end up generating multiple tokens close together. To avoid this, if multiple ingesters are being scaled up simultaneously, we only use the new strategy on one of them. This seems to be working well so far, but if we encounter any problems with this approach, we can force the ingesters to join the ring one by one.

If we decide to merge this PR, I recommend leaving this feature as experimental for now and, therefore, hidden from the documentation.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • [NA] Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: alanprot <alanprot@gmail.com>
Signed-off-by: alanprot <alanprot@gmail.com>
@alanprot alanprot force-pushed the minimize-token-spread branch from ee93c02 to f05c14c Compare April 10, 2024 17:35
Copy link
Contributor

@yeya24 yeya24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. Any reason it is still a draft?

pkg/ring/lifecycler.go Outdated Show resolved Hide resolved
… back to random

Signed-off-by: alanprot <alanprot@gmail.com>
@alanprot alanprot force-pushed the minimize-token-spread branch 2 times, most recently from 7cd1cca to 931ad0c Compare April 11, 2024 01:50
@alanprot alanprot marked this pull request as ready for review April 11, 2024 02:16
@alanprot alanprot force-pushed the minimize-token-spread branch from 931ad0c to 55325b0 Compare April 11, 2024 02:25
@alanprot alanprot force-pushed the minimize-token-spread branch from 55325b0 to 2de0c64 Compare April 11, 2024 02:25
@alanprot alanprot merged commit 75f9851 into cortexproject:master Apr 11, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants