-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Emit aggregation groups in chunks to avoid blocking async runtime #18906
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
Open
ahmed-mez
wants to merge
4
commits into
apache:main
Choose a base branch
from
ahmed-mez:ahmed/long-poll
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+545
−35
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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'm not sure if I fully understand this. Looking at the previous code, it does look like it was already emitting groups incrementally.
The difference I see is that in this new code we track the offset with
self.emission_offsetbut the other side of theifstatements mutatesself.group_valuesin place to trim the results that have already been emitted.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.
The
emission_offsetoptimization is just to avoid the expensive "copy remaining rows" operation that the oldEmitTo::Firstpath did during input processing. The real fix is replacingemit(EmitTo::All)(which blocks for seconds on large group counts) with incremental drain https://github.com/apache/datafusion/pull/18906/files#diff-69c8ecaca5e2c7005f2ed1facaa41f80b45bfd006f2357e53ff3072f535c287dR1196There 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.
Doesn't that mean then that the
elsepart (whendrain_mode == false) is now dead code? FWIW I can put apanic!()here:output } else { + panic!("foo"); let groups_rows = group_values.iter().take(n); let output = self.row_converter.convert_rows(groups_rows)?;And all the tests in the crate pass
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 think it's needed for
emit_early_if_necessary()forPartialmode with memory pressure andgroup_ordering.emit_to()when input is sorted or partially sorted. Those 2 cases can trigger incremental / early emission.I added a test case for sorted input c4903b6 that triggers that path.
Uh oh!
There was an error while loading. Please reload this page.
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'll reframe. If during the benchmarks you see that the total execution time is the same with the old code vs these new one that executes with
drain_mode == true, how about just leavinggroup_values/row.rsas it was?If there's actually no noticeable performance improvement, we might same some lines of code and complexity by just keeping the old path here in
group_values/row.rs, as the actual improvement is happening inrow_hash.rs.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 can give that a try but it will be less efficient for sure. There is no value in retaining the state of the hash map when draining. And you can see that the
drain_mode == falsepath is doing much heavier operations compared todrain_mode == true.