spark资源动态调整--内容搬运,周知

发布时间 2023-05-09 11:06:31作者: 贾彤
  1. 动态资源分配

Spark的动态资源分配就是executor数据量的动态增减,具体的增加和删除数量根据业务的实际需要动态的调整。具体表现为:如果executor数据量不够,则增加数量,如果executor在一段时间内空闲,则移除这个executor。

动态增加executor配置项:spark.dynamicAllocation.schedulerBacklogTimeout

说明:executor启动间隔spark.dynamicAllocation.schedulerBacklogTimeout(默认1s)。当task到来时,spark会根据启动间隔依次启动executor,如果资源充足,则每次按照spark.dynamicAllocation.sustainedSchedulerBacklogTimeout的值启动1,2,4…个executor,直至资源分配得到满足。

动态移除executor配置项:spark.dynamicAllocation.executorIdleTimeout

说明:如果executor的空闲间隔超过spark.dynamicAllocation.executorIdleTimeout设置的值(默认60s)的话,则该executor会被移除,除非内存里面有缓存数据。

  1. 动态资源分配的开启

(1)       spark.dynamicAllocation.enabled=true,表示开启动态资源分配功能

(2)       spark.shuffle.service.enabled=true,表示在nodemanager上开启shuffle功能,只有这两个配置项都开启的时候,动态资源分配功能才算生效。

PS:以spark on yarn为例,spark.shuffle.service.enabled=true,还需要在yarn-site.xml中配置以下内容。

        <property>
      <name>yarn.nodemanager.aux-services</name>
      <value>mapreduce_shuffle,spark_shuffle</value>
    </property>
    <property>
      <name>yarn.nodemanager.aux-services.spark_shuffle.class</name>
      <value>org.apache.spark.network.yarn.YarnShuffleService</value>
    </property>
    <property>
      <name>spark.shuffle.service.port</name>
      <value>xxxx</value>
    </property>
  1. 动态executor相关配置(spark-default.conf)汇总和说明

参数名

默认值

描述

spark.dynamicAllocation.enabled

false

启动态资源分配功能开关

spark.shuffle.service.enabled

false

在nodemanager上开启shuffle功能开关

spark.dynamicAllocation.cachedExecutorIdleTimeout

infinity

如果executor内有缓存数据,并且空闲了配置项的值的时间(秒)。则remove该executor。默认值无限制,也就是如果有缓存数据,则不会remove该executor

spark.dynamicAllocation.executorIdleTimeout

60s

executor空闲时间达到该规定值,则将该executor被回收

spark.dynamicAllocation.initialExecutors

spark.dynamicAllocation.minExecutors

Driver拉起SparkContext时初始executor数

spark.dynamicAllocation.maxExecutors

infinity

最大使用的executor数,默认无限制

spark.dynamicAllocation.minExecutors

0

最少保留的executor数

spark.dynamicAllocation.schedulerBacklogTimeout

1s

当task到来时,开始分配executor的时间间隔

spark.dynamicAllocation.sustainedSchedulerBacklogTimeout

1s

当task到来后,已经开始分配executor后,再次申请executor的时间间隔,直至申请到足够的资源

  1. 总结

通过设置合理的minExecutors-maxExecutors等配置项的值,Spark的动态资源分配使集群的资源更能充分的按需使用。华为云DLI数据湖探索服务在开源Spark基础上进行了大量的性能优化与服务化改造,兼容Apache Spark生态和接口,动态资源分配同样在DLI Spark作业上兼容使用,用户只需要在spark参数列表里配置相应的参数即可方便的使用。

文章来源:华为云社区

文章链接:https://bbs.huaweicloud.com/blogs/detail/196158

文章作者:霞光