The memoryOverhead OOM

Everything so far lives inside the JVM heap. The cluster manager does not police the heap, though. It limits the whole process, and it sets that limit at the heap plus spark.executor.memoryOverhead. When the process's resident memory crosses the limit, the cluster manager kills it outright, with no exception, no spill and no chance to finish the task.

What lives outside the heap

None of this appears in Spark's memory accounting, so none of it can spill or be evicted. The default overhead is the larger of the floor and the share: for the running example's 8,192 MB heap, 10% gives 819 MB, and the cluster manager grants a container of 9,011 MB.

Heap error or container kill

Heap OutOfMemoryError
  • The JVM throws java.lang.OutOfMemoryError: Java heap space inside a task
  • The executor log holds the error and its stack trace
  • The task fails with the error as its reason
  • Fix with less data per task, more heap, or fewer cores
Container kill
  • The cluster manager kills the process from outside the JVM
  • The executor log stops mid-stream, with no OutOfMemoryError
  • The driver reports ExecutorLostFailure, often with exit code 137, which is 128 plus signal 9
  • Fix with more spark.executor.memoryOverhead or fewer concurrent tasks

The tell is the mismatch. In the Executors tab, covered in the next section, a dead executor's storage memory can read far below its total, and its last log lines can be routine task progress, because the heap never ran out. The process outgrew its limit in memory the JVM does not count. The driver's failure reason starts with ExecutorLostFailure (executor 7 exited caused by one of the running tasks), followed by the cluster manager's own words: the container was killed for exceeding memory limits.

Raising the overhead

Fix the region that grew. Raising spark.executor.memory from 8g to 9g grows a heap that had room and adds only about 100 MB of overhead through the 10% share. Set the overhead directly instead:

from pyspark.sql import SparkSession

spark = (
    SparkSession.builder
    .appName("trips_nightly")
    .config("spark.executor.memory", "8g")
    .config("spark.executor.cores", "4")
    .config("spark.executor.memoryOverhead", "2g")
    .getOrCreate()
)

The container grows from 9,011 MB to 10,240 MB, and every added megabyte lands outside the heap, where the kills came from. Spark 3.3 added spark.executor.memoryOverheadFactor for setting the share instead of a size: raising it from 0.10 to 0.20 gives the same 8 GB heap about 1,638 MB of overhead.

Executors keep dying mid-stage. The driver shows ExecutorLostFailure with exit code 137, the executor logs end with no OutOfMemoryError, and the dead executors' storage memory read 0.9 GiB of 4.4 GiB. Each has an 8g heap and the default overhead. What do you change?

About this lesson

This section is part of the Memory and Caching: Intermediate lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.