Term | Meaning |
---|---|
Application | User program built on Spark. Consists of a driver program and executors on the cluster. |
Application jar | A 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 program | The process running the main() function of the application and creating the SparkContext |
Cluster manager | An external service for acquiring resources on the cluster (e.g. standalone manager, Mesos, YARN) |
Deploy mode | Distinguishes 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 node | Any node that can run application code in the cluster |
Executor | A 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. |
Task | A unit of work that will be sent to one executor |
Job | A parallel computation consisting of multiple tasks that gets spawned in response to a Spark action (e.g. save , collect ); you'll see this term used in the driver's logs. |
Stage | Each 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. |
###基於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都完成后作業結束。