feat: Re-spill sort stream if unable to reserve for 2 streams#22945
Open
EmilyMatt wants to merge 2 commits into
Open
feat: Re-spill sort stream if unable to reserve for 2 streams#22945EmilyMatt wants to merge 2 commits into
EmilyMatt wants to merge 2 commits into
Conversation
Member
|
Could you please add a test in memory constraint env fuzz testing we have? |
|
Thank you for opening this pull request! Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch). Details |
Contributor
Author
|
I'm not sure what the supposed API change is, as all the functions I've modified are private 🤔 and the "details" tab shows unrelated stuff |
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.
Rationale for this change
I've encountered several cases where the merge reservation cannot acquire the minimum reservation needed(2 streams, with a buffer size of 1), we currently error in these cases but that's not a necessity.
I've implemented a simple re-spill mechanism for when the first 2 streams cannot be reserved: we take the larger of those streams, and we re-spill it with all its batches split in half(done using slice() so no copying happens at that stage and we'll have a smaller memory peak)
This converges until we have enough memory to perform the merge(because max_record_batch_size is halved, ideally)
I've encountered this in situations where there is heavy skew, so maybe in the future might be worth it running this in general whenever one stream has a max_record_batch_size that is far above the other streams, could greatly improve performance of the entire merge stream at the cost of re-spilling once.
What changes are included in this PR?
Aforementioned implementation
Are these changes tested?
Yes
Are there any user-facing changes?
No