TermMeaning
ApplicationUser program built on Spark. Consists of a driver program and executors on the cluster.
Application jarA jar containing the user's Spark application. In some cases users will want to create an "uber jar" containing their application along with its dependencies. The user's jar should never include Hadoop or Spark libraries, however, these will be added at runtime.
Driver programThe process running the main() function of the application and creating the SparkContext
Cluster managerAn external service for acquiring resources on the cluster (e.g. standalone manager, Mesos, YARN)
Deploy modeDistinguishes where the driver process runs. In "cluster" mode, the framework launches the driver inside of the cluster. In "client" mode, the submitter launches the driver outside of the cluster.
Worker nodeAny node that can run application code in the cluster
ExecutorA process launched for an application on a worker node, that runs tasks and keeps data in memory or disk storage across them. Each application has its own executors.
TaskA unit of work that will be sent to one executor
JobA parallel computation consisting of multiple tasks that gets spawned in response to a Spark action (e.g. savecollect); you'll see this term used in the driver's logs.
StageEach job gets divided into smaller sets of tasks called stages that depend on each other (similar to the map and reduce stages in MapReduce); you'll see this term used in the driver's logs.
Spark有三种模式的部署,YARN,Standalone,Mesos。worker只在Standalone模式才有。Worker节点是Spark的工作节点,用于执行提交的作业。

###基于standalone的Spark架构与作业执行流程
Standalone模式下,集群启动时包括Master与Worker,其中Master负责接收客户端提交的作业,管理Worker。提供了Web展示集群与作业信息。
 
**名词解释:**
 
**1. Standalone模式下存在的角色。**
 
Client:客户端进程,负责提交作业到Master。
 
Master:Standalone模式中主控节点,负责接收Client提交的作业,管理Worker,并命令Worker启动Driver和Executor。
 
Worker:Standalone模式中slave节点上的守护进程,负责管理本节点的资源,定期向Master汇报心跳,接收Master的命令,启动Driver和Executor。
 
Driver: 一个Spark作业运行时包括一个Driver进程,也是作业的主进程,负责作业的解析、生成Stage并调度Task到Executor上。包括DAGScheduler,TaskScheduler。
 
Executor:即真正执行作业的地方,一个集群一般包含多个Executor,每个Executor接收Driver的命令Launch Task,一个Executor可以执行一到多个Task。

worker可以理解为实体机,Executor可以理解为一个进程,Executor是真正执行任务的单元。
 
**2.作业相关的名词解释**
 
Stage:一个Spark作业一般包含一到多个Stage。
 
Task:一个Stage包含一到多个Task,通过多个Task实现并行运行的功能。
 
DAGScheduler: 实现将Spark作业分解成一到多个Stage,每个Stage根据RDD的Partition个数决定Task的个数,然后生成相应的Task set放到TaskScheduler中。
 
TaskScheduler:实现Task分配到Executor上执行。
任务调度关系:首先利用DAGSchedule将用户提交的作业划分为多个stage并将Stage划分成不同的TaskSet,接着利用TaskSchedule将每个Stage


Stage和Task的关系:Stage可以理解为一个mapreduce处理,每个stage里的task都可以在一个executor中完成而不需要shuffle。其实划分stage的标准就是看是否发生了shuffle。

那么Executor和Stage的关系其实也比较明朗了,Stage是逻辑上的,Executor是实体,TaskSchedule将Stage中的Task分配到Executor中执行。


###提交作业
作业就是指用户的提交的程序。根据Driver的运行方式可以分为两种,Driver(作业的master,负责作业的解析、生成stage并调度task到,包含DAGScheduler)运行在Worker上,Driver运行在客户端。

**Driver运行在Worker上**
通过org.apache.spark.deploy.Client类执行作业,作业运行命令如下:
  ./bin/spark-class org.apache.spark.deploy.Client launch spark://host:port file:///jar_url org.apache.spark.examples.SparkPi spark://host:port


作业流程图

作业执行流程描述:
客户端提交作业给Master。Master让一个Worker启动Driver,即SchedulerBackend。Worker创建一个DriverRunner线程,DriverRunner启动SchedulerBackend进程。 另外Master还会让其余Worker启动Exeuctor,即ExecutorBackend。Worker创建一个ExecutorRunner线程,ExecutorRunner会启动ExecutorBackend进程。 ExecutorBackend启动后会向Driver的SchedulerBackend注册。SchedulerBackend进程中包含DAGScheduler,它会根据用户程序,生成执行计划,并调度执行。对于每个stage的task,都会被存放到TaskScheduler中,ExecutorBackend向SchedulerBackend汇报的时候把TaskScheduler中的task调度到ExecutorBackend执行。 所有stage都完成后作业结束。

**Driver运行在Client**
所谓的Client其实就是指用户提交作业的那台机子。Driver运行在客户端的,一般直接执行Spark作业,作业运行命令如下(示例):
 
 ./bin/run-example org.apache.spark.examples.SparkPi spark://host:port
流程图

作业执行流程描述:
客户端启动后直接运行用户程序,启动Driver相关的工作:DAGScheduler和BlockManagerMaster等。 客户端的Driver向Master注册。 Master还会让Worker启动Exeuctor。Worker创建一个ExecutorRunner线程,ExecutorRunner会启动ExecutorBackend进程。 ExecutorBackend启动后会向Driver的SchedulerBackend注册。Driver的DAGScheduler解析作业并生成相应的Stage,每个Stage包含的Task通过TaskScheduler分配给Executor执行。 所有stage都完成后作业结束。











posted on 2017-03-05 12:08  sunrye  阅读(3205)  评论(0编辑  收藏  举报