-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22465][FOLLOWUP] Update the number of partitions of default partitioner when defaultParallelism is set #20091
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -262,14 +262,11 @@ class PartitioningSuite extends SparkFunSuite with SharedSparkContext with Priva | |
|
|
||
| test("defaultPartitioner") { | ||
| val rdd1 = sc.parallelize((1 to 1000).map(x => (x, x)), 150) | ||
| val rdd2 = sc | ||
| .parallelize(Array((1, 2), (2, 3), (2, 4), (3, 4))) | ||
| val rdd2 = sc.parallelize(Array((1, 2), (2, 3), (2, 4), (3, 4))) | ||
| .partitionBy(new HashPartitioner(10)) | ||
| val rdd3 = sc | ||
| .parallelize(Array((1, 6), (7, 8), (3, 10), (5, 12), (13, 14))) | ||
| val rdd3 = sc.parallelize(Array((1, 6), (7, 8), (3, 10), (5, 12), (13, 14))) | ||
| .partitionBy(new HashPartitioner(100)) | ||
| val rdd4 = sc | ||
| .parallelize(Array((1, 2), (2, 3), (2, 4), (3, 4))) | ||
| val rdd4 = sc.parallelize(Array((1, 2), (2, 3), (2, 4), (3, 4))) | ||
| .partitionBy(new HashPartitioner(9)) | ||
| val rdd5 = sc.parallelize((1 to 10).map(x => (x, x)), 11) | ||
|
|
||
|
|
@@ -284,7 +281,42 @@ class PartitioningSuite extends SparkFunSuite with SharedSparkContext with Priva | |
| assert(partitioner3.numPartitions == rdd3.getNumPartitions) | ||
| assert(partitioner4.numPartitions == rdd3.getNumPartitions) | ||
| assert(partitioner5.numPartitions == rdd4.getNumPartitions) | ||
| } | ||
|
|
||
| test("defaultPartitioner when defaultParallelism is set") { | ||
| assert(!sc.conf.contains("spark.default.parallelism")) | ||
| try { | ||
| sc.conf.set("spark.default.parallelism", "4") | ||
|
|
||
| val rdd1 = sc.parallelize((1 to 1000).map(x => (x, x)), 150) | ||
| val rdd2 = sc.parallelize(Array((1, 2), (2, 3), (2, 4), (3, 4))) | ||
| .partitionBy(new HashPartitioner(10)) | ||
| val rdd3 = sc.parallelize(Array((1, 6), (7, 8), (3, 10), (5, 12), (13, 14))) | ||
| .partitionBy(new HashPartitioner(100)) | ||
| val rdd4 = sc.parallelize(Array((1, 2), (2, 3), (2, 4), (3, 4))) | ||
| .partitionBy(new HashPartitioner(9)) | ||
| val rdd5 = sc.parallelize((1 to 10).map(x => (x, x)), 11) | ||
|
Contributor
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. Can we add a case where partitioner is not used and default (from spark.default.parallelism) gets used ? |
||
| val rdd6 = sc.parallelize(Array((1, 2), (2, 3), (2, 4), (3, 4))) | ||
| .partitionBy(new HashPartitioner(3)) | ||
|
|
||
| val partitioner1 = Partitioner.defaultPartitioner(rdd1, rdd2) | ||
| val partitioner2 = Partitioner.defaultPartitioner(rdd2, rdd3) | ||
| val partitioner3 = Partitioner.defaultPartitioner(rdd3, rdd1) | ||
| val partitioner4 = Partitioner.defaultPartitioner(rdd1, rdd2, rdd3) | ||
| val partitioner5 = Partitioner.defaultPartitioner(rdd4, rdd5) | ||
| val partitioner6 = Partitioner.defaultPartitioner(rdd5, rdd5) | ||
| val partitioner7 = Partitioner.defaultPartitioner(rdd1, rdd6) | ||
|
|
||
| assert(partitioner1.numPartitions == rdd2.getNumPartitions) | ||
| assert(partitioner2.numPartitions == rdd3.getNumPartitions) | ||
| assert(partitioner3.numPartitions == rdd3.getNumPartitions) | ||
| assert(partitioner4.numPartitions == rdd3.getNumPartitions) | ||
| assert(partitioner5.numPartitions == rdd4.getNumPartitions) | ||
| assert(partitioner6.numPartitions == sc.defaultParallelism) | ||
| assert(partitioner7.numPartitions == sc.defaultParallelism) | ||
| } finally { | ||
| sc.conf.remove("spark.default.parallelism") | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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.
This is the core change. I think it makes sense as it fixes a regression in #20002
If the partitioner is not eligible, but its numPartition is larger the the default one, we should still pick this partitioner instead of creating a new one.
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 are multiple cases here.
a) spark.default.parallelism is not set by user.
For this case, PR is a noop
b) maxPartitions is atleast an order higher than max partitioner
b.1) If spark.default.parallelism is not set, the PR is a noop.
b.2) spark.default.parallelism is explicitly set by user.
This is a change in behavior which has been introduced - rely on user specified value instead of trying to infer it when inferred value is off by atleast an order.
If users were setting suboptimal values for "spark.default.parallelism" - then there will be a change in behavior - though I would argue this is the expected behavior given documentation of 'spark.default.parallelism'
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.
It depends on how you define "default". In this case, if we can benefit from reusing an existing partitioner, we should pick that partitioner. If we want to respect
spark.default.parallelismstrictly, we should not reuse partitioner at all.For this particular case, picking the existing partitioner is obviously a better choice and it was the behavior before #20002 , so I'm +1 on this change.
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.
[Edited, hopefully, for clarity]
I dont see an ambiguity here - am I missing something ?
To rephrase my point - this proposed PR has an impact only if user has explicitly set 'spark.default.parallelism' - else it is a noop.
If this is not the case (other than desired behavior of SPARK-22465), I might be missing something; do let me know !
What is the concern here ? Users have set incorrect values for spark.default.parallelism ?
I agree with you - we should not have - except that ship has sailed long long time back - since atleast 0.5 this has been the behavior in spark - I dont have context before that.
Historically, default parallelism was added later - using "largest partitioner if set or largest partition size when no partitioner is set" was the behavior. When default parallelism was introduced, probably (I guess) for backward compatible, the behavior was continued.
#20002 surgically fixed only the case when inferred partition size was off by atleast an order.
When it is off by an order - dont rely on largest partitioner, it is not useful due to OOM's.
In this case, if user has explicitly specified spark.default.parallelism, rely on user provided value - else preserve existing behavior of picking largest partition.
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 we all agree that reusing partitioner is an existing behavior and we should not stick to
spark.default.parallelismhere.#20002 is good as it fixes a bad case where reusing partitioner slows down the query. And this PR surgically fixed one regression introduced by #20002 that, even if the existing partitioner is not eligible(has very little partitions), it's still better than fallback to default parallelism.