有时候在dev环境尤其是虚拟机集群的环境中,在启动spark job时有可能会遇到如下类似报错:
ERROR spark.SparkContext: Error initializing SparkContext.
java.lang.IllegalArgumentException: Required executor memory (1024+384 MB) is
above the max threshold (1024 MB) of this cluster! Please check the values of
'yarn.scheduler.maximum-allocation-mb' and/or 'yarn.nodemanager.resource.memory-mb'.
at org.apache.spark.deploy.yarn.Client.verifyClusterResources(Client.scala:319)
一、原因分析
从日志中很容易看出,Spark在初始化SparkContext的时候由于executor要求的内存超过了整个集群锁给出的内存的最大阈值了。
二、解决方案
既然是所分配的硬件资源和所需求的硬件资源的冲突,解决办法分为两类:
- 减小required memory;
- 增加memory allocation;
前者可以通过在提交Spark job时,指定更小的executor memory来实现,比如:
--executor-memory=300M
后者则需要修改配置项的取值了,'yarn.scheduler.maximum-allocation-mb'被定义在了yarn-site.xml文件中:
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>10000</value>
</property>
将该配置项的取值设置得大于required memory即可。
如有错误之处,敬请指正!
网友评论