Skip to content

Commit 8ab6c28

Browse files
committed
Compute numTasks from job start stage infos.
1 parent 5884f91 commit 8ab6c28

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

core/src/main/scala/org/apache/spark/ui/jobs/JobProgressListener.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ class JobProgressListener(conf: SparkConf) extends SparkListener with Logging {
8585
val jobData: JobUIData =
8686
new JobUIData(jobStart.jobId, Some(System.currentTimeMillis), None, jobStart.stageIds,
8787
jobGroup, JobExecutionStatus.RUNNING)
88+
// Compute (a potential underestimate of) the number of tasks that will be run by this job:
89+
jobData.numTasks = {
90+
val allStages = jobStart.stageInfos
91+
val missingStages = allStages.filter(_.completionTime.isEmpty)
92+
missingStages.map(_.numTasks).sum
93+
}
8894
jobIdToData(jobStart.jobId) = jobData
8995
activeJobs(jobStart.jobId) = jobData
9096
for (stageId <- jobStart.stageIds) {
@@ -189,7 +195,6 @@ class JobProgressListener(conf: SparkConf) extends SparkListener with Logging {
189195
jobId <- activeJobsDependentOnStage;
190196
jobData <- jobIdToData.get(jobId)
191197
) {
192-
jobData.numTasks += stage.numTasks
193198
jobData.numActiveStages += 1
194199
}
195200
}
@@ -245,8 +250,6 @@ class JobProgressListener(conf: SparkConf) extends SparkListener with Logging {
245250
execSummary.taskTime += info.duration
246251
stageData.numActiveTasks -= 1
247252

248-
val isRecomputation = stageData.completedIndices.contains(info.index)
249-
250253
val (errorMessage, metrics): (Option[String], Option[TaskMetrics]) =
251254
taskEnd.reason match {
252255
case org.apache.spark.Success =>
@@ -279,9 +282,7 @@ class JobProgressListener(conf: SparkConf) extends SparkListener with Logging {
279282
jobData.numActiveTasks -= 1
280283
taskEnd.reason match {
281284
case Success =>
282-
if (!isRecomputation) {
283-
jobData.numCompletedTasks += 1
284-
}
285+
jobData.numCompletedTasks += 1
285286
case _ =>
286287
jobData.numFailedTasks += 1
287288
}

core/src/main/scala/org/apache/spark/ui/jobs/UIData.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ private[jobs] object UIData {
4646
var jobGroup: Option[String] = None,
4747
var status: JobExecutionStatus = JobExecutionStatus.UNKNOWN,
4848
/* Tasks */
49+
// `numTasks` is a potential underestimate of the true number of tasks that this job will run
50+
// see https://github.com/apache/spark/pull/3009 for an extensive discussion of this
4951
var numTasks: Int = 0,
5052
var numActiveTasks: Int = 0,
5153
var numCompletedTasks: Int = 0,

core/src/test/scala/org/apache/spark/ui/UISeleniumSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ class UISeleniumSuite extends FunSuite with WebBrowser with Matchers {
188188
eventually(timeout(5 seconds), interval(50 milliseconds)) {
189189
go to (sc.ui.get.appUIAddress.stripSuffix("/") + "/jobs")
190190
find(cssSelector(".stage-progress-cell")).get.text should be ("2/2 (1 failed)")
191+
// Ideally, the following test would pass, but currently we over-count completed tasks
192+
// if task recomputations occur:
193+
// find(cssSelector(".progress-cell .progress")).get.text should be ("2/2 (1 failed)")
194+
// Instead, we guarantee that the total number of tasks is always correct, while the number
195+
// of completed tasks may be higher:
196+
find(cssSelector(".progress-cell .progress")).get.text should be ("3/2 (1 failed)")
191197
}
192198
}
193199
}

0 commit comments

Comments
 (0)