The Executor Memory Split

Every executor runs as a single JVM process, and the memory it gets is fixed when it launches. The spark.executor.memory setting, which --executor-memory sets on spark-submit, becomes that JVM's maximum heap. Inside the heap, Spark draws 3 regions, each with its own job and its own way of failing. A further pool, the overhead, sits outside the heap and gets its own section later in this lesson.

Three regions inside the heap

Bottom of the heap to top

Sizing an 8 GB executor

The arithmetic runs in megabytes of 1,024 KB, which the Spark UI writes as MiB: start from the heap, take away the reserved block, then split the rest by spark.memory.fraction. The executor below, 8 GB of heap and 4 cores, is the running example for every section that follows.

RegionHow it is computedSize at an 8 GB heap
Heap (`spark.executor.memory`)heap in GB times 1,0248,192 MB
Reservedfixed300 MB
Usable heapheap minus reserved7,892 MB
Unified (`spark.memory.fraction` 0.6)usable times 0.64,735 MB
Storage side (`storageFraction` 0.5)unified times 0.5about 2,368 MB
Execution sideunified minus storage sideabout 2,367 MB
User memoryusable times 0.43,157 MB

Look at where the 0.6 lands. It multiplies the usable heap, so an executor launched with 8 GB gives Spark's managed region about 4.6 GB, a little over half of what the command line asked for. The storage and execution sides are a starting position: the next section shows each one growing into the other's space, and what happens when the owner wants it back.

Spark 1.6 introduced this layout with spark.memory.fraction at 0.75. Spark 2.0 lowered the default to 0.6, where it has stayed.

Which setting moves which region

SettingDefaultRaising it does this
`spark.executor.memory`1gGrows every region except reserved, in proportion
`spark.memory.fraction`0.6Grows unified memory and shrinks user memory by the same amount
`spark.memory.storageFraction`0.5Widens the cache's protected share and narrows execution's
`spark.executor.cores`1 on most cluster managersChanges no region, but more tasks share the execution side at once

An executor launches with spark.executor.memory set to 4g and every other memory setting at its default. How large is its unified region, the pool execution and storage share?

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.