1.现象
执行命令:bin/spark-submit --class org.apache.spark.examples.SparkPi --executor-memory 1G --total-executor-cores 2 ./examples/jars/spark-examples_2.11-2.4.0-cdh6.2.1.jar 100时
Spark-Shell报错:
ERROR spark.SparkContext: Error initializing SparkContext.
java.lang.IllegalArgumentException: Required executor memory (1024), overhead (384 MB), and PySpark memory (0 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’.
2.原因
单个任务可申请的默认最大内存为1024M,任务执行实际需要1384M个,需要增加可申请的内存量,修改配置参数如下图。
3.解决方法
修改对应参数
#MR ApplicationMaster占用的内存量
yarn.app.mapreduce.am.resource.mb =4g
#单个节点上金额分配的物理内存总量
yarn.nodemanager.resource.memory-mb=8g
#单个任务可申请的最多物理内存量
yarn.scheduler.maximum-allocation-mb=4g