Spark Standalone模式提交任务

  Cluster模式:

./spark-submit  \
--master spark://node01:7077  \
--deploy-mode cluster 
--class org.apache.spark.examples.SparkPi \
--driver-memory 1g \
--executor-memory 1g \
--executor-cores 2 \
../lib/spark-examples-1.6.0-hadoop2.6.0.jar  100

  • 执行流程

1、cluster模式提交应用程序后,会向Master请求启动Driver.(而不是启动application)

2、Master接受请求,随机在集群一台节点启动Driver进程。

3、Driver启动后为当前的应用程序申请资源。Master返回资源,并在对应的worker节点上发送消息启动Worker中的executor进程。

4、Driver端发送task到worker节点上执行。

5、worker将执行情况和执行结果返回给Driver端。Driver监控task任务,并回收结果。

  • 总结

1、当在客户端提交多个application时,Driver会在Woker节点上随机启动,这种模式会将单节点的网卡流量激增问题分散到集群中在客户端看不到task执行情况和结果。要去webui中看。cluster模式适用于生产环境

          2、 Master模式先启动Driver,再启动Application。

  Client模式:

 ./spark-submit \
--master spark://node01:7077 \
--class org.apache.spark.examples.SparkPi \
--driver-memory 1g \
--executor-memory 1g \
--executor-cores 2 \
../lib/spark-examples-1.6.0-hadoop2.6.0.jar 100

---------------------------------------------------------------------
./spark-submit \
--master spark://node01:7077 \
--deploy-mode client \
--class org.apache.spark.examples.SparkPi \
--driver-memory 1g \
--executor-memory 1g \
--executor-cores 2 \
../lib/spark-examples-1.6.0-hadoop2.6.0.jar 100

  • 执行流程

1、client模式提交任务后,会在客户端启动Driver进程。

2、Driver会向Master申请启动Application启动的资源。

3、资源申请成功,Driver端将task发送到worker端执行

4、worker将task执行结果返回到Driver端。

  • 总结

    1、client模式适用于测试调试程序。Driver进程是在客户端启动的,这里的客户端就是指提交应用程序的当前节点。在Driver端可以看到task执行的情况。生产环境下不能使用client模式,是因为:假设要提交100个application到集群运行,Driver每次都会在client端启动,那么就会导致客户端100次网卡流量暴增的问题。(因为要监控task的运行情况,会占用很多端口,如上图的结果图)客户端网卡通信,都被task监控信息占用。

    2、Client端作用

1. Driver负责应用程序资源的申请

2. 任务的分发。

3. 结果的回收。

4. 监控task执行情况。

Spark on yarn模式提交任务  

  官方文档:http://spark.apache.org/docs/latest/running-on-yarn.html

  Spark-Yarn  Cluster模式:

./bin/spark-submit --class org.apache.spark.examples.SparkPi \
--master yarn \
--deploy-mode cluster \
--driver-memory 1g \
--executor-memory 1g \
--executor-cores \
--queue default \
lib/spark-examples*.jar \ ---------------------------------------------------------------------------------------------------------------------------------
./bin/spark-submit --class cn.edu360.spark.day1.WordCount \
--master yarn \
--deploy-mode cluster \
--driver-memory 1g \
--executor-memory 1g \
--executor-cores \
--queue default \
/home/bigdata/hello-spark-1.0.jar \
hdfs://node-1.edu360.cn:9000/wc hdfs://node-1.edu360.cn:9000/out-yarn-1

  Spark-yarn Cluster集群模式原理

    Spark Driver首先作为一个ApplicationMaster在YARN集群中启动,客户端提交给ResourceManager的每一个job都会在集群的NodeManager节点上分配一个唯一的ApplicationMaster,由该ApplicationMaster管理全生命周期的应用。具体过程:

. 由client向ResourceManager提交请求,并上传jar到HDFS上
  这期间包括四个步骤:
    a).连接到RM
    b).从RM的ASM(ApplicationsManager )中获得metric、queue和resource等信息。
    c). upload app jar and spark-assembly jar
    d).设置运行环境和container上下文(launch-container.sh等脚本)
. ResouceManager向NodeManager申请资源,创建Spark ApplicationMaster(每个SparkContext都有一个ApplicationMaster)
. NodeManager启动ApplicationMaster,并向ResourceManager AsM注册
. ApplicationMaster从HDFS中找到jar文件,启动SparkContext、DAGscheduler和YARN Cluster Scheduler
. ResourceManager向ResourceManager AsM注册申请container资源
. ResourceManager通知NodeManager分配Container,这时可以收到来自ASM关于container的报告。(每个container对应一个executor)
. Spark ApplicationMaster直接和container(executor)进行交互,完成这个分布式任务。

  Spark-Yarn   Client模式:

./bin/spark-submit --class org.apache.spark.examples.SparkPi \
--master yarn \
--deploy-mode client \
--driver-memory 1g \
--executor-memory 1g \
--executor-cores \
--queue default \
lib/spark-examples*.jar \ spark-shell必须使用client模式
./bin/spark-shell --master yarn --deploy-mode client

实际案例:在YARN模式,executor-cores和executor-memory的设置对调度计算机的性能作用很重要

$ ./bin/spark-submit \
--class cn.cstor.face.BatchCompare \
--master yarn \
--deploy-mode client \
--executor-memory 30G \
--executor-cores 20 \
--properties-file $BIN_DIR/conf/cstor-spark.properties \
cstor-deep-1.0-SNAPSHOT.jar

在client模式下,Driver运行在Client上,通过ApplicationMaster向RM获取资源。本地Driver负责与所有的executor container进行交互,并将最后的结果汇总。结束掉终端,相当于kill掉这个spark应用。一般来说,如果运行的结果仅仅返回到terminal上时需要配置这个。

客户端的Driver将应用提交给Yarn后,Yarn会先后启动ApplicationMaster和executor,另外ApplicationMaster和executor都 是装载在container里运行,container默认的内存是1G,ApplicationMaster分配的内存是driver- memory,executor分配的内存是executor-memory。同时,因为Driver在客户端,所以程序的运行结果可以在客户端显 示,Driver以进程名为SparkSubmit的形式存在。

如果使用spark on yarn 提交任务,一般情况,都使用cluster模式,该模式,Driver运行在集群中,其实就是运行在ApplicattionMaster这个进程成,如果该进程出现问题,yarn会重启ApplicattionMaster(Driver),SparkSubmit的功能就是为了提交任务。

如果使用交换式的命令行,必须用Client模式,该模式,Driver是运行在SparkSubmit进程中,因为收集的结果,必须返回到命令行(即启动命令的那台机器上),该模式,一般测试,或者运行spark-shell、spark-sql这个交互式命令行是使用

注意:如果你配置spark-on-yarn的client模式,其实会报错。
修改所有yarn节点的yarn-site.xml,在该文件中添加如下配置 <property>
<name>yarn.nodemanager.pmem-check-enabled</name>
<value>false</value>
</property> <property>
<name>yarn.nodemanager.vmem-check-enabled</name>
<value>false</value>
</property>

   两种模式的区别(yarn):

    cluster模式:Driver程序在Yarn中运行,应用的运行结果不能在客户端显示,所以最好运行那些将结果最终保存在外部存储介质(如HDFS,Redis,MySQL)而非stdout输出的应用程序,客户端的终端显示的仅是作为Yarn的job的简单运行状况.

    client模式:Driver运行在Client上,应用程序运行结果会在客户端显示,所有适合运行结果又输出的应用程序(Spark-shell)

  Spark-Submit 参数详解:

  --master MASTER_URL         spark://host:port, mesos://host:port, yarn, or local.
--deploy-mode DEPLOY_MODE Whether to launch the driver program locally ("client") or
on one of the worker machines inside the cluster ("cluster")
(Default: client).
--class CLASS_NAME Your application's main class (for Java / Scala apps).
--name NAME A name of your application.
--jars JARS Comma-separated list of local jars to include on the driver
and executor classpaths.
--packages Comma-separated list of maven coordinates of jars to include
on the driver and executor classpaths. Will search the local
maven repo, then maven central and any additional remote
repositories given by --repositories. The format for the
coordinates should be groupId:artifactId:version.
--exclude-packages Comma-separated list of groupId:artifactId, to exclude while
resolving the dependencies provided in --packages to avoid
dependency conflicts.
--repositories Comma-separated list of additional remote repositories to
search for the maven coordinates given with --packages.
--py-files PY_FILES Comma-separated list of .zip, .egg, or .py files to place
on the PYTHONPATH for Python apps.
--files FILES Comma-separated list of files to be placed in the working
directory of each executor. --conf PROP=VALUE --properties-file FILE 从文件中载入额外的配置,如果不指定则载入conf/spark-defaults.conf。 --driver-memory MEM Memory for driver (e.g. 1000M, 2G) (Default: 1024M).
--driver-java-options Extra Java options to pass to the driver.
--driver-library-path Extra library path entries to pass to the driver.
--driver-class-path Extra class path entries to pass to the driver. Note that
jars added with --jars are automatically included in the
classpath. --executor-memory MEM Memory per executor (e.g. 1000M, 2G) (Default: 1G). --proxy-user NAME User to impersonate when submitting the application. --help, -h Show this help message and exit
--verbose, -v Print additional debug output
--version, Print the version of current Spark
YARN-only:

Options:
--driver-cores NUM driver使用的核心数,只在cluster模式使用,默认值为1。
--queue QUEUE_NAME 提交到指定的YARN队列,默认队列为"default"。
--num-executors NUM 启动的executor的数量,默认值为2.
--archives ARCHIVES Comma separated list of archives to be extracted into the
working directory of each executor.
--principal PRINCIPAL Principal to be used to login to KDC, while running on
secure HDFS.
--keytab KEYTAB The full path to the file that contains the keytab for the
principal specified above. This keytab will be copied to
the node running the Application Master via the Secure
Distributed Cache, for renewing the login tickets and the
delegation tokens periodically.

注意:如果部署模式是cluster,但是代码中有标准输出的话将看不到,需要把结果写到HDFS中,如果是client模式则可以看到输出。

Spark提交任务(Standalone和Yarn)的更多相关文章

  1. spark 提交任务报错 Yarn application has already ended! It might have been killed or unable to launch application master

    1.任务是提交在yarn上的,查看 resourceManager页面 有如下信息 Current usage: 58.4 MB of 1 GB physical memory used; 2.2 G ...

  2. Spark:三种任务提交流程standalone、yarn-cluster、yarn-client

    spark的runtime参考:Spark:Yarn-cluster和Yarn-client区别与联系浪尖分享资料 standalone Spark可以通过部署与Yarn的架构类似的框架来提供自己的集 ...

  3. Spark 学习笔记之 Standalone与Yarn启动和运行时间测试

    Standalone与Yarn启动和运行时间测试: 写一个简单的wordcount: 打包上传运行: Standalone启动: 运行时间: Yarn启动: 运行时间: 测试结果: Standalon ...

  4. Spark基本工作流程及YARN cluster模式原理(读书笔记)

    Spark基本工作流程及YARN cluster模式原理 转载请注明出处:http://www.cnblogs.com/BYRans/ Spark基本工作流程 相关术语解释 Spark应用程序相关的几 ...

  5. spark提交模式

    spark基本的提交语句: ./bin/spark-submit \ --class <main-class> \ --master <master-url> \ --depl ...

  6. spark提交应用的方法(spark-submit)

    参考自:https://spark.apache.org/docs/latest/submitting-applications.html 常见的语法: ./bin/spark-submit \    ...

  7. spark提交命令 spark-submit 的参数 executor-memory、executor-cores、num-executors、spark.default.parallelism分析

    转载:https://blog.csdn.net/zimiao552147572/article/details/96482120 nohup spark-submit --master yarn - ...

  8. spark提交异常日志分析

    java.lang.NoSuchMethodError: org.apache.spark.sql.SQLContext.sql(Ljava/lang/String;)Lorg/apache/spar ...

  9. 3 weekend110的job提交的逻辑及YARN框架的技术机制 + MR程序的几种提交运行模式

    途径1: 途径2: 途径3: 成功! 由此,可以好好比较下,途径1和途径2 和途径3 的区别. 现在,来玩玩weekend110的joba提交的逻辑之源码跟踪 原来如此,weekend110的job提 ...

随机推荐

  1. vue将数据绑定到属性中

    *必须使用[] <tr v-for="(p,index) in prodects"> @*v-bind:class="styleType(index)&quo ...

  2. FormCollection的用法

    FormCollection的用法: 有时候前台抛来的字段太多,在后台一个一个例举出来显得麻烦,而且还容易出错,FormCollection解决了这个烦恼 #region 给商家留言 [HttpPos ...

  3. 单元测试模拟request后台

    编写测试单元 @RunWith(SpringJUnit4ClassRunner.class) 让测试运行于Spring测试环境 @WebAppConfiguration是一个类级别的注释,用于声明Ap ...

  4. IDEA中的一些常用的设置与快捷键

    idea 清屏(控制台)快捷键 eclipse清屏快捷键为鼠标右键+R 而在idea中默认并没有清屏console的快捷键 所以需要我们自行设置: 1,ctrl+alt+s打开settings 2,找 ...

  5. Sharepoint 2013企业内容管理学习笔记(二) 全自动化内容管理

    全自动化内容管理 所谓全自动化内容管理啊,其实对于用户来说,就更简单便捷有爱了,用户只需要把文件上传到部门网站的放置库中,文件就会快速自动躺到企业记录中心的某个归档记录库了,怎么样,很方便,有没有,很 ...

  6. ArcGIS创建要素类

    在使用ARCGIS软件进行工作时,免不了要建立地理数据库和要素类之类的.一下是我创建文件地理数据库并在数据库中创建要素类写相关步骤: 1.启动软件,可以使用ARCCatalog直接进行创建也可以使用A ...

  7. 学习lucene5.5.4的笔记

    说说几个常用的类. OpenMode是一个枚举类,有三个元素,分别表示IndexWriter的打开模式. CREATE:每次打开IndexWriter时清空当前索引目录下的索引,再新建索引. APPE ...

  8. outlook添加邮箱账户时,测试成功,下一步显示请求失败

    今天在给公司同事添加邮箱账户时,全部设置正常,测试也成功了,但是点击下一步时,出现了请求失败的提示.     1.  看到这个提示,我首先重启了一下outlook,发现进去添加还是不行  2.重启了电 ...

  9. 【2017-06-17】QtGui基础控件:QSpinBox及QDoubleSpinBox

    今天开始一个新的系列,主要是翻译并摘录QtGui中基础空间的常用方法,并做一些简单的实验程序: 我觉得这是一个炒冷饭的行为,但有时候冷饭不能不炒,不热不好吃,而且也很容易发霉. 其实到现在这种状态,对 ...

  10. 【js基础修炼之路】— 深入浅出理解闭包

    之前对于闭包的理解只是很肤浅的,只是浮于表面,这次深究了一下闭包,下面是我对闭包的理解. 什么是闭包? 引用高程里的话 => 闭包就是有权访问另一个作用域中变量的函数,闭包是由函数以及创建该函数 ...