Scale Count Before Size
Once an executor shape works, a job that needs more capacity can get it 2 ways: more executors of that shape, or bigger executors. Reach for more executors first. The validated shape keeps its memory per core, its broadcast cost and its crash radius, and the slot count rises in step with the executor count.
What doubling the count buys
Take the 2,400-task read stage again, with tasks of 20 seconds. On 100 slots it runs 24 waves and takes 8 minutes; on 200 slots it runs 12 waves in 4 minutes. The capacity consumed stays the same: 100 slots for 8 minutes and 200 slots for 4 minutes are both 800 slot-minutes. While tasks outnumber slots, more executors buy speed at a flat cost.
| Executors of 5 cores | Slots | Waves | Stage time | Slot-minutes |
|---|---|---|---|---|
| 10 | 50 | 48 | 16 min | 800 |
| 20 | 100 | 24 | 8 min | 800 |
| 40 | 200 | 12 | 4 min | 800 |
| 80 | 400 | 6 | 2 min | 800 |
| 160 | 800 | 3 | 1 min | 800 |
| 600 | 3,000 | 1 | 20 s | 1,000 |
The flat line ends when slots outnumber tasks. At 3,000 slots the stage still has 2,400 tasks, so it runs a single 20-second wave with 600 slots idle, and the run pays for all 3,000. Each stage hits this ceiling at its own task count: in a job with a 2,400-task read and a 600-task shuffle, the shuffle stage stops gaining at 600 slots, long before the read stage does. Past a stage's ceiling, only more partitions make it faster.
Why not more cores per executor
The tempting shortcut is to double spark.executor.cores from 5 to 10 on the same executors. Slots double too, but the job walks back into the fat-executor costs: 10 tasks per storage client, a heap with twice the tasks behind every pause, and twice the work rerun per crash. Unless memory doubles with it, each task's share of execution memory halves as well.
A job's slowest stage has 180 tasks of about 2 minutes each, running on 24 executors of 5 cores with no spill. What does moving to 48 executors of the same shape do to that stage?
- It drops from 2 waves to 1, about 4 minutes to 2, with 60 of the 240 slots idle
- It drops from 2 waves to 1, but per-task memory halves, so the tasks start to spill
- Nothing changes, because the stage's 180 tasks are fixed and so is its runtime
- It drops from 4 waves to 2, since each added executor adds 5 tasks to the stage
When size is the right lever
Bigger executors help when a single task needs more memory than it gets. A task's memory comes from its own executor's unified pool, shared with the other tasks running beside it, so it depends on heap per core and never on how many executors exist. Adding 50 executors leaves every task with the memory it had. Before raising memory per core, try to shrink the task's input: more shuffle partitions, or a salted hot key. When the input can't shrink, raise spark.executor.memory with cores held at 5, or keep the heap and drop to 4 cores.
- Add executors
- The stage has more tasks than slots
- Tasks finish without spilling
- Many short waves make up the stage time
- The goal is a shorter run at about the same cost
- Grow each executor
- One task spills or fails on memory
- Its partition can't be split any further
- A large broadcast takes much of each heap
- Memory per task, not slot count, is the limit
A stage has 2,000 shuffle partitions of about 200MB. One task processes 9GB for a single customer ID and spills heavily while the others finish cleanly. Which change targets the problem?
- Double the executor count, since more slots give the 9GB task more memory
- Raise shuffle partitions to 4,000, since smaller partitions will split the 9GB key
- Double cores per executor, which gives the hot task more threads to work with
- Salt the hot customer ID so its rows spread over many tasks, then combine the pieces
About this lesson
This section is part of the Cluster Sizing: 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.