Spark的三种提交模式
- Spark内核架构,其实就是第一种模式,standalone模式,基于Spark自己的Master-Worker集群。
- 第二种,是基于YARN的yarn-cluster模式。
- 第三种,是基于YARN的yarn-client模式。
如果,你要切换到第二种和第三种模式,很简单,将我们之前用于提交spark应用程序的spark-submit脚本,加上--master参数,设置为yarn-cluster,或yarn-client,即可。如果你没设置,那么,就是standalone模式。
yarn-cluster模式
首先看看yarn-cluster模式
基于yarn-cluster提交模式深度剖析.png
流程详细分析
spark-submit提交(yarn-cluster),发送请求到ResourceManager,请求启动ApplicationMaster,ResourceManager接收到请求后,会在某个NodeManager上分配container,启动ApplicationMaster
ResourceManager分配Container,在某个NodeManager上,启动ApplicationMaster
ApplicationMaster(相当于是Driver)
ApplicationMaster找ResourceManager,请求container,启动Executor
ResourceManager分配一批container,用于启动Executor
ApplicationMaster所在的NodeManager上,可能会启动Executor
ApplicationMaster连接其他NodeManager,来启动Executor,这里的NameNode相当于Wroker
Executor启动后,向ApplicationMaster反向注册
yarn-client模式
接下来看yarn-client模式
基于yarn-client提交模式深度剖析.png
流程详细分析
spark-submit提交(yarn-client),会在本地启动Driver进程
发送给ResourceManager,请求启动ApplicationMaster
ResourceManager分配Container,在某个NodeManager上启动ApplicationMaster,但这里的ApplicationMaster,其实只是一个ExecutorLauncher
ExecutorLauncher(ApplicationMaster)申请Container,启动executor
ResourceManager分配一批Container
ExecutorLauncher(ApplicationMaster)所在的NodeManager上,可能会启动Executor
ExecutorLauncher(ApplicationMaster)连接其他NodeManager,用Container资源,启动Executor
Executor反向注册到本地的Driver上
两种模式的区别
yarn-client模式用于测试,因为driver运行在本地客户端,负责调度application,会与yarn集群产生超大量的网络通信,从而导致网卡流量激增,可能会被公司的运维给警告,好处在于,直接执行时,本地可以看到所有log,方便调试
yarn-cluster,用于生产环境,因为driver运行在NodeManager,没有网卡流量激增的问题,缺点在于,调试不方便,本地用spark-submit提交后,看不到log,只能通过yarn application -logs application_id这种命令来查看,很麻烦
实战
两个脚本文件
yarn-client
/opt/module/spark/bin/spark-submit \
--class com.zj.spark.core.WordCountCluster \
--master yarn-client \
--num-executors 3 \
--driver-memory 100m \
--executor-memory 100m \
--executor-cores 3 \
/opt/module/datas/sparkstudy/java/mysparkstudy-1.0-SNAPSHOT-jar-with-dependencies.jar \
yarn-cluster
/opt/module/spark/bin/spark-submit \
--class com.zj.spark.core.WordCountCluster \
--master yarn-cluster \
--num-executors 3 \
--driver-memory 100m \
--executor-memory 100m \
--executor-cores 3 \
/opt/module/datas/sparkstudy/java/mysparkstudy-1.0-SNAPSHOT-jar-with-dependencies.jar \