我的 Spark 作业由于 java.lang.OutOfMemoryError: Java 堆空间而失败。
我尝试使用配置参数,例如 executor-cores、executor-memory、num-executors、driver-cores 、driver-memory
、spark.yarn.driver.memoryOverhead
、spark.yarn.executor.memoryOverhead
根据Ramzy's answer 。以下是我的配置集
--master yarn-cluster --executor-cores 4 --executor-memory 10G --num-executors 30 --driver-cores 4 --driver-memory 16G --queue team_high --conf spark.eventLog.dir=hdfs:///spark-history --conf spark.eventLog.enabled=true --conf spark.yarn.historyServer.address=xxxxxxxxx:xxxx --conf spark.sql.tungsten.enabled=true --conf spark.ui.port=5051 --conf spark.sql.shuffle.partitions=30 --conf spark.yarn.driver.memoryOverhead=1024 --conf spark.yarn.executor.memoryOverhead=1400 --conf spark.dynamicAllocation.enabled=true --conf spark.shuffle.service.enabled=true --conf spark.sql.orc.filterPushdown=true --conf spark.scheduler.mode=FAIR --conf hive.exec.dynamic.partition=false --conf hive.exec.dynamic.partition.mode=nonstrict --conf mapreduce.fileoutputcommitter.algorithm.version=2 --conf orc.stripe.size=67108864 --conf hive.merge.orcfile.stripe.level=true --conf hive.merge.smallfiles.avgsize=2560000 --conf hive.merge.size.per.task=2560000 --conf spark.driver.extraJavaOptions='-XX:+UseCompressedOops -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps' --conf spark.executor.extraJavaOptions='-XX:+UseCompressedOops -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC'
对于上述问题,它有时有效,但大多数时候失败。 在调试时,我发现了以下GC日志。有人可以帮助我理解这些日志并帮助我调整这项工作吗?
#
# java.lang.OutOfMemoryError: Java heap space
# -XX:OnOutOfMemoryError="kill %p"
# Executing /bin/sh -c "kill 79911"...
Heap
PSYoungGen total 2330112K, used 876951K [0x00000006eab00000, 0x00000007c0000000, 0x00000007c0000000)
eden space 1165312K, 75% used [0x00000006eab00000,0x0000000720365f50,0x0000000731d00000)
from space 1164800K, 0% used [0x0000000731d00000,0x0000000731d00000,0x0000000778e80000)
to space 1164800K, 0% used [0x0000000778e80000,0x0000000778e80000,0x00000007c0000000)
ParOldGen total 6990848K, used 6990706K [0x0000000540000000, 0x00000006eab00000, 0x00000006eab00000)
object space 6990848K, 99% used [0x0000000540000000,0x00000006eaadc9c0,0x00000006eab00000)
Metaspace used 69711K, capacity 70498K, committed 72536K, reserved 1112064K
class space used 9950K, capacity 10182K, committed 10624K, reserved 1048576K
End of LogType:stdout
最佳答案
我在集群中运行spark时遇到了间歇性内存问题,我发现,发生这种情况主要是因为以下原因:-
1)Rdd分区可能太大而无法处理,您可以通过使用重新分区API增加分区数量来减小分区大小。这将减少每个执行器要处理的数据量。由于您为执行器提供了 10g 和 4 个核心,这意味着该执行器可以运行 4 个并发任务(分区),并且这 4 个任务将在它们之间共享 10g 内存,这恰好意味着只需要 2.5g 来处理一个分区。
val rddWithMorePartitions = rdd.repartition(rdd.getNumPartitions*2)
2)如果您的用例是计算密集型的并且您没有进行任何缓存,那么您可以通过调整以下参数来减少分配给存储的内存。
spark.storage.memoryFraction=0.6(默认)
你可以将其更改为以下-
spark.storage.memoryFraction=0.5
3)您应该考虑将执行程序内存增加到 25GB 以上。
--executor-memory 26G
关于java - 调整 Yarn 中的 Spark 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50176269/