zoukankan      html  css  js  c++  java
  • spark提交模式

    spark基本的提交语句:
    ./bin/spark-submit  --class <main-class>  --master <master-url>  --deploy-mode <deploy-mode>  --conf <key>=<value> ... # other options <application-jar>  [application-arguments]
    参数的含义:
    • --class: 主函数所在的类。
    • --master: master的url,后面会解释 (e.g. spark://23.195.26.187:7077)
    • --deploy-mode: 部署driver在本地还是集群的一个work节点上,这也是client模式与cluster模式的区别。默认是client的模式。
    • --conf:用 key=value形式指定参数,如果包含空格那么要用双引号引起来,例如“key=value”
    • application-jar:jar包的路径.该路径必须在集群内全局可见。 例如: hdfs:// path 或者 file:// 这个path必须是所有节点都存在。.
    • application-arguments: 传递给main函数 参数,如java main方法中的args[].
     
    常用 提交模式:
    第一种:client模式
    适合于有专门的getway机器与集群位于同一网段,这种模式下,spark-submit提交后driver直接启动昨晚集群的一个client。集群的输出会返回到client端的console上。这种模式很适合spark-shell。
     
    第二种:如果提交的机器远离spark集群的worker机器,最好使用cluster模式,该模式能够减少网络传输的错误。目前standalone模式并不支持py的这种方式。
     
    对于cluster的管理还有一些参数要指定,比如说在standalone模式下,指定--supervise参数可以在driver在返回码是非0的退出后重启driver。下面是几种常用的提交命令参数:
    #本地运行,指定8个core
    ./bin/spark-submit  
    --class org.apache.spark.examples.SparkPi 
     --master local[8]  
    /path/to/examples.jar  
    100
    # 在 Spark standalone 集群并且是client模式
    ./bin/spark-submit  
    --class org.apache.spark.examples.SparkPi  
    --master spark://207.184.161.138:7077  
    --executor-memory 20G  
    --total-executor-cores 100  
    /path/to/examples.jar  
    1000
    # 在 Spark standalone 集群并且是cluster模式 并指定supervise
    ./bin/spark-submit  
    --class org.apache.spark.examples.SparkPi  
    --master spark://207.184.161.138:7077  
    --deploy-mode cluster  
    --supervise  
    --executor-memory 20G  
    --total-executor-cores 100  
    /path/to/examples.jar  
    1000
    # Yarn cluster模式export HADOOP_CONF_DIR=XXX
    ./bin/spark-submit 
    --class org.apache.spark.examples.SparkPi  
    --master yarn  
    --deploy-mode cluster  
    # can be client for client mode
    --executor-memory 20G  
    --num-executors 50  
    /path/to/examples.jar  
    1000
    # python提交到standalone的cluster模式
    ./bin/spark-submit  
    --master spark://207.184.161.138:7077  
    examples/src/main/python/pi.py  
    1000
    # mesos cluster模式,并指定supervise。
    ./bin/spark-submit  
    --class org.apache.spark.examples.SparkPi  
    --master mesos://207.184.161.138:7077  
    --deploy-mode cluster  
    --supervise  
    --executor-memory 20G  
    --total-executor-cores 100  
    http://path/to/examples.jar 
    1000
    关于master url的指定方法:
    local 本地worker线程中运行spark,完全没有并行
    local[K] 在本地work线程中启动K个线程运行spark
    local[*] 启动与本地work机器的core个数想通的线程数来运行spark
    spark://HOST:PORT 连接指定的standalone集群的master,默认7077端口
    mesos://HOST:PORT 连接到mesos集群,默认5050端口。如果mesos使用了zk,那么也可以mesos://zk://.... 加 --deploy-mode cluster这种形式。
    yarn 使用yarn的cluster或者yarn的client模式连接。取决于--deploy-mode参数,集群的位置需要使用hadoop的配置或者yarn的配置中去寻找。
     
    关于默认配置文件:
    spark-submit会默认读取conf/spark-defaults.conf 里面设置 配置。
     
    依赖管理:
    使用spark-submit来提交spark程序,spark app本身jar以及使用--jars指定的所有jar包都会自动被分发到集群。--jars参数必须使用逗号分隔。spark使用下面这些方法指定jar来分发jar:
    • file: - 绝对路径 file:/ dirver的http file server。executors会从该driver上拉取jar。
    • hdfs:, http:, https:, ftp: -从这些位置拉取
    • local: - 从worke所在 每台机器本地拉取文件,适合于jar包很大的场景。
  • 相关阅读:
    HDU 4024 Dwarven Sniper’s hunting(数学公式 或者是二分)
    二分图最大匹配总结
    HDU 4022 Bombing (STL应用)
    HDU 1847 Good Luck in CET4 Everybody!(组合博弈)
    HDU 1556 Color the ball(树状数组)
    HDU 4023 Game(博弈)
    HDU 1406 完数(水题)
    HDU 4021 24 Puzzle
    Oracle 多表查询优化
    【编程之美】字符串移位包含的问题(续)
  • 原文地址:https://www.cnblogs.com/duanxz/p/4454606.html
Copyright © 2011-2022 走看看