Apache Spark Big Data (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Memory Management Architecture: Storage Memory vs Execution Memory, memory fractions, and off-heap memory.
senior LevelMost AskedState ManagementMemory ManagementSystem Design
In Simple Words: Spark divides executor JVM heap into distinct pools:
- Reserved Memory (300 MB): Reserved for Spark internal engine processes.
- Spark Memory (
spark.memory.fraction = 0.6): The remaining 60% of heap is dynamically shared between:- Execution Memory: Used for shuffles, joins, sorts, and aggregations.
- Storage Memory: Used for cached DataFrames (
df.cache()) and broadcast variables. - Dynamic Borrowing: Execution can evict Storage memory if needed. Storage cannot evict Execution memory.
- User Memory (40%): User data structures, UDF allocations, and internal metadata.