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

Large diffs are not rendered by default.

68 changes: 68 additions & 0 deletions core/src/main/scala/org/apache/spark/status/AppStateUtils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.status

import org.apache.spark.status.api.v1.{TaskData, TaskMetrics}

private[spark] object AppStateUtils {

def schedulerDelay(task: TaskData): Long = {
if (task.taskMetrics.isDefined && task.duration.isDefined) {
val m = task.taskMetrics.get
schedulerDelay(task.launchTime.getTime(), fetchStart(task), task.duration.get,
m.executorDeserializeTime, m.resultSerializationTime, m.executorRunTime)
} else {
0L
}
}

def gettingResultTime(task: TaskData): Long = {
gettingResultTime(task.launchTime.getTime(), fetchStart(task), task.duration.getOrElse(-1L))
}

def schedulerDelay(
launchTime: Long,
fetchStart: Long,
duration: Long,
deserializeTime: Long,
serializeTime: Long,
runTime: Long): Long = {
math.max(0, duration - runTime - deserializeTime - serializeTime -
gettingResultTime(launchTime, fetchStart, duration))
}

def gettingResultTime(launchTime: Long, fetchStart: Long, duration: Long): Long = {
if (fetchStart > 0) {
if (duration > 0) {
launchTime + duration - fetchStart
} else {
System.currentTimeMillis() - fetchStart
}
} else {
0L
}
}

private def fetchStart(task: TaskData): Long = {
if (task.resultFetchStart.isDefined) {
task.resultFetchStart.get.getTime()
} else {
-1
}
}
}
48 changes: 32 additions & 16 deletions core/src/main/scala/org/apache/spark/status/AppStatusListener.scala
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ private[spark] class AppStatusListener(
Option(liveStages.get((event.stageId, event.stageAttemptId))).foreach { stage =>
stage.activeTasks += 1
stage.firstLaunchTime = math.min(stage.firstLaunchTime, event.taskInfo.launchTime)

val locality = event.taskInfo.taskLocality.toString()
val count = stage.localitySummary.getOrElse(locality, 0L) + 1L
stage.localitySummary = stage.localitySummary ++ Map(locality -> count)
maybeUpdate(stage, now)

stage.jobs.foreach { job =>
Expand Down Expand Up @@ -402,7 +406,7 @@ private[spark] class AppStatusListener(

val now = System.nanoTime()

val metricsDelta = liveTasks.remove(event.taskInfo.taskId).map { task =>
val (updatedTask, metricsDelta) = liveTasks.remove(event.taskInfo.taskId).map { task =>
task.info = event.taskInfo

val errorMessage = event.reason match {
Expand All @@ -420,9 +424,10 @@ private[spark] class AppStatusListener(
}
task.errorMessage = errorMessage
val delta = task.updateMetrics(event.taskMetrics)
update(task, now)
delta
}.orNull
(task.updateAndGet(kvstore, now), delta)
}.getOrElse {
(null, null)
}

val (completedDelta, failedDelta, killedDelta) = event.reason match {
case Success =>
Expand All @@ -437,7 +442,7 @@ private[spark] class AppStatusListener(

Option(liveStages.get((event.stageId, event.stageAttemptId))).foreach { stage =>
if (metricsDelta != null) {
stage.metrics.update(metricsDelta)
stage.metrics.add(metricsDelta)
}
stage.activeTasks -= 1
stage.completedTasks += completedDelta
Expand Down Expand Up @@ -473,7 +478,7 @@ private[spark] class AppStatusListener(
esummary.failedTasks += failedDelta
esummary.killedTasks += killedDelta
if (metricsDelta != null) {
esummary.metrics.update(metricsDelta)
esummary.metrics.add(metricsDelta)
}
maybeUpdate(esummary, now)

Expand Down Expand Up @@ -584,11 +589,11 @@ private[spark] class AppStatusListener(
maybeUpdate(task, now)

Option(liveStages.get((sid, sAttempt))).foreach { stage =>
stage.metrics.update(delta)
stage.metrics.add(delta)
maybeUpdate(stage, now)

val esummary = stage.executorSummary(event.execId)
esummary.metrics.update(delta)
esummary.metrics.add(delta)
maybeUpdate(esummary, now)
}
}
Expand Down Expand Up @@ -670,7 +675,7 @@ private[spark] class AppStatusListener(
// can update the executor information too.
liveRDDs.get(block.rddId).foreach { rdd =>
if (updatedStorageLevel.isDefined) {
rdd.storageLevel = updatedStorageLevel.get
rdd.setStorageLevel(updatedStorageLevel.get)
}

val partition = rdd.partition(block.name)
Expand Down Expand Up @@ -844,7 +849,7 @@ private[spark] class AppStatusListener(
}

stages.foreach { s =>
val key = s.id
val key = Array(s.info.stageId, s.info.attemptId)
kvstore.delete(s.getClass(), key)

val execSummaries = kvstore.view(classOf[ExecutorStageSummaryWrapper])
Expand All @@ -864,15 +869,15 @@ private[spark] class AppStatusListener(
.asScala

tasks.foreach { t =>
kvstore.delete(t.getClass(), t.info.taskId)
kvstore.delete(t.getClass(), t.taskId)
}

// Check whether there are remaining attempts for the same stage. If there aren't, then
// also delete the RDD graph data.
val remainingAttempts = kvstore.view(classOf[StageDataWrapper])
.index("stageId")
.first(s.stageId)
.last(s.stageId)
.first(s.info.stageId)
.last(s.info.stageId)
.closeableIterator()

val hasMoreAttempts = try {
Expand All @@ -884,7 +889,18 @@ private[spark] class AppStatusListener(
}

if (!hasMoreAttempts) {
kvstore.delete(classOf[RDDOperationGraphWrapper], s.stageId)
kvstore.delete(classOf[RDDOperationGraphWrapper], s.info.stageId)
}

// Clean up cached quantiles for the stage attempt.
val cachedQuantiles = kvstore.view(classOf[CachedQuantile])
.index("stage")
.first(key)
.last(key)
.asScala
.toList
cachedQuantiles.foreach { q =>
kvstore.delete(q.getClass(), q.id)
}
}
}
Expand All @@ -899,9 +915,9 @@ private[spark] class AppStatusListener(
// On live applications, try to delete finished tasks only; when in the SHS, treat all
// tasks as the same.
val toDelete = KVUtils.viewToSeq(view, countToDelete.toInt) { t =>
!live || t.info.status != TaskState.RUNNING.toString()
!live || t.status != TaskState.RUNNING.toString()
}
toDelete.foreach { t => kvstore.delete(t.getClass(), t.info.taskId) }
toDelete.foreach { t => kvstore.delete(t.getClass(), t.taskId) }
stage.savedTasks.addAndGet(-toDelete.size)
}
stage.cleaning = false
Expand Down
Loading