spark任务动态资源分配

开启动态资源分配

为了生效还要求完成提前完成以下任意一种配置

第一种方法:

1、Application提交时需要附带以下设置:

set spark.dynamicAllocation.enabled = true
set spark.dynamicAllocation.shuffleTracking.enabled = true

第二种方法:

1、Application提交时需要附带以下设置:

spark.dynamicAllocation.enabled = true
spark.shuffle.service.enabled = true

2、设置External shuffle service:

设置shuffleTracking或者External shuffle service的目的是,使得executors被移除时不会丢失他们写过的shuffle files。

原理细节说明

实现动态资源分配之前,先实现对Executors产生的数据的解耦

解得啥子耦:整体spark application对其写入的数据文件的依赖

考虑Executor写入数据操作的行为:① 往shuffle files写入;② 往cache or disk 中持久化

解决shuffle files的数据

如果在shuffle完成前,移除了一个executor,那之后这个executor所要写入的shuffle files就要重新由别的executor再次完成计算并写入。(这是一个非常不必要的做法)

通过使用external shuffle service,会在每个node上为你的spark applications和executors独立地启动一个一直运行的进程。因此,之后spark executors将从这些进程获取shuffle files而不是直接去找executors。即,意味着shuffle files的生命周期可以超出写入这些shuffle files的executor的生命周期。

解决cache or disk持久化的数据

Executors除了往shuffle files写入数据,还会往cache或者disk中持久化数据。当Executors被移除后,Executors存在cache中的data将会无法被获取。

为了解决该问题,默认情况下保存cache data的executors不会被删除。当然,这个配置是可以修改的,通过设置参数spark.dynamicAllocation.cachedExecutorIdleTimeout,

set spark.shuffle.service.fetch.rdd.enabled to true后,spark能够从前面提到的external shuffle service去获取磁盘持久化的RDD blocks。在动态分配的情况下,如果启用此功能,则只有磁盘持久块的executors在 spark.dynamicAllocation.executorIdleTimeout 之后才会被被认为是空闲的,并将相应地释放。

on Yarn

1、对YARN进行配置,修改集群每台Node上的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>7337</value>
</property>

2、将$SPARK_HOME/yarn/ spark-<version>-yarn-shuffle.jar拷贝到每台NodeManager下的${HADOOP_HOME}/share/hadoop/yarn/lib/目录,然后重启所有修改过配置的节点。

3、配置$SPARK_HOME/conf/spark-defaults.conf,增加以下参数

# 启用External shuffle Service服务
spark.shuffle.service.enabled true
# Shuffle Service默认服务端口,必须和yarn-site中的一致
spark.shuffle.service.port 7337
# 开启动态资源分配
spark.dynamicAllocation.enabled true
# 每个Application最小分配的executor数
spark.dynamicAllocation.minExecutors 0
# 每个Application最大并发分配的executor数
spark.dynamicAllocation.maxExecutors 3
spark.dynamicAllocation.schedulerBacklogTimeout 1s
spark.dynamicAllocation.sustainedSchedulerBacklogTimeout 5s
# executor 空闲超过60s 则释放
spark.dynamicAllocation.executorIdleTimeout 60s
#  如果启用动态分配,则要运行executor的初始数量。如果设置了“–num-executors”(或“spark.executor.instances”)并且大于这个值,则会使用这个值进行初始化。 如: max(initialExecuor = 3, –num-executors = 10) 取最大
spark.dynamicAllocation.initialExecutors 1
# 如果启用了动态分配,并且缓存数据块的executor已经空闲了超过这个时间,executor将被释放
spark.dynamicAllocation.cachedExecutorIdleTimeout 60s
on K8s

官方文档说明属于Future Work。

Future Work

There are several Spark on Kubernetes features that are currently being worked on or planned to be worked on. Those features are expected to eventually make it into future versions of the spark-kubernetes integration.

Some of these include:

  • Dynamic Resource Allocation and External Shuffle Service
  • Job Queues and Resource Management
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spark 中,任务提交时可以使用静态分配资源和动态分配资源两种方式。 1. 静态分配资源: 静态分配资源是指在任务提交时,为每个应用程序分配固定的资源。这样每个应用程序都会独占预先分配的资源,无论其实际需求如何。静态分配资源适用于资源需求较为稳定的应用程序。 在 Spark 中,可以通过以下方式进行静态分配资源: - 在使用 `spark-submit` 命令提交应用程序时,通过 `--executor-cores`、`--executor-memory`、`--num-executors` 等参数指定每个执行器的核心数、内存和执行器的数量。 - 通过配置文件 `spark-defaults.conf` 中的 `spark.executor.cores`、`spark.executor.memory` 和 `spark.executor.instances` 属性进行设置。 2. 动态分配资源: 动态分配资源是指在任务执行期间根据应用程序的实际需求动态分配资源。这样可以更灵活地利用集群资源,使得不同应用程序之间可以共享资源。动态分配资源适用于资源需求波动较大的应用程序。 在 Spark 中,可以通过以下方式进行动态分配资源: - 启用 Spark动态资源分配功能,通过设置 `spark.dynamicAllocation.enabled` 为 `true` 来开启。 - 配置动态分配资源相关的参数,如 `spark.dynamicAllocation.minExecutors`、`spark.dynamicAllocation.maxExecutors`、`spark.dynamicAllocation.initialExecutors` 等。 动态资源分配的原理是根据应用程序的需求和集群的资源情况,动态调整执行器的数量。当应用程序的负载较重时,可以增加执行器的数量以提供更多资源;当负载较轻时,可以减少执行器的数量以释放资源。 需要注意的是,动态资源分配功能依赖于 Spark Standalone、YARN 或者 Mesos 等集群管理器。在使用动态资源分配时,还可以设置一些其他相关的参数,如 `spark.dynamicAllocation.executorIdleTimeout`、`spark.dynamicAllocation.schedulerBacklogTimeout` 等,以进一步调优资源分配策略。 综上所述,静态分配资源适用于资源需求较为稳定的应用程序,而动态分配资源则适用于资源需求波动较大的应用程序。选择合适的资源分配方式可以更好地利用集群资源并提高应用程序的性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值