spark资源分配

1、分配哪些资源?

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

2、在哪里分配这些资源?

   在我们在生产环境中,提交spark作业时,用的spark-submit shell脚本,里面调整对应的参数

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

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

--num-executors 3 \  配置executor的数量

--executor-memory 100m \  配置每个executor的内存大小

--executor-cores 3 \  配置每个executor的cpu core数量

--driver-memory 100m \  配置driver的内存(影响很大)

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

3、调节到多大,算是最大呢?

第一种,Spark Standalone,公司集群上,搭建了一套Spark集群,你心里应该清楚每台机器还能够

给你使用的,大概有多少内存,多少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)

4、为什么调节了资源以后,性能可以提升?

增加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的内存量:

增加了内存量以后,对性能的提升,有三点:

   1、如果需要对RDD进行cache,那么更多的内存,就可以缓存更多的数据,将更少的数据写入磁盘

甚至不写入磁盘。减少了磁盘IO

   2、对于shuffle操作,reduce端,会需要内存来存放拉取的数据并进行聚合。如果内存不够,也会写入磁盘。如果给executor分配更多内存以后,就有更少的数据,需要写入磁盘,甚至不需要写入磁盘。减少了磁盘IO,提升了性能。

   3、对于task的执行可能会创建很多对象。如果内存比较小,可能会频繁导致JVM堆内存满了,

然后频繁GC,垃圾回收,minor GC和full GC。(速度很慢)。内存加大以后,带来更少的GC,垃圾回收,

避免了速度变慢,性能提升

5、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数

 

猜你喜欢

转载自my.oschina.net/u/2000675/blog/1813511