-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23496][CORE] Locality of coalesced partitions can be severely skewed by the order of input partitions #20664
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
Changes from 1 commit
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 | ||
|---|---|---|---|---|
|
|
@@ -1129,6 +1129,36 @@ class RDDSuite extends SparkFunSuite with SharedSparkContext { | |||
| }.collect() | ||||
| } | ||||
|
|
||||
| test("SPARK-23496: order of input partitions can result in severe skew in coalesce") { | ||||
|
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. this test looks to me as a good candidate for flakiness, since we are are picking random numbers. Can we set the seed in order to avoid this?
Contributor
Author
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. The test is in fact deterministic. The seed is already fixed here:
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. I see, thanks, sorry, I missed it |
||||
| val numInputPartitions = 100 | ||||
| val numCoalescedPartitions = 50 | ||||
| val locations = Array("locA", "locB") | ||||
|
|
||||
| val inputRDD = sc.makeRDD(Range(0, numInputPartitions).toArray[Int], numInputPartitions) | ||||
| assert(inputRDD.getNumPartitions == numInputPartitions) | ||||
|
|
||||
| val locationPrefRDD = new LocationPrefRDD(inputRDD, { (p: Partition) => | ||||
| if (p.index < numCoalescedPartitions) { | ||||
| Seq(locations(0)) | ||||
| } else { | ||||
| Seq(locations(1)) | ||||
| } | ||||
| }) | ||||
| val coalescedRDD = new CoalescedRDD(locationPrefRDD, numCoalescedPartitions) | ||||
|
|
||||
| val numPartsPerLocation = coalescedRDD | ||||
| .getPartitions | ||||
| .map(coalescedRDD.getPreferredLocations(_).head) | ||||
| .groupBy(identity) | ||||
| .mapValues(_.size) | ||||
|
|
||||
| // Without the fix these would be: | ||||
|
||||
| // numPartsPerLocation(locations(0)) == numCoalescedPartitions - 1 | ||||
| // numPartsPerLocation(locations(1)) == 1 | ||||
| assert(numPartsPerLocation(locations(0)) > 0.4 * numCoalescedPartitions) | ||||
|
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. How confident are we on the assert condition to be true? How is the fraction
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. nvm, the result is deterministic.
Contributor
Author
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. Added comment about flakiness & fixed seed. |
||||
| assert(numPartsPerLocation(locations(1)) > 0.4 * numCoalescedPartitions) | ||||
| } | ||||
|
|
||||
| // NOTE | ||||
| // Below tests calling sc.stop() have to be the last tests in this suite. If there are tests | ||||
| // running after them and if they access sc those tests will fail as sc is already closed, because | ||||
|
|
@@ -1210,3 +1240,16 @@ class SizeBasedCoalescer(val maxSize: Int) extends PartitionCoalescer with Seria | |||
| groups.toArray | ||||
| } | ||||
| } | ||||
|
|
||||
| /** Alters the preferred locations of the parent RDD using provided function. */ | ||||
| class LocationPrefRDD[T: ClassTag]( | ||||
| @transient var prev: RDD[T], | ||||
| val locationPicker: Partition => Seq[String]) extends RDD[T](prev) { | ||||
| override protected def getPartitions: Array[Partition] = prev.partitions | ||||
|
|
||||
| override def compute(partition: Partition, context: TaskContext): Iterator[T] = | ||||
| null.asInstanceOf[Iterator[T]] | ||||
|
|
||||
| override def getPreferredLocations(partition: Partition): Seq[String] = | ||||
| locationPicker(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.
Perhaps add comment to explain the purpose of this change here?