-
Notifications
You must be signed in to change notification settings - Fork 47
Rebalance files globally across the partitions produced by FileScanConfigTaskEstimator #450
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,17 +279,31 @@ impl TaskEstimator for FileScanConfigTaskEstimator { | |
| let file_scan: &FileScanConfig = dse.data_source().as_any().downcast_ref()?; | ||
|
|
||
| let mut new_file_scan = file_scan.clone(); | ||
| new_file_scan.file_groups.clear(); | ||
| for file_group in file_scan.file_groups.clone() { | ||
| new_file_scan | ||
| .file_groups | ||
| .extend(file_group.split_files(task_count)); | ||
| } | ||
| let input_group_count = file_scan.file_groups.len().max(1); | ||
| let all_partitioned_files = file_scan | ||
| .file_groups | ||
| .iter() | ||
| .flat_map(|file_group| file_group.iter().cloned()) | ||
| .collect::<Vec<_>>(); | ||
| let file_groups = | ||
| rebalance_round_robin(all_partitioned_files, input_group_count * task_count); | ||
| new_file_scan.file_groups = file_groups.into_iter().map(Into::into).collect(); | ||
|
Comment on lines
+283
to
+290
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One requirement for this type of changes is that they should prove through the benchmarks that they indeed bring performance benefits, but this change does not seem to be meeting this criteria. Maybe there are opportunities for further re-splitting Also, you might want to try ClickBench instead, which has a greater number of files VS TPC-H or TPC-DS, you probably would get some better numbers there.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the fact that this PR shows 0 diffs in the plan snapshots makes me thing that it might be collaterally doing exactly the same thing as the previous code. Maybe that's the reason why you see no performance impact? |
||
| let plan = DataSourceExec::from_data_source(new_file_scan); | ||
| Some(Arc::new(PartitionIsolatorExec::new(plan, task_count))) | ||
| } | ||
| } | ||
|
|
||
| fn rebalance_round_robin<T>(items: Vec<T>, target_groups: usize) -> Vec<Vec<T>> { | ||
| let target_groups = target_groups.min(items.len()); | ||
| let mut groups = (0..target_groups) | ||
| .map(|_| Vec::new()) | ||
| .collect::<Vec<Vec<T>>>(); | ||
| for (idx, item) in items.into_iter().enumerate() { | ||
| groups[idx % target_groups].push(item); | ||
| } | ||
| groups | ||
| } | ||
|
|
||
| /// Tries multiple user-provided [TaskEstimator]s until one returns an estimation. If none | ||
| /// returns an estimation, a set of default [TaskEstimation] implementations is tried. Right | ||
| /// now the only default [TaskEstimation] is [FileScanConfigTaskEstimator]. | ||
|
|
@@ -393,6 +407,22 @@ mod tests { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_rebalance_round_robin_fixes_group_boundary_skew() { | ||
| let items = (0..8).collect::<Vec<_>>(); | ||
| let groups = rebalance_round_robin(items, 5); | ||
| let sizes = groups.iter().map(Vec::len).collect::<Vec<_>>(); | ||
| assert_eq!(sizes, vec![2, 2, 2, 1, 1]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_rebalance_round_robin_caps_partitions_to_file_count() { | ||
| let items = vec![10, 20, 30]; | ||
| let groups = rebalance_round_robin(items, 5); | ||
| let sizes = groups.iter().map(Vec::len).collect::<Vec<_>>(); | ||
| assert_eq!(sizes, vec![1, 1, 1]); | ||
| } | ||
|
|
||
| impl CombinedTaskEstimator { | ||
| fn push(&mut self, value: impl TaskEstimator + Send + Sync + 'static) { | ||
| self.user_provided.push(Arc::new(value)); | ||
|
|
||
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.
Nice! sounds like a good thing to try. Can you try running the benchmarks for this and report the outcome?