-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-4479][SQL] Avoids unnecessary defensive copies when sort based shuffle is on #3422
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 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 |
|---|---|---|
|
|
@@ -205,6 +205,13 @@ private[spark] class ExternalSorter[K, V, C]( | |
| map.changeValue((getPartition(kv._1), kv._1), update) | ||
| maybeSpillCollection(usingMap = true) | ||
| } | ||
| } else if (bypassMergeSort) { | ||
| // SPARK-4479: Also bypass buffering if merge sort is bypassed to avoid defensive copies | ||
| if (records.hasNext) { | ||
| spillToPartitionFiles(records.map { kv => | ||
| ((getPartition(kv._1), kv._1), kv._2.asInstanceOf[C]) | ||
| }) | ||
| } | ||
| } else { | ||
| // Stick values into our buffer | ||
| while (records.hasNext) { | ||
|
|
@@ -336,6 +343,10 @@ private[spark] class ExternalSorter[K, V, C]( | |
| * @param collection whichever collection we're using (map or buffer) | ||
| */ | ||
| private def spillToPartitionFiles(collection: SizeTrackingPairCollection[(Int, K), C]): Unit = { | ||
| spillToPartitionFiles(collection.iterator) | ||
| } | ||
|
|
||
| private def spillToPartitionFiles(iterator: Iterator[((Int, K), C)]): Unit = { | ||
| assert(bypassMergeSort) | ||
|
|
||
| // Create our file writers if we haven't done so yet | ||
|
|
@@ -350,9 +361,9 @@ private[spark] class ExternalSorter[K, V, C]( | |
| } | ||
| } | ||
|
|
||
| val it = collection.iterator // No need to sort stuff, just write each element out | ||
| while (it.hasNext) { | ||
| val elem = it.next() | ||
| // No need to sort stuff, just write each element out | ||
| while (iterator.hasNext) { | ||
| val elem = iterator.next() | ||
| val partitionId = elem._1._1 | ||
| val key = elem._1._2 | ||
| val value = elem._2 | ||
|
|
@@ -748,6 +759,12 @@ private[spark] class ExternalSorter[K, V, C]( | |
|
|
||
| context.taskMetrics.memoryBytesSpilled += memoryBytesSpilled | ||
| context.taskMetrics.diskBytesSpilled += diskBytesSpilled | ||
| context.taskMetrics.shuffleWriteMetrics.filter(_ => bypassMergeSort).foreach { m => | ||
|
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 was reading through For next time, I think we should just use a simple
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. Ah, sorry for that. "Learned" this from Michael, won't do this again, lol
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. Lies 😜 I don't think I've ever written a |
||
| if (curWriteMetrics != null) { | ||
| m.shuffleBytesWritten += curWriteMetrics.shuffleBytesWritten | ||
| m.shuffleWriteTime += curWriteMetrics.shuffleWriteTime | ||
| } | ||
| } | ||
|
|
||
| lengths | ||
| } | ||
|
|
||
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.
Skipping this buffering seems to make it so that much of the rest of the
bypassMergeSort-handling code is no longer needed. For example, if we don't buffer then we won't need to spill, so we can remove the code that deals with merging spills in thebypassMergeSortcase. Based on this, I've opened #6397 to remove all of this now-unused code and to move the handling of thebypassMergeSortpath into its own file. It would be great if this PR's reviewers could look at that PR to double-check my reasoning.