Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/2416#discussion_r17924149
--- Diff:
core/src/main/scala/org/apache/spark/util/collection/ExternalSorter.scala ---
@@ -232,35 +224,18 @@ private[spark] class ExternalSorter[K, V, C](
return
}
- val collection: SizeTrackingPairCollection[(Int, K), C] = if
(usingMap) map else buffer
-
- // TODO: factor this out of both here and ExternalAppendOnlyMap
- if (elementsRead > trackMemoryThreshold && elementsRead % 32 == 0 &&
- collection.estimateSize() >= myMemoryThreshold)
- {
- // Claim up to double our current memory from the shuffle memory pool
- val currentMemory = collection.estimateSize()
- val amountToRequest = 2 * currentMemory - myMemoryThreshold
- val granted = shuffleMemoryManager.tryToAcquire(amountToRequest)
- myMemoryThreshold += granted
- if (myMemoryThreshold <= currentMemory) {
- // We were granted too little memory to grow further (either
tryToAcquire returned 0,
- // or we already had more memory than myMemoryThreshold); spill
the current collection
- spill(currentMemory, usingMap) // Will also release memory back
to ShuffleMemoryManager
- }
+ if (usingMap) {
+ map = maybeSpill(map)
+ } else {
+ buffer = maybeSpill(buffer)
}
}
/**
* Spill the current in-memory collection to disk, adding a new file to
spills, and clear it.
- *
- * @param usingMap whether we're using a map or buffer as our current
in-memory collection
*/
- private def spill(memorySize: Long, usingMap: Boolean): Unit = {
- val collection: SizeTrackingPairCollection[(Int, K), C] = if
(usingMap) map else buffer
+ protected[this] def spill[A <: SizeTrackingPairCollection[(Int, K),
C]](collection: A): A = {
val memorySize = collection.estimateSize()
-
- spillCount += 1
val threadId = Thread.currentThread().getId
logInfo("Thread %d spilling in-memory batch of %d MB to disk (%d
spill%s so far)"
.format(threadId, memorySize / (1024 * 1024), spillCount, if
(spillCount > 1) "s" else ""))
--- End diff --
Not your code, but this message is also identical across both places. Maybe
move them into the parent `spill` as well?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]