Spark - 模式

为了规划和执行分布式计算,使用job概念,使用Stages和Tasks,跨工作节点执行。
Spark由driver组成,在一组工作节点上协调执行。它还负责跟踪所有工作节点,以及节点上执行的工作。

  • Driver:包含应用程序和主程序。
  • Executor:工作节点上运行的进程。Inside the executor, the individual tasks or computations are run。一个工作节点上可以有一个或多个executors,每个executor内部可以有多个tasks。当Driver连接到cluster manager,cluster manager分配资源,运行executors。

Cluster Manager负责跨节点的资源调度和分配。

how Spark works
Spark程序的主要入口是SparkContext。SparkContext在Driver组件内,代表与集群的连接,运行调度、任务分发和编排。
Spark 2.x,引入了新变量SparkSession。现在,SparkContext, SQLContext, and HiveContext 是SparkSession的成员变量。

当你启动一个Driver程序的时候,使用SparkContext将命令发布到集群,然后,executors将执行这些指令。一旦执行完成,Driver程序完成了该job。

可以使用SparkContext增加RDDs、accumulators,和在集群内广播变量。每个JVM进程内只能有一个SparkContext。在增加新的之前,必须stop()活动的SparkContext。
Driver解析代码、规划执行。When we perform any computations, the computations will actually be done at the local level by each node, using in-memory processing.

Driver coordinates the computations

Driver为任务增加Directed Acyclic Graph (DAG),DAG分stages and tasks执行。一个DAG代表一个job,job被分成子集,叫做stages,每个stage被当作tasks(one core per task)执行。
下面两图分别是一个简单job,以及DAG被分成stages and tasks。先看job

a simple job

下来是the stages in the job and the tasks:

the stages in the job and the tasks

operations的类型决定了stages的数量和组成。一般来说,transformation以及之前的工作在同一个stage,但是,每个operation(比如reduce or shuffle)总是增加新的stage。
Tasks是stage的一部分,和执行operations的core直接相关。
如果是YARN或者Mesos作为cluster manager,可以使用动态YARN调度,来增加executors的数量。

因此,driver管理整个执行过程的容错能力。一旦job完成,输出可以被写进文件、database或者控制台。

Driver程序内的代码(包括全部变量和对象)必须是完全可序列化的。经常可以看到不可序列化异常,这通常是因为从块的外部包含了全局变量。

部署

Spark支持三种部署方式:

  • Spark standalone
  • Spark on YARN
  • Spark on Mesos

In standalone mode, the client can interact with the cluster, either through spark-submit or Spark shell.
In either case, the Driver communicates with the Spark master Node to get the worker nodes, where executors can be started for this application.

Spark standalone

不依赖任何外部调度器(YARN or Mesos)。
Spark standalone uses a built-in scheduler without depending on any external scheduler such as YARN or Mesos. To install Spark in standalone mode, you have to copy the spark binary install package onto all the machines in the cluster.
下面是一个独立部署示例。
standalone deployment

此时,客户端通过spark-submit or Spark shell和cluster交互。
Driver和master Node通信,得到worker nodes。
多个客户端和cluster交互,在Worker Nodes上增加自己的executors。每个客户端有自己的Driver组件。

Spark Driver also has a Web UI, which helps you to understand everything about the Spark cluster, the executors running, the jobs and tasks, environment variables, and cache. The most important use, of course, is to monitor the jobs.

Spark on YARN

客户端和YARN资源管理交互,获得运行Spark execution的容器。可以视为仅为你部署的miniSpark-cluster。
多个客户端在cluster nodes (node managers)上增加自己的executors。
此时,每个客户端也都有自己的Driver组件。
使用YARN运行的时候,Spark在YARN-client模式,或者在YARN-cluster模式。

YARN client mode

In YARN client mode, the Driver runs on a node outside the cluster (typically where the client is).
Driver首先联系资源管理器,请求运行job的资源。然后,Driver在容器0中启动Spark application master。master在资源管理器分配的容器中增加executors,YARN容器可以在集群控制的任何节点上。因此,所有的分配都是由资源管理器管理的。
甚至Spark application master也需要和资源管理器通信,以获取后续容器。

YARN-client mode

YARN cluster mode

Driver运行在集群内的一个节点上(typically where the application master is)。Client先联系资源管理器,请求资源运行job。资源管理器分配容器。然后,client把代码提交给集群,然后启动Driver和Spark application master。Driver和master一起运行,然后在容器上增加executors。YARN容器可以在任何节点。因此,分配都由资源管理器管理。
甚至Spark application master也需要和资源管理器通信,以获取后续容器。

Yarn-cluster mode

There is no shell mode in YARN cluster mode, since the Driver itself is running inside YARN.

Spark on Mesos

Mesos deployment is similar to Spark standalone mode and the Driver communicates with the Mesos Master, which then allocates the resources needed to run the executors.As seen in standalone mode, the Driver then communicates with the executors to run the job.因此,Driver首先和master联系,然后在所有的Mesos slave nodes上确保容器的请求。
当容器分配给job的时候,然后Driver启动executors,执行代码。当job完成,Driver退出的时候,提醒Mesos master,Mesos slave nodes节点上该容器的相关资源被回收。
多个clients和集群交互,在slave节点上增加自己的executors。
每个客户端也都有自己的Driver组件。

mesos-based deployment

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值