spark on yarn內存和CPU分配


以spark1.6為例,使用內存和CPU的無外乎三個:appMaster、driver、executor,下面分別分析spark on yarn的client與cluster模式下的內存和CPU分配
一、vcores
1、driver核數:
  client模式:無
  cluster模式:spark.driver.cores=1(默認)
2、AppMaster核數:
  client模式:spark.yarn.am.cores=1(默認)
  cluster模式:spark.driver.cores=1(默認)
3、executor核數:
  spark.executor.cores=1(默認)
4、executor內每個task使用的核數:
  spark.task.cpus=1(默認)
5、每個executor內能夠並行運行的task數:
  spark.executor.cores / spark.task.cpus
6、yarn上啟動executor的個數:
  SPARK_EXECUTOR_INSTANCES/spark.executor.instances=2(默認)
7、要向yarn申請的總的vcores = executor核數 * executor個數 + AppMaster核數,
  具體yarn給多少顆vcores,類似於mapreduce on yarn的情況,參考文章:
  https://www.cnblogs.com/yesecangqiong/p/6274427.html
注意---------------------------
  1、:spark.driver.cores只能在cluster模式下使用
  2、spark.executor.instances與spark.dynamicAllocation.enabled不能共同使用,如果兩個都做了配置,spark.executor.instances有效
  3、要向使spark.task.cpus>1時起作用,還應該保證yarn的配置文件"capacity-scheduler.xml"中的配置選項"yarn.scheduler.capacity.resource-calculator"
    的值為:"org.apache.hadoop.yarn.util.resource.DominantResourceCalculator",而不應該是默認的"org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator"
    可以參考文章:https://www.cnblogs.com/yesecangqiong/p/10125333.html

二、內存
1、driver需要申請的內存 = 基本內存 + 額外內存
  基本內存:
    spark.driver.memory=1g(默認)
  額外內存:
    1、有參數配置則直接等於參數配置
      spark.yarn.driver.memoryOverhead
    2、無參數配置(即默認)
      max(driver基本內存 * 0.1,384M)
2、appMster需要申請的內存 = 基本內存 + 額外內存(memoryOverhead)
  基本內存:
    client模式:spark.yarn.am.memory=512MB(默認)
    cluster模式:appMaster與driver運行於同一個JVM(yarn上的同一container),決定於:spark.driver.memory=1g(默認)
  額外內存:
    1、有參數配置則直接等於參數配置
      client模式:spark.yarn.am.memoryOverhead
      cluster模式:spark.yarn.driver.memoryOverhead
    2、沒有配置相應參數(即默認):
      yarn-client模式:max(AppMaster基本內存 * 0.1,384M)
      yarn-cluster模式:max(Driver基本內存 * 0.1,384M)
3、executor需要申請的內存 = 基本內存 + 額外內存
  基本內存:
    spark.executor.memory=1g(默認)
  額外內存:
    1、有參數配置則直接等於參數配置
      spark.yarn.executor.memoryOverhead
    2、無參數配置(即默認)
      max(executor基本內存 * 0.1,384M)
4、要向yarn申請的總的內存 = executor內存 * executor個數 + AppMaster內存 ,
  具體yarn給多少內存,類似於mapreduce on yarn的情況,參考文章:
  https://www.cnblogs.com/yesecangqiong/p/6274427.html
注意--------------------------------:
  在client模式下,spark.driver.memory不能由代碼中的SparkConf配置指定,只能通過配置文件或運行腳本中指定

三、參考官方文檔:
  http://spark.apache.org/docs/1.6.0/running-on-yarn.html#configuration
  http://spark.apache.org/docs/1.6.0/configuration.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM