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数
相关文章
相关标签/搜索