欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > YARN Container与Spark Executor参数优先级详解

YARN Container与Spark Executor参数优先级详解

2026/5/3 5:01:07 来源:https://blog.csdn.net/hanwen112/article/details/146883688  浏览:    关键词:YARN Container与Spark Executor参数优先级详解

在Spark on YARN环境中,资源参数的配置涉及YARN和Spark两个层面的参数设置,它们之间存在一定的优先级关系。以下是关键参数的优先级解析:

1. 参数优先级总览

Spark on YARN的资源参数优先级遵循以下原则:

  1. Spark-submit命令行参数 > spark-defaults.conf配置 > 环境变量 > 默认值
  2. YARN层面的资源限制会最终约束Spark申请的资源总量

2. 关键参数对应关系

2.1 内存相关参数

Spark参数YARN对应参数说明
spark.executor.memory-Executor JVM堆内存大小
spark.yarn.executor.memoryOverhead-Executor堆外内存(默认max(384MB, 0.1*executorMemory))
-yarn.scheduler.maximum-allocation-mb单个Container能申请的最大内存,限制Executor总内存(堆+堆外)
-yarn.nodemanager.resource.memory-mb单个NodeManager的总可用内存

内存计算公式
Executor总内存 = spark.executor.memory + spark.yarn.executor.memoryOverheadyarn.scheduler.maximum-allocation-mb

2.2 CPU相关参数

Spark参数YARN对应参数说明
spark.executor.cores-每个Executor使用的vCore数
-yarn.scheduler.maximum-allocation-vcores单个Container能申请的最大vCore数
-yarn.nodemanager.resource.cpu-vcores单个NodeManager的总vCore数

3. 参数优先级具体分析

3.1 内存参数优先级

  1. Spark层面

    • 如果同时设置spark.executor.memoryspark.yarn.executor.memoryOverhead,则Executor总内存为两者之和
    • 如果只设置spark.executor.memory,堆外内存按默认公式计算
  2. YARN层面约束

    • Executor总内存不能超过yarn.scheduler.maximum-allocation-mb
    • 所有Executor总内存不能超过yarn.nodemanager.resource.memory-mb
  3. 内存规整化

    • YARN会按yarn.scheduler.increment-allocation-mb(默认1024MB)对申请的内存进行规整化处理

3.2 CPU参数优先级

  1. Spark层面

    • spark.executor.cores指定每个Executor使用的vCore数
  2. YARN层面约束

    • spark.executor.coresyarn.scheduler.maximum-allocation-vcores
    • Executor数量 × spark.executor.coresyarn.nodemanager.resource.cpu-vcores

4. 最佳实践建议

  1. 内存配置建议

    • 单个Executor内存不宜过大(推荐不超过64GB),以避免GC问题
    • 预留约10-15%的内存作为堆外内存(通过spark.yarn.executor.memoryOverhead)
    • 考虑HDFS客户端并发限制,每个Executor的并行任务数建议不超过5个
  2. CPU配置建议

    • 每个Executor的vCore数建议4-6个,以平衡并行度和资源利用率
    • 考虑yarn.nodemanager.resource.cpu-vcores的总量,合理设置Executor数量
  3. 动态资源分配

    • 启用spark.dynamicAllocation.enabled=true实现Executor数量动态调整
    • 配合设置spark.dynamicAllocation.minExecutorsspark.dynamicAllocation.maxExecutors

5. 配置示例

# Spark提交命令示例
spark-submit \--master yarn \--deploy-mode cluster \--executor-memory 10G \--executor-cores 4 \--num-executors 10 \--conf spark.yarn.executor.memoryOverhead=2G \--conf spark.dynamicAllocation.enabled=true \--conf spark.dynamicAllocation.maxExecutors=20 \your_application.jar

对应的YARN配置建议:

<!-- yarn-site.xml -->
<property><name>yarn.nodemanager.resource.memory-mb</name><value>65536</value> <!-- 64GB -->
</property>
<property><name>yarn.scheduler.maximum-allocation-mb</name><value>16384</value> <!-- 16GB -->
</property>
<property><name>yarn.nodemanager.resource.cpu-vcores</name><value>16</value>
</property>
<property><name>yarn.scheduler.maximum-allocation-vcores</name><value>8</value>
</property>

通过理解这些参数的优先级关系,可以更有效地配置Spark on YARN应用程序,充分利用集群资源,同时避免因参数配置不当导致的资源申请失败或性能问题。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词