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.
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
Support Optimized Write #1198
base: master
Are you sure you want to change the base?
Support Optimized Write #1198
Changes from all commits
72e6555
e2d12dc
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
There was an update on the Spark side to make this more performant: apache/spark@9e1d00c
Is the main reason to not just use the Spark versions directly to add the configurable mergedPartitionFactor, or to not rely on those internal helper functions?
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.
Yes it's for both; make configurable and not rely on spark internal util which can change frequently. But I'm also okay to use Spark one. I'm just waiting for databricks team to get back on this. (and auto compaction too)
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.
https://learn.microsoft.com/en-us/azure/synapse-analytics/spark/optimize-write-for-apache-spark
FYI, the code is being used in prod at least 6 months and no major issue so far.
We might need to increase binSize config / PARQUET COMPRESSION RATIO for larger files. (60~80mb avg for now)
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.
Hmm I tried building and using this myself and I don't seem to be getting my large partitions split, gonna add some more logging to try to see why/what's happening.
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.
Yes it's the case this approach (Spark rebalance logic) cannot handle. Because the unit of rebalancing is determined by the source partition layout. If the data is skewed or only few number of partitions, it cannot be rebalanced properly.
Please refer the figure in #1158 (comment)
If the source dataframe consists of all same key=1 and 10GB of 1 partition, it cannot be split.
e.g. df.repartition(1, col("key")).select(col("key")).write.format("delta").parquet("path")
I removed redundant repartition execution plan on top of the child plan, but it cannot cover all the cases.
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 smallest unit of splitting is the single task map output for a single reducer ID right? That wasn't what I was seeing, where I had all my map tasks shuffle write < 1 GB, but I had some reducer tasks reading > 10 GB of shuffle data. After digging through how map output sizes work a little bit, I'm gonna try again and see if this is some weird side effect of
HighlyCompressedMapStatus
for large numbers of reducing partitions (> 2000 by default). Only thought is some weird effect of a lot of small blocks being "averaged out" to compute map output sizes per reducer.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.
That appeared to be it. I dropped my shuffle partitions to 1k and it behaved as I would expect. Not sure how common my case would be with particular types of data skew, but maybe it would be good to log a warning if your shuffle partitions exceeds the threshold for using
HighlyCompressedMapStatus
, it can limit the ability to properly split skewed partitions, because average map output size is used for individual map reducer outputs, instead of the real 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.
Can you explain each of the cases with comments... these are pretty complicated on to reason about
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.
Thanks for the review! I'll add some comments & classdoc and try to improve documentation in #1158
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.
@tdas I added some example for OptimizeWrite partitioned data.
#1158 (comment)
Could you have a look and let me know if there is something unclear?
For non-partitioned data, here I use RoundRobinPartitioning but it could be inefficient in some cases as it distributes all rows into all partitions which is unnecessary. I think we could improve it 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 am trying to understand this and map it spark code. what you are trying to do is remove a shuffle if it wasnt added automatically by the planner to ensure requirement. Doesnt that mean if user asked for repartitioning by a certain way with an explicit programmatic API (e.g., DataFrame.repartition) we will be ignoring that completely?
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.
Yes it's because for Optimize Write, we add repartition(partitionColumns)( + rebalancing) at top of the plan, so unnecessary repartition(n) or coalesce(n) could be removed.
#1158 - Things to do - 3 for detail