Spark executors keep dying with OOM in one stage — triage the cause from the log
A nightly job (8 GB executors, ~100 GB input, spark.sql.shuffle.partitions=800) now fails. AQE is disabled on this cluster. Below is what the driver log and the Spark UI show for the failing stage.
Constraints: name the cause; say what in the readout rules out a driver OOM, a bad node and a shuffle-fetch failure; give the fix.
Stage 12 (SortMergeJoin, 800 tasks): 799 succeeded, 1 failed
task 37.0 executor 3 host w-07 java.lang.OutOfMemoryError: Java heap space
task 37.1 executor 9 host w-02 java.lang.OutOfMemoryError: Java heap space
task 37.2 executor 14 host w-11 java.lang.OutOfMemoryError: Java heap space
task 37.3 executor 5 host w-04 java.lang.OutOfMemoryError: Java heap space
Job aborted: Task 37 in stage 12.0 failed 4 times
Shuffle read, task 37: 52 GB median task: 110 MB
Driver: heap 30% used, no errorsDiagnose the cause.
A skewed data slice: task 37 fails on four hosts in a row, reading 52 GB against a 110 MB median. A bad node would fail on one host, a lost shuffle would show FetchFailedException, and the driver is healthy. Spread the key — salting or AQE's skew join.
- Doubling executor memory, which only moves the wall for a growing hot key
- Raising shuffle partitions, which cannot split a single key's rows
- Treating repeated failures of one task as flaky hardware
- What would a
FetchFailedExceptionin this stage tell you instead? - When does raising
spark.executor.memoryOverheadfix an executor kill?
Read the output sign by sign.
- Where it fails.
OutOfMemoryErrorin tasks on executors, while the driver sits at 30% heap with no errors — so it is not acollect()or a broadcast built on the driver. - What repeats. The same task 37 fails on four different executors and hosts until
spark.task.maxFailures(default 4) runs out. A bad node would tie the failures to one host, and the task would pass elsewhere. Here a data slice is failing. - What is absent. No
FetchFailedException: the previous stage's shuffle output is intact, so this is not a lost executor. - Why. Task 37 reads 52 GB against a 110 MB median — a hot key landed in its partition. An 8 GB executor cannot hold it, and 32 GB would only postpone the problem while the key grows.
from pyspark.sql import functions as F
# find the key
left.groupBy("join_key").count().orderBy(F.desc("count")).show(5)
# option 1: turn AQE on — its skew join splits such partitions in a sort-merge join
spark.conf.set("spark.sql.adaptive.enabled", "true")
spark.conf.set("spark.sql.adaptive.skewJoin.enabled", "true")
# option 2: salt the hot key by hand (see the salting question)If the key is a service value that should never match, or NULL on the preserved side of an outer join (an inner join already drops NULL keys), filtering it out before the join is simpler.