You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * The active job for this result stage. Will be empty if the job has already finished * (e.g., because the job was cancelled).*/private[this] var_activeJob:Option[ActiveJob] =NonedefactiveJob:Option[ActiveJob] = _activeJob
defsetActiveJob(job: ActiveJob):Unit= {
_activeJob =Option(job)
}
defremoveActiveJob():Unit= {
_activeJob =None
}
/** * Returns the sequence of partition ids that are missing (i.e. needs to be computed). * * This can only be called when there is an active job.*/overridedeffindMissingPartitions():Seq[Int] = {
valjob= activeJob.get
(0 until job.numPartitions).filter(id =>!job.finished(id))
}
/** * Interface used to listen for job completion or failure events after submitting a job to the * DAGScheduler. The listener is notified each time a task succeeds, as well as if the whole * job fails (and no further taskSucceeded events will happen).*/private[spark] traitJobListener {
deftaskSucceeded(index: Int, result: Any):UnitdefjobFailed(exception: Exception):Unit
}
/** * Get or create the list of parent stages for a given RDD. The new Stages will be created with * the provided firstJobId.*/privatedefgetOrCreateParentStages(rdd: RDD[_], firstJobId: Int):List[Stage] = {
getShuffleDependencies(rdd).map { shuffleDep =>
getOrCreateShuffleMapStage(shuffleDep, firstJobId)
}.toList
}
/** * An interface for sort algorithm * FIFO: FIFO algorithm between TaskSetManagers * FS: FS algorithm between Pools, and FIFO or FS within Pools*/private[spark] traitSchedulingAlgorithm {
defcomparator(s1: Schedulable, s2: Schedulable):Boolean
}
/** * An interface to build Schedulable tree * buildPools: build the tree nodes(pools) * addTaskSetManager: build the leaf nodes(TaskSetManagers)*/private[spark] traitSchedulableBuilder {
defrootPool:PooldefbuildPools():UnitdefaddTaskSetManager(manager: Schedulable, properties: Properties):Unit
}
/** * A set of tasks submitted together to the low-level TaskScheduler, usually representing * missing partitions of a particular stage.*/private[spark] classTaskSet(
valtasks:Array[Task[_]],
valstageId:Int,
valstageAttemptId:Int,
valpriority:Int,
valproperties:Properties) {
valid:String= stageId +"."+ stageAttemptId
overridedeftoString:String="TaskSet "+ id
}
overrideprotecteddefhandle(m: Message):Unit= m match {
case_: Stop=>
fireStopRequest()
case _ =>thrownewIllegalArgumentException(s"Unexpected message type: ${m.getClass().getName()}")
}
7.1 调度系统概述
第一层:Cluster Manager(在YARN模式下为ResourceManager,在Mesos模式下是Mesos Master,在Standlone模式下是Master)将资源分配给Application
第二层:Application进一步将资源分配给Application的各个Task。
我们这里主要讲解第二层。
7.2 RDD 详情
更多RDD的内容,请查看 #1
7.3 Stage 详情
DAGScheduler会将Job的RDD划分到不同的stage,并构建这些stage的依赖关系。这样可以使得没有依赖关系的stage并行执行,有依赖关系的stage顺序执行。
7.3.1 ResultStage 的实现
ResultStage 可以使用指定的函数对RDD中的分区进行计算并得出最终结果。ResultStage 是最后执行的stage,此阶段主要进行作业的收尾工作。
7.3.2 ShuffleMapStage 的实现
ShuffleMapStage是DAG调度流程的中间stage,他可以包括一到多个ShuffleMapTask,这些ShuffleMapTask将生成用于Shuffle的数据。
7.3.3 StageInfo
StageInfo用于描述stage信息,并可以传递给SparkListener。StageInfo包括以下属性。
........
StageInfo 提供了一个当stage失败时要调用的方法,
stageFailed
。StageInfo 伴生对象提供了 构建stageInfo的方法。
7.4 面向DAG的调度器 DAGScheduler
JobListener 用于对作业中的每个Task执行成功或失败进行监听,JobWaiter实现了JobListener 并最终确定作业的成功或失败。
7.4.1 JobListener 与 JobWaiter
JobListener 定义了所有Job的监听器的接口规范:
JobWaiter实现了JobListener 。
7.4.2 ActiveJob 详解
ActiveJob用来表示已经激活的Job,即被DAGScheduler接收处理的Job。
7.4.3 DAGSchedulerEventProcessLoop 的简要介绍
DAGSchedulerEventProcessLoop 是DAGScheduler内部的事件循环处理器,用于处理DAGSchedulerEvent类型的事件。它能够处理的事件包括:
源码
7.4.4 DAGScheduler 的组成
7.4.5 DAGScheduler 提供的常用方法
7.4.6 DAGScheduler 与 Job的提交
用户提交的Job首先会被转换成一系列RDD,然后才交给DAGScheduler 进行处理。DAGScheduler 的runJob是这一过程的入口。
submitJob的实现。
DAGSchedulerEventProcessLoop
接收到JobSubmitted
事件后,将调用DAGScheduler 的handleJobSubmitted方法。7.4.7 构建Stage
Job中所有Stage提交过程包括反向驱动和正向提交。
7.4.7 提交ResultStage
7.4.9 提交还未计算的 Task
submitMissingTasks方法。此方法在Stage中没有不可用的父Stage时,提交当前Stage还未提交的任务。
7.4.10 DAGScheduler 的调度流程
7.4.11 Task 执行结果的处理
7.5 调度池 Pool
TaskSchedulerImpl对Task的调度依赖于调度池Pool。
7.5.1 调度算法
特质 SchedulingAlgorithm定义了调度算法的规范。
7.5.2 Pool的实现
Pool是对TaskSet进行调度的调度池。调度池内部有一个根调度队列,包含了多个子调度池。子调度池自身的调度队列中还包含其他调度池或者TaskSetManager,所以整个调度池是一个多层次的调度队列。
7.5.3 调度池构建器
SchedulableBuilder定义了调度池构建器的行为规范。
FIFOSchedulableBuilder
FairSchedulableBuilder
7.6 任务集合管理器 TaskSetManager
TaskSetManager也实现了Schedulable特质,并参与到调度池的调度当中。
7.6.1 Task集合
DAGScheduler 将Task提交到TaskScheduler 时,需要将多个Task打包问TaskSet。TaskSet是整个调度池中对Task进行调度管理的基本单位,由调度池中的TaskSetManager来管理。
7.6.2 TaskSetManager 的成员属性
7.6.3 调度池与推断执行
7.6.4 Task本地性
7.6.5 TaskSetManager 的常用的方法
7.7 运行器后端接口 LauncherBackend
7.7.1 BackendConnection的实现
BackendConnection是LauncherBackend的内部组件,用于保持与LauncherServer的Socket连接,并通过此Socket收发消息。
handle 处理LauncherServer发送的消息
close 关闭socket链接
7.7.2 LauncherBackend 的实现
LauncherBackend 是 SchedulerBackend与LauncherServer通信的组件。
7.8 调度后端接口 SchedulerBackend
SchedulerBackend是TaskScheduler的调度后端接口,TaskScheduler给Task分配资源实际上是通过SchedulerBackend来完成的,SchedulerBackend给Task分配完资源后将与分配给Task的Executor通信,并要求后者运行Task。
7.8.1 SchedulerBackend 的定义
7.8.2 LocalSchedulerBackend 的实现分析
7.9 任务结果获取器 TaskResultGetter
enqueueSuccessfulTask
enqueueFailedTask
7.10 任务调度器 TaskScheduler
The text was updated successfully, but these errors were encountered: