Spark作业提交后,在driver上运行init()方法时报错:
java.lang.OutOfMemoryError: GC overhead limit exceeded
报错原因是代码中使用了HashMap而且数据量很大,所以导致GC overhead,调整JVM的启动参数-Xms和-Xmx,这个参数配置Java堆的大小,因为代码运行时hashmap对象存放在堆中,故需调大改参数。配置时需要考虑机器的内存大小,不能盲目配置过大。
若作业提交时以yarn-client模式提交,Driver运行时的JVM参数是spark在spark-env.sh 配置文件中读取,因此在spark-env.sh中加入配置:
SPARK_DRIVER_MEMORY=2G
作业在每个worker上运行时报错:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
此时需要配置每个worker运行的MEMORY参数,在spark-env.sh中配置:
export SPARK_WORKER_MEMORY=4g
export SPARK_WORKER_CORES=4
spark作业提交时配置两个参数:
--executor-memory 4G
--total-executor-cores 4
executor-memory属性配置的是JVM进程的Java堆区域,这个值设置为多大合适呢?
首先要注意的是,设置的值必须要小于运行Excutor的container的最大内存。
spark作业在提交时指定了运行模式,我这里指定的是yarn-client模式,以这种模式运行作业时,资源管理部分完全由yarn进行管理,yarn-site.xml配置文件中有两个属性
<property>
<name>yarn.app.mapreduce.am.resource.mb</name>
<value>2048</value>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>10240</value>
</property>
ApplicationMaster运行在一个container中,yarn.app.mapreduce.am.resource.mb
属性配置ApplicationMaster所在的container的最大内存。
Excutor也是运行在container中,yarn.scheduler.maximum-allocation-mb
配置Excutor所在的container的最大内存,该值默认值为1024m。
其次需要知道Executor执行的时候,用的内存可能会超过executor-memoy,所以会为Executor额外预留一部分内存属性。
因此 executorMemory(实际上Excutor所使用的最大内存) =args.executorMemory(--executor-memory
参数所配置的属性值) + executorMemoryOverhead(额外预留一部分内存)
其中executorMemory = yarn.scheduler.maximum-allocation-mb
中配置的container的最大内存.
属性spark.yarn.executor.memoryOverhead
用于配置预留的这部分内存,MemoryOverhead是JVM进程中除Java堆以外占用的空间大小,包括方法区(永久代)、Java虚拟机栈、本地方法栈、JVM进程本身所用的内存、直接内存。如果没有配置该属性,则默认值由一个公式
math.max((MEMORY_OVERHEAD_FACTOR * executorMemory).toInt, MEMORY_OVERHEAD_MIN))
进行计算,其中,
MEMORY_OVERHEAD_FACTOR=0.1,
MEMORY_OVERHEAD_MIN=384m,
executorMemory=args.executor-memory
原文链接:https://blog.csdn.net/zjwcsdn123/article/details/80137883
网友评论