Skip to content

Adds aggregation across metrics for failed/succeeded and non completed stages #1558

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

Merged
merged 14 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -321,7 +321,7 @@ class AppSparkMetricsAnalyzer(app: AppBase) extends AppAnalysisBase(app) {
val emptyNodeNames = Seq.empty[String]
val emptyDiagnosticMetrics = HashMap.empty[String, AccumProfileResults]
// TODO: this has stage attempts. we should handle different attempts
app.stageManager.getAllStages.map { sm =>
app.stageManager.getAllCompletedStages.map { sm =>
// TODO: Should we only consider successful tasks?
val tasksInStage = app.taskManager.getTasks(sm.stageInfo.stageId,
sm.stageInfo.attemptNumber())
Expand Down Expand Up @@ -358,13 +358,12 @@ class AppSparkMetricsAnalyzer(app: AppBase) extends AppAnalysisBase(app) {
}

/**
* Aggregates the SparkMetrics by stage. This is an internal method to populate the cached metrics
* Aggregates the SparkMetrics by completed stage information.
* This is an internal method to populate the cached metrics
* to be used by other aggregators.
* @param index AppIndex (used by the profiler tool)
*/
private def aggregateSparkMetricsByStageInternal(index: Int): Unit = {
// TODO: this has stage attempts. we should handle different attempts

// For Photon apps, peak memory and shuffle write time need to be calculated from accumulators
// instead of task metrics.
// Approach:
Expand Down Expand Up @@ -392,7 +391,7 @@ class AppSparkMetricsAnalyzer(app: AppBase) extends AppAnalysisBase(app) {
}
}

app.stageManager.getAllStages.foreach { sm =>
app.stageManager.getAllCompletedStages.foreach { sm =>
// TODO: Should we only consider successful tasks?
val tasksInStage = app.taskManager.getTasks(sm.stageInfo.stageId,
sm.stageInfo.attemptNumber())
Expand Down Expand Up @@ -447,7 +446,16 @@ class AppSparkMetricsAnalyzer(app: AppBase) extends AppAnalysisBase(app) {
perStageRec.swBytesWrittenSum,
perStageRec.swRecordsWrittenSum,
perStageRec.swWriteTimeSum) // converted to milliseconds by the aggregator
stageLevelSparkMetrics(index).put(sm.stageInfo.stageId, stageRow)
val existingStageProfileEntry = stageLevelSparkMetrics(index).get(sm.stageInfo.stageId)
if (existingStageProfileEntry.isDefined) {
// We already have a profile entry for this stage.
// Basically this means we have multiple attempts for the same stage.
// We need to aggregate the metrics from the new attempt with the existing one
val aggregatedStageProfileEntry = existingStageProfileEntry.get.aggregateWith(stageRow)
stageLevelSparkMetrics(index).put(sm.stageInfo.stageId, aggregatedStageProfileEntry)
} else {
stageLevelSparkMetrics(index).put(sm.stageInfo.stageId, stageRow)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,52 @@ case class StageAggTaskMetricsProfileResult(
swRecordsWrittenSum: Long,
swWriteTimeSum: Long // milliseconds
) extends BaseJobStageAggTaskMetricsProfileResult {

def aggregateWith(other: StageAggTaskMetricsProfileResult): StageAggTaskMetricsProfileResult = {
// This assert ensures only two StageAggTaskMetricsProfileResult which
// have the same id are aggregated. This is important because we retain the
// id and appIndex of the first stage.
assert(this.id == other.id && this.appIndex == other.appIndex)
StageAggTaskMetricsProfileResult(
appIndex = this.appIndex,
id = this.id,
numTasks = this.numTasks + other.numTasks,
duration = Option(this.duration.getOrElse(0L) + other.duration.getOrElse(0L)),
diskBytesSpilledSum = this.diskBytesSpilledSum + other.diskBytesSpilledSum,
durationSum = this.durationSum + other.durationSum,
durationMax = Math.max(this.durationMax, other.durationMax),
durationMin = Math.min(this.durationMin, other.durationMin),
durationAvg = (this.durationAvg + other.durationAvg) / 2,
executorCPUTimeSum = this.executorCPUTimeSum + other.executorCPUTimeSum,
executorDeserializeCpuTimeSum = this.executorDeserializeCpuTimeSum +
other.executorDeserializeCpuTimeSum,
executorDeserializeTimeSum = this.executorDeserializeTimeSum +
other.executorDeserializeTimeSum,
executorRunTimeSum = this.executorRunTimeSum + other.executorRunTimeSum,
inputBytesReadSum = this.inputBytesReadSum + other.inputBytesReadSum,
inputRecordsReadSum = this.inputRecordsReadSum + other.inputRecordsReadSum,
jvmGCTimeSum = this.jvmGCTimeSum + other.jvmGCTimeSum,
memoryBytesSpilledSum = this.memoryBytesSpilledSum + other.memoryBytesSpilledSum,
outputBytesWrittenSum = this.outputBytesWrittenSum + other.outputBytesWrittenSum,
outputRecordsWrittenSum = this.outputRecordsWrittenSum + other.outputRecordsWrittenSum,
peakExecutionMemoryMax = Math.max(this.peakExecutionMemoryMax, other.peakExecutionMemoryMax),
resultSerializationTimeSum = this.resultSerializationTimeSum +
other.resultSerializationTimeSum,
resultSizeMax = Math.max(this.resultSizeMax, other.resultSizeMax),
srFetchWaitTimeSum = this.srFetchWaitTimeSum + other.srFetchWaitTimeSum,
srLocalBlocksFetchedSum = this.srLocalBlocksFetchedSum + other.srLocalBlocksFetchedSum,
srRemoteBlocksFetchSum = this.srRemoteBlocksFetchSum + other.srRemoteBlocksFetchSum,
srRemoteBytesReadSum = this.srRemoteBytesReadSum + other.srRemoteBytesReadSum,
srRemoteBytesReadToDiskSum = this.srRemoteBytesReadToDiskSum +
other.srRemoteBytesReadToDiskSum,
srTotalBytesReadSum = this.srTotalBytesReadSum + other.srTotalBytesReadSum,
srcLocalBytesReadSum = this.srcLocalBytesReadSum + other.srcLocalBytesReadSum,
swBytesWrittenSum = this.swBytesWrittenSum + other.swBytesWrittenSum,
swRecordsWrittenSum = this.swRecordsWrittenSum + other.swRecordsWrittenSum,
swWriteTimeSum = this.swWriteTimeSum + other.swWriteTimeSum
)
}

override def idHeader = "stageId"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class StageModel private(sInfo: StageInfo) {
stageInfo.failureReason.isDefined
}

def hasCompleted: Boolean = {
stageInfo.completionTime.isDefined
}

def getFailureReason: String = {
stageInfo.failureReason.getOrElse("")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,6 +53,18 @@ class StageModelManager extends Logging {
*/
def getAllStages: Iterable[StageModel] = stageIdToInfo.values.flatMap(_.values)

/**
* Returns all successful StageModels that have been created as a result of handling
* StageSubmitted/StageCompleted-events.
*
* @return Iterable of all successful StageModels
*/
def getAllCompletedStages: Iterable[StageModel] = {
stageIdToInfo.values.flatMap(_.values).filter(stage => {
stage.hasCompleted && !stage.hasFailed
})
}

/**
* Returns all Ids of stage objects created as a result of handling StageSubmitted/StageCompleted.
*
Expand Down