Spark 部署提交模式意义解析

Spark 的官方从 Cluster Mode Overview 中,官方向我们介绍了 cluster 模式的部署方式。

Spark 作为独立进程在集群上运行,他们通过 SparkContext 进行协调。

SparkContext 可以通过多种方式来连接 Cluster Managers 资源调度器。我们先来看下这个集群模式的架构图

 

首先我要神明一点 standalone 也是集群模式的一种。只是说他不是通过第三方调度器比如 Yarn | Mesos  。我一直被这个名字误导,一直觉得是不是 alone 就是单机模式的意思?其实不是,他是 spark 在没有第三方调度器的情况下,自己对资源进行申请调度的一种方式。采用这种方式会有一个 Driver Program 作为 master 负责调度资源。

不管我们选用哪种第三方调度器,我们都会在获得资源之后申请 executor ,在使用 yarn 的情况下这些 executor 会分散在集群中各个  application_master 上面。

这些 spark 的 executor 会处理计算并存储你的应用信息。这个时候申请好 executor 之后我们就可以将代码通过 SC 发送到 executor 了。最后 SparkContext 会发送 task 到 executors 里面去 run 。

我们来整理一下上面提到的信息。

首先这种通过第三方调度器的是集群模式。集群模式在申请 SparkContext 的时候有很多种模式,拿 Yarn 举例。

yarn-client客户端模式 连接到 YARN 集群。需要配置 HADOOP_CONF_DIR。
yarn-cluster集群模式 连接到 YARN 集群 。需要配置 HADOOP_CONF_DIR。

这里的 yarn-client 模式简单理解就是说 我们提交任务的机器可以作为 driver 他一般在集群之中。这样的话我们提交任务之后会直接由提交任务的机器充当 driver 角色。drvier 需要在应用的整个运行周期里面都保持连接和存活。

yarn-cluster 可以理解为一个远程的提交任务的机器时候使用的参数。因为只提交任务,并不在集群种参与计算,也不充当 driver 。所以一般 yarn 会在收到这种模式任务之后,现在集群内部创建一个 driver 然后再开始上面 yarn-client 做的后续工作。

剩下的模式

local 本地单线程
local[K] 本地多线程(指定K个内核)
local[*] 本地多线程(指定所有可用内核)
spark://HOST:PORT 连接到指定的 Spark standalone cluster master,需要指定端口。
mesos:
//HOST:PORT 连接到指定的 Mesos 集群,需要指定端口。

这些参数都可以在 spark-submit --master local 这个参数里设置。对应 ss 或者 sc 应用的 

sc_conf.setMaster('local[4]')

这样的函数设置。

这里注意我们在使用 yarn 的时候如果直接写 yarn ,其实我们使用的是 yarn-client 模式。

这里还有一个关于 Deploy mode glossary

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.

 如果我需要直接让应用在本地执行,比如我使用 jupyter 调试程序。

当然可以直接在申请资源的时候设置 local 

这样的话本地环境比较可控也方便,坑也比较少 美滋滋。

 

 

Reference:

https://www.zhihu.com/question/23967309    spark在那里指定master URL呢

https://www.cnblogs.com/ITtangtang/p/7967386.html    Spark On Yarn的两种模式yarn-cluster和yarn-client深度剖析

posted @ 2019-12-11 21:03  piperck  阅读(543)  评论(0编辑  收藏  举报