• 【Spark-core学习之四】 Spark任务提交


    环境
      虚拟机:VMware 10
      Linux版本:CentOS-6.5-x86_64
      客户端:Xshell4
      FTP:Xftp4
      jdk1.8
      scala-2.10.4(依赖jdk1.8)
      spark-1.6

    术语

    Master(standalone):资源管理的主节点(进程)
    Cluster Manager:在集群上获取资源的外部服务(例如standalone,Mesos,Yarn )
    Worker Node(standalone):资源管理的从节点(进程) 或者说管理本机资源的进程
    Application:基于Spark的⽤用户程序,包含了driver程序和运行在集群上的executor程序
    Driver Program:用来连接工作进程(Worker)的程序
    Executor:是在一个worker进程所管理的节点上为某Application启动的⼀一个进程,该进程负责运行任务,并且负责将数据存在内存或者磁盘上。每个应用都有各自独立的executors
    Task:被送到某个executor上的工作单元
    Job:包含很多任务(Task)的并行计算,可以看做和action对应
    Stage:一个Job会被拆分很多组任务,每组任务被称为Stage(就像Mapreduce分map task和reduce task一样)

    任务提交参数:

    [root@PCS101 bin]# ./spark-submit 
    Usage: spark-submit [options] <app jar | python file> [app arguments]
    Usage: spark-submit --kill [submission ID] --master [spark://...]
    Usage: spark-submit --status [submission ID] --master [spark://...]
    
    Options:
      --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           Arbitrary Spark configuration property.
      --properties-file FILE      Path to a file from which to load extra properties. If not
                                  specified, this will look for 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
    
     Spark standalone with cluster deploy mode only:
      --driver-cores NUM          Cores for driver (Default: 1).
    
     Spark standalone or Mesos with cluster deploy mode only:
      --supervise                 If given, restarts the driver on failure.
      --kill SUBMISSION_ID        If given, kills the driver specified.
      --status SUBMISSION_ID      If given, requests the status of the driver specified.
    
     Spark standalone and Mesos only:
      --total-executor-cores NUM  Total cores for all executors.
    
     Spark standalone and YARN only:
      --executor-cores NUM        Number of cores per executor. (Default: 1 in YARN mode,
                                  or all available cores on the worker in standalone mode)
    
     YARN-only:
      --driver-cores NUM          Number of cores used by the driver, only in cluster mode
                                  (Default: 1).
      --queue QUEUE_NAME          The YARN queue to submit to (Default: "default").
      --num-executors NUM         Number of executors to launch (Default: 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.

    --master
    MASTER_URL, 可以是spark://host:port, mesos://host:port, yarn, yarn-cluster,yarn-client, local
    --deploy-mode
    DEPLOY_MODE, Driver程序运行的地方,client或者cluster,默认是client。
    --class
    CLASS_NAME, 主类名称,含包名
    --jars
    逗号分隔的本地JARS, Driver和executor依赖的第三方jar包
    --files
    用逗号隔开的文件列表,会放置在每个executor工作目录中
    --conf
    spark的配置属性
    --driver-memory
    Driver程序使用内存大小(例如:1000M,5G),默认1024M
    --executor-memory
    每个executor内存大小(如:1000M,2G),默认1G

    Spark standalone with cluster deploy mode only:
    --driver-cores
    Driver程序的使用core个数(默认为1),仅限于Spark standalone模式

    Spark standalone or Mesos with cluster deploy mode only:
    --supervise
    失败后是否重启Driver,仅限于Spark alone或者Mesos模式

    Spark standalone and Mesos only:
    --total-executor-cores
    executor使用的总核数,仅限于SparkStandalone、Spark on Mesos模式

    Spark standalone and YARN only:
    --executor-cores
    每个executor使用的core数,Spark on Yarn默认为1,standalone默认为worker上所有可用的core。

    YARN-only:
    --driver-cores
    driver使用的core,仅在cluster模式下,默认为1。
    --queue
    QUEUE_NAME 指定资源队列的名称,默认:default
    --num-executors
    一共启动的executor数量,默认是2个。

    一、standalone任务提交
    1、clinet
    (1)执行原理图


    (2)执行流程
    (2.1)client模式提交任务后,会在客户端启动Driver进程。
    (2.2)Driver会向Master申请启动Application启动的资源。
    (2.3)资源申请成功,Driver端将task发送到worker端执行。
    (2.4)worker将task执行结果返回到Driver端。
    (3)总结
    client模式适用于测试调试程序。Driver进程是在客户端启动的,这里的客户端就是指提交应用程序的当前节点。在Driver端可以看到task执行的情况。生产环境下不能使用client模式,是因为:假设要提交100个application到集群运行,Driver每次都会在client端启动,那么就会导致客户端100次网卡流量暴增的问题。

    2、cluster
    (1)执行原理图

    (2)执行流程
    (2.1)cluster模式提交应用程序后,会向Master请求启动Driver.
    (2.2)Master接受请求,随机在集群一台节点启动Driver进程。
    (2.3)Driver启动后为当前的应用程序申请资源。
    (2.4)Driver端发送task到worker节点上执行。
    (2.5)worker将执行情况和执行结果返回给Driver端。

    (3)总结
    Driver进程是在集群某一台Worker上启动的,在客户端是无法查看task的执行情况的。假设要提交100个application到集群运行,每次Driver会随机在集群中某一台Worker上启动,那么这100次网卡流量暴增的问题就散布在集群上。

    总结Standalone两种方式提交任务,Driver与集群的通信包括:

    (1)Driver负责应用程序资源的申请
    (2)任务的分发。
    (3)结果的回收。
    (4)监控task执行情况。


    二、YARN任务提交
    1、client
    (1)执行原理图

    (2)执行流程
    (2.1)客户端提交一个Application,在客户端启动一个Driver进程。
    (2.2)应用程序启动后会向RS(ResourceManager)发送请求,启动AM(ApplicationMaster)的资源。
    (2.3)RS收到请求,随机选择一台NM(NodeManager)启动AM。这里的NM相当于Standalone中的Worker节点。
    (2.4)AM启动后,会向RS请求一批container资源,用于启动Executor.
    (2.5)RS会找到一批NM返回给AM,用于启动Executor。
    (2.6)AM会向NM发送命令启动Executor。
    (2.7)Executor启动后,会反向注册给Driver,Driver发送task到Executor,执行情况和结果返回给Driver端。

    (3)总结
    Yarn-client模式同样是适用于测试,因为Driver运行在本地,Driver会与yarn集群中的Executor进行大量的通信,会造成客户机网卡流量的大量增加.
    ApplicationMaster的作用:
    (1)为当前的Application申请资源
    (2)给NameNode发送消息启动Executor。
    注意:ApplicationMaster有launchExecutor和申请资源的功能,并没有作业调度的功能。

    2、cluster
    (1)执行原理图


    (2)执行过程
    (2.1)客户机提交Application应用程序,发送请求到RS(ResourceManager),请求启动AM(ApplicationMaster)。
    (2.2)RS收到请求后随机在一台NM(NodeManager)上启动AM(相当于Driver端)。
    (2.3)AM启动,AM发送请求到RS,请求一批container用于启动Executor。
    (2.4)RS返回一批NM节点给AM。
    (2.5)AM连接到NM,发送请求到NM启动Executor。
    (2.6)Executor反向注册到AM所在的节点的Driver。Driver发送task到Executor。

    (3)总结
    Yarn-Cluster主要用于生产环境中,因为Driver运行在Yarn集群中某一台nodeManager中,每次提交任务的Driver所在的机器都是随机的,不会产生某一台机器网卡流量激增的现象,缺点是任务提交后不能看到日志。只能通过yarn查看日志。
    ApplicationMaster的作用:
    (1)为当前的Application申请资源
    (2)给NameNode发送消息启动Excutor。
    (3)任务调度。
    停止集群任务命令:yarn application -kill applicationID

    参考:

    Spark

    Spark运行流程

  • 相关阅读:
    《编程珠玑》读后感之一
    《梦断代码》读后感之三
    java项目中下载文件文件名乱码
    struts中action与页面之间的传值方式
    使用JSON数据报错和方法
    java中实现将一个数字字符串转换成逗号分隔的数字串, 即从右边开始每三个数字用逗号分隔
    java中判断一个字符在字符串中出现的次数
    使用面向对象(OO)的思想,实现循环输入多个会员的信息,根据会员编号,查找会员积分
    MySQL添加用户、删除用户与授权
    vi编辑器的使用
  • 原文地址:https://www.cnblogs.com/cac2020/p/10649732.html
Copyright © 2020-2023  润新知