Apache Spark Big Data (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Debugging Executor OOM: `Java heap space` vs `Container killed by YARN/K8s for exceeding memory limits`.
senior LevelMemory ManagementDocker & ContainersKubernetes
In Simple Words: Distinguishing the two distinct out-of-memory errors:
java.lang.OutOfMemoryError: Java heap space:- Occurs inside the JVM.
- Root Cause: Excessive memory allocations during large joins, aggregations, or huge arrays cached in memory.
- Fix: Increase
spark.executor.memoryor increase shuffle partitions (spark.sql.shuffle.partitions) to reduce partition size.
Container killed by YARN / K8s for exceeding memory limits:- The OS/Cgroup killed the executor container.
- Root Cause: Off-heap memory exceeded allocated overhead (PySpark Python memory, native C-libraries, heavy off-heap shuffle buffers).
- Fix: Increase
spark.executor.memoryOverhead(e.g. from 10% to 25%).