Skip to content
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

Initial attempt to rightsize executor memory #3

Open
wants to merge 1 commit into
base: oss-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ class StageSkewAnalyzer extends AppAnalyzer {
}


// Copied from Spark
def byteFromString(str: String): Long = {
val unit = 1L << 20 // MiB see ByteUnit.java
val (input, multiplier) =
if (str.length() > 0 && str.charAt(0) == '-') {
(str.substring(1), -1)
} else {
(str, 1)
}
multiplier * JavaUtils.byteStringAs(input, unit)
}

def bytesToString(size: Long): String = {
val TB = 1L << 40
val GB = 1L << 30
Expand Down Expand Up @@ -123,7 +135,33 @@ class StageSkewAnalyzer extends AppAnalyzer {
if (! problamaticCoalesces.isEmpty) {
suggested += (("spark.sql.adaptive.coalescePartitions.enabled", "false"))
}
suggested.toMap
// Suggest decreasing the amount of executor memory if it looks like we are over allocated.
// https://spark.apache.org/docs/latest/configuration.html#memory-management documents the options
// Note: we need to careful with resource profiles here.
val safetyMargin = 1.2
val minChange = byteFromString("100M")
val memoryFraction = conf.getOrElse("spark.memory.fraction", "0.6").toDouble
val idealTargetMemories = ac.stageMap.values.map { s =>
val rpId = s.resourceProfileId
val peakMemory = s.taskPeakMemoryUsage.max
// This is how much we want to have for the RDDs and user objects
val targetUserSize = peakMemory * safetyMargin
val targetExecMemorySize = targetUserSize / memoryFraction
(rpId, targetExecMemorySize)
}.groupBy(_._1).mapValues(_._2.max)
// Go through the target memories and output if and only if we'd change the config
idealTargetMemories.foreach {
case (rpId, target) =>
// Resource profile zero is the general case
// TODO: Make recommendations for other resource profiles, maybe.
if (rpId == 0) {
val existingMemory = byteFromString(conf.getOrElse("spark.executor.memory", "2g"))
if (target < existingMemory - minChange) {
suggested += (("spark.executor.memory", bytesToString(target)))
}
}
}
suggested
}

def computePerStageEfficiencyStatistics(ac: AppContext, out: mutable.StringBuilder): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import scala.collection.mutable
This keeps track of data per stage
*/

class StageTimeSpan(val stageID: Int, numberOfTasks: Long, val sqlTask: Boolean) extends TimeSpan {
class StageTimeSpan(val stageID: Int, numberOfTasks: Long, val sqlTask: Boolean, val rpId: Int) extends TimeSpan {
var stageMetrics = new AggregateMetrics()
// We actually want to keep the start times so we can suggest increasing
// max execs if we see very different start times since that can
Expand Down