EXECUTION & PERFORMANCEPySpark

Memory Management & Tungsten

Distributed data processing with Spark — pick a topic on the left and its full breakdown loads here: the execution model, worked jobs and diagrams, performance and shuffle behavior, and the habits that keep Spark jobs fast, correct, and affordable.

18 min readTopics chapter readerLevel · Performance
01 · Orientation

What You'll Master Here

execution memory is the workbench (active processing), storage memory is the shelf (cached data). They flex into each other, and if the workbench overflows, work spills onto the floor (disk).

4 min · Topic 1 of 4

Spark is an in-memory engine, so understanding how it uses executor memory is the key to avoiding its two most feared failures: OutOfMemoryError (the job crashes) and excessive spill (the job crawls). This chapter opens the executor memory model and the Tungsten engine that makes Spark fast.

You will learn how an executor divides its heap into execution memory (for shuffles, joins, aggregations, sorts) and storage memory (for cached data), how they share space dynamically, what off-heap memory is, and how Tungsten, binary memory layout plus whole-stage code generation, gives the structured APIs their speed.

With a diagram of the memory regions and a worked OOM/spill diagnosis. This is the chapter that turns cryptic memory errors into a checklist.

Core mental model

An executor's memory is a shared workshop: execution memory is the workbench (active processing), storage memory is the shelf (cached data). They flex into each other, and if the workbench overflows, work spills onto the floor (disk).

Why it matters

OOM and spill are the most common ways Spark jobs fail or slow down. Knowing the memory regions and how to tune them (executor memory, partition size, memory fraction) is essential operational skill, and a frequent interview deep-dive.

execution memory
Memory for shuffles, joins, sorts, and aggregations during processing.
storage memory
Memory for cached/persisted data blocks.
spill
Writing data to disk when it does not fit in execution memory.
Tungsten
Spark's engine for binary memory layout and whole-stage code generation.
Common mistake

Responding to every OOM by just raising executor memory. Often the real fix is smaller partitions or less skew; throwing memory at it is costly and may not help.

Better habit

Read OOM/spill as a signal about partition size and skew, not just total memory.

Know the split: execution vs storage, sharing one unified region.

Trust Tungsten codegen; write clear structured-API code so it can apply.

The big idea

Executor memory is shared between active processing (execution) and cached data (storage). Most memory failures are really partition-size or skew problems. Tungsten is why the structured APIs are fast: compact binary data and generated code.

Remember this

Executor memory splits into execution and storage regions that flex dynamically; OOM and spill usually trace to oversized partitions or skew, not just low total memory. Tungsten (binary layout + codegen) powers the structured APIs' speed.

Practice2 prompts
  1. What are the two main regions of executor memory, and what does each hold?
  2. Why is raising executor memory not always the right fix for OOM?