运行时OOM问题

更新时间:
复制 MD 格式

本文介绍MaxCompute Spark作业运行时常见的OOM(Out Of Memory)问题及解决方案。

查看内存使用

LogView 2.0包含Sensor功能,可以查看Master以及每个Worker在运行时的内存和CPU使用情况。排查OOM问题时,建议先通过Sensor确认内存使用趋势,定位是堆内还是堆外内存不足。

Cannot allocate memory

该错误通常是堆外内存(Off-Heap)不足导致。

  • Executor端出现:增大spark.executor.memoryOverhead参数。

  • Driver端出现:增大spark.driver.memoryOverhead参数。

    20/09/01 11:05:27 WARN BlockManager: Persisting block rdd_230_291 to disk instead.
    20/09/01 11:05:29 INFO TableReaderUtil: read table close, blockId: 20200901030346786g5j464pr2_4
    20/09/01 11:05:29 INFO MemoryStore: Block rdd_230_51 stored as values in memory (estimated size 2.7 GB, free 8.4 GB)
    20/09/01 11:05:29 INFO Executor: Finished task 51.0 in stage 52.0 (TID 2260). 2210 bytes result sent to driver
    20/09/01 11:05:37 INFO TableReaderUtil: read table close, blockId: 20200901030346406gdkbyssa_9
    20/09/01 11:05:43 INFO MemoryStore: Block rdd_230_171 stored as values in memory (estimated size 2.7 GB, free 5.7 GB)
    20/09/01 11:05:43 INFO Executor: Finished task 171.0 in stage 52.0 (TID 2380). 2253 bytes result sent to driver
    20/09/01 11:05:46 INFO TableReaderUtil: read table close, blockId: 20200901030346386fnh0tsa_11
    20/09/01 11:05:48 INFO TableReaderUtil: read table close, blockId: 20200901030345422g9kbyssa_18
    OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000004ce300000, 3699376128, 0) failed; error='Cannot allocate memory' (errno=12)

java.lang.OutOfMemoryError: Java heap space

该错误通常是堆内内存不足导致,可通过以下方式解决:

  • 增大Executor堆内存:增大spark.executor.memory

  • 限制Executor并行度:减小spark.executor.cores。多个同时运行的Task共享Executor内存,减少并行度可使单个Task获得更多内存。

  • 增加分区数量:减小每个Executor负载。

  • 排查数据倾斜:如果仅部分Task出现OOM而其他Task内存充足,通常是数据倾斜所致,需检查数据分布并优化。

No route to host / Could not find CoarseGrainedScheduler

出现No route to host: workerd*********Could not find CoarseGrainedScheduler错误,极有可能是某些Executor发生OOM后进程被终止。此类错误不会直接显示OOM信息,需结合LogView Sensor确认内存使用情况,然后参考如下方案调整内存配置:

  • 增大Executor堆内存:增大spark.executor.memory

  • 限制Executor并行度:减小spark.executor.cores。多个同时运行的Task共享Executor 的内存,减少并行度可使单个Task获得更多内存。

  • 增加分区数量:减小每个Executor负载。

  • 排查数据倾斜:如果仅部分Task出现OOM而其他Task内存充足,通常是数据倾斜所致,需检查数据分布并优化。