-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-49386][CORE][SQL][FOLLOWUP] More accurate memory tracking for memory based spill threshold #52190
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
[SPARK-49386][CORE][SQL][FOLLOWUP] More accurate memory tracking for memory based spill threshold #52190
Changes from 2 commits
b586774
350754b
4920958
16fc9e8
8023fd3
32a744d
cc33b04
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 |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ import scala.collection.mutable.ArrayBuffer | |
|
|
||
| import org.apache.spark.{SparkEnv, TaskContext} | ||
| import org.apache.spark.internal.Logging | ||
| import org.apache.spark.internal.LogKeys.{CLASS_NAME, MAX_NUM_ROWS_IN_MEMORY_BUFFER} | ||
| import org.apache.spark.internal.LogKeys.{CLASS_NAME, MAX_NUM_ROWS_IN_MEMORY_BUFFER, NUM_BYTES_MAX} | ||
| import org.apache.spark.memory.TaskMemoryManager | ||
| import org.apache.spark.serializer.SerializerManager | ||
| import org.apache.spark.sql.catalyst.expressions.UnsafeRow | ||
|
|
@@ -44,20 +44,23 @@ import org.apache.spark.util.collection.unsafe.sort.{UnsafeExternalSorter, Unsaf | |
| * excessive disk writes. This may lead to a performance regression compared to the normal case | ||
| * of using an [[ArrayBuffer]] or [[Array]]. | ||
| */ | ||
| private[sql] class ExternalAppendOnlyUnsafeRowArray( | ||
| class ExternalAppendOnlyUnsafeRowArray( | ||
|
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. Does The previous PR added parameters in
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. other data structures (
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. I've updated the classdoc |
||
| taskMemoryManager: TaskMemoryManager, | ||
| blockManager: BlockManager, | ||
| serializerManager: SerializerManager, | ||
| taskContext: TaskContext, | ||
| initialSize: Int, | ||
| pageSizeBytes: Long, | ||
| numRowsInMemoryBufferThreshold: Int, | ||
| sizeInBytesInMemoryBufferThreshold: Long, | ||
| numRowsSpillThreshold: Int, | ||
| maxSizeSpillThreshold: Long) extends Logging { | ||
| sizeInBytesSpillThreshold: Long) extends Logging { | ||
|
|
||
| def this(numRowsInMemoryBufferThreshold: Int, | ||
| numRowsSpillThreshold: Int, | ||
| maxSizeSpillThreshold: Long) = { | ||
| def this( | ||
| numRowsInMemoryBufferThreshold: Int, | ||
| sizeInBytesInMemoryBufferThreshold: Long, | ||
| numRowsSpillThreshold: Int, | ||
| sizeInBytesSpillThreshold: Long) = { | ||
| this( | ||
| TaskContext.get().taskMemoryManager(), | ||
| SparkEnv.get.blockManager, | ||
|
|
@@ -66,8 +69,9 @@ private[sql] class ExternalAppendOnlyUnsafeRowArray( | |
| 1024, | ||
| SparkEnv.get.memoryManager.pageSizeBytes, | ||
| numRowsInMemoryBufferThreshold, | ||
| sizeInBytesInMemoryBufferThreshold, | ||
| numRowsSpillThreshold, | ||
| maxSizeSpillThreshold) | ||
| sizeInBytesSpillThreshold) | ||
| } | ||
|
|
||
| private val initialSizeOfInMemoryBuffer = | ||
|
|
@@ -78,6 +82,7 @@ private[sql] class ExternalAppendOnlyUnsafeRowArray( | |
| } else { | ||
| null | ||
| } | ||
| private var inMemoryBufferSizeInBytes = 0L | ||
|
|
||
| private var spillableArray: UnsafeExternalSorter = _ | ||
| private var totalSpillBytes: Long = 0 | ||
|
|
@@ -116,19 +121,24 @@ private[sql] class ExternalAppendOnlyUnsafeRowArray( | |
| spillableArray = null | ||
| } else if (inMemoryBuffer != null) { | ||
| inMemoryBuffer.clear() | ||
| inMemoryBufferSizeInBytes = 0; | ||
| } | ||
| numFieldsPerRow = 0 | ||
| numRows = 0 | ||
| modificationsCount += 1 | ||
| } | ||
|
|
||
| def add(unsafeRow: UnsafeRow): Unit = { | ||
| if (numRows < numRowsInMemoryBufferThreshold) { | ||
| // Once spills, we will switch to UnsafeExternalSorter permanently. | ||
| if (spillableArray == null && numRows < numRowsInMemoryBufferThreshold && | ||
| inMemoryBufferSizeInBytes < sizeInBytesSpillThreshold) { | ||
|
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. Should
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. oh I made a typo here...
cloud-fan marked this conversation as resolved.
Outdated
|
||
| inMemoryBuffer += unsafeRow.copy() | ||
| inMemoryBufferSizeInBytes += unsafeRow.getSizeInBytes | ||
| } else { | ||
| if (spillableArray == null) { | ||
| logInfo(log"Reached spill threshold of " + | ||
| log"${MDC(MAX_NUM_ROWS_IN_MEMORY_BUFFER, numRowsInMemoryBufferThreshold)} rows, " + | ||
| log"or ${MDC(NUM_BYTES_MAX, sizeInBytesInMemoryBufferThreshold)} bytes, " + | ||
| log"switching to ${MDC(CLASS_NAME, classOf[UnsafeExternalSorter].getName)}") | ||
|
|
||
| // We will not sort the rows, so prefixComparator and recordComparator are null | ||
|
|
@@ -142,7 +152,7 @@ private[sql] class ExternalAppendOnlyUnsafeRowArray( | |
| initialSize, | ||
| pageSizeBytes, | ||
| numRowsSpillThreshold, | ||
| maxSizeSpillThreshold, | ||
| sizeInBytesSpillThreshold, | ||
| false) | ||
|
|
||
| // populate with existing in-memory buffered rows | ||
|
|
@@ -156,6 +166,7 @@ private[sql] class ExternalAppendOnlyUnsafeRowArray( | |
| false) | ||
| ) | ||
| inMemoryBuffer.clear() | ||
| inMemoryBufferSizeInBytes = 0 | ||
| } | ||
| numFieldsPerRow = unsafeRow.numFields() | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.