spark資源分配

一、分配哪些資源?

   executor、core per executor、memory per executor、driver memoryshell

二、在哪裏分配這些資源?

   在咱們在生產環境中,提交spark做業時,用的spark-submit shell腳本,裏面調整對應的參數緩存

/usr/local/spark/bin/spark-submit \oop

--class cn.spark.sparktest.core.WordCountCluster \性能

--num-executors 3 \  配置executor的數量spa

--executor-memory 100m \  配置每一個executor的內存大小orm

--executor-cores 3 \  配置每一個executor的cpu core數量對象

--driver-memory 100m \  配置driver的內存(影響很大)隊列

/usr/local/SparkTest-0.0.1-SNAPSHOT-jar-with-dependencies.jar \內存

三、調節到多大,算是最大呢?

第一種,Spark Standalone,公司集羣上,搭建了一套Spark集羣,你內心應該清楚每臺機器還可以hadoop

給你使用的,大概有多少內存,多少cpu core;那麼,設置的時候,就根據這個實際的狀況,

去調節每一個spark做業的資源分配。好比說你的每臺機器可以給你使用4G內存,2個cpu core;

20臺機器;executor,20;平均每一個executor:4G內存,2個cpu core。

第二種,Yarn。資源隊列。資源調度。應該去查看,你的spark做業,要提交到的資源隊列,  

 hadoop   spark  storm 每個隊列都有各自的資源(cpu mem)

大概有多少資源?500G內存,100個cpu core;executor,50;平均每一個executor:10G內存,2個cpu core。

Spark-submit的時候怎麼指定資源隊列?  --conf spark.yarn.queue default

設置隊列名稱:spark.yarn.queue default

一個原則,你能使用的資源有多大,就儘可能去調節到最大的大小(executor的數量,幾十個到上百個不等;

executor內存;executor cpu core)

四、爲何調節了資源之後,性能能夠提高?

增長executor:

   若是executor數量比較少,那麼,可以並行執行的task數量就比較少,就意味着,咱們的Application的並行執行的能力就很弱。

   好比有3個executor,每一個executor有2個cpu core,那麼同時可以並行執行的task,就是6個。6個執行完之後,再換下一批6個task。增長了executor數量之後,那麼,就意味着,可以並行執行的task數量,也就變多了。好比原先是6個,如今可能能夠並行執行10個,甚至20個,100個。那麼並行能力就比以前提高了數倍,數十倍。相應的,性能(執行的速度),也能提高數倍~數十倍。

增長每一個executor的cpu core:

   也是增長了執行的並行能力。本來20個executor,每一個才2個cpu core。可以並行執行的task數量,

就是40個task。如今每一個executor的cpu core,增長到了5個。可以並行執行的task數量,就是100個task。執行的速度,提高了2倍左右。

增長每一個executor的內存量:

增長了內存量之後,對性能的提高,有三點:

   一、若是須要對RDD進行cache,那麼更多的內存,就能夠緩存更多的數據,將更少的數據寫入磁盤

甚至不寫入磁盤。減小了磁盤IO

   二、對於shuffle操做,reduce端,會須要內存來存放拉取的數據並進行聚合。若是內存不夠,也會寫入磁盤。若是給executor分配更多內存之後,就有更少的數據,須要寫入磁盤,甚至不須要寫入磁盤。減小了磁盤IO,提高了性能。

   三、對於task的執行可能會建立不少對象。若是內存比較小,可能會頻繁致使JVM堆內存滿了,

而後頻繁GC,垃圾回收,minor GC和full GC。(速度很慢)。內存加大之後,帶來更少的GC,垃圾回收,

避免了速度變慢,性能提高

五、spark動態資源分配

動態申請executor,若是有新任務處於等待狀態,而且等待時間超過spark.dynamicAllocation.schedulerBacklogTimeout(默認1s),則會依次啓動executor,每次啓動1,2,4,8…個executor(若是有的話)。啓動的間隔由spark.dynamicAllocation.sustainedSchedulerBacklogTimeout控制(默認與schedulerBacklogTimeout相同)。
動態移除executor,executor空閒時間超過spark.dynamicAllocation.executorIdleTimeout設置的值(默認60s ),該executor會被移除,除非有緩存數據。

相關配置

參數名 默認值 描述
spark.dynamicAllocation.executorIdleTimeout 60s executor空閒時間達到規定值,則將該executor移除。
spark.dynamicAllocation.cachedExecutorIdleTimeout infinity 緩存了數據的executor默認不會被移除
spark.dynamicAllocation.maxExecutors infinity 最多使用的executor數,默認爲你申請的最大executor數
spark.dynamicAllocation.minExecutors 0 最少保留的executor數
spark.dynamicAllocation.schedulerBacklogTimeout 1s 有task等待運行時間超過該值後開始啓動executor
spark.dynamicAllocation.executorIdleTimeout schedulerBacklogTimeout 動態啓動executor的間隔
spark.dynamicAllocation.initialExecutors spark.dynamicAllocation.minExecutors 若是全部的executor都移除了,從新請求時啓動的初始executor數
相關文章
相關標籤/搜索