A Worked Sizing
Here is the whole method on a single job. A daily batch reads 1TB of Parquet events, filters them, joins a 6MB country table, aggregates by day and title, and writes the result. It must finish within 45 minutes of starting, and the team keeps a third of that as headroom, so the compute target is 30 minutes.
- events (1TB) (source, Parquet files)
- countries (6MB) (source, broadcast)
- Stage 1: scan, filter, join (transform, Spark stage); parallelism: 8,192 partitions
- Stage 2: aggregate (transform, Spark stage); parallelism: 2,000 partitions
- daily_rollup (storage, Parquet files); freshness: 45 min
- events (1TB) -> Stage 1: scan, filter, join
- countries (6MB) -> Stage 1: scan, filter, join
- Stage 1: scan, filter, join -> Stage 2: aggregate
- Stage 2: aggregate -> daily_rollup
Step 1: bytes to tasks
At 128MB per split, 1TB on disk, which is 1,024GB, becomes 8,192 read tasks. A test run on a 10% sample wrote 40GB of shuffle data, which scales to about 400GB for the full input. At roughly 200MB per partition that calls for 2,048 partitions; round to 2,000, a count that will divide evenly into the slot count chosen below, and set spark.sql.shuffle.partitions to it.
Step 2: measure task time
Task durations come from a measurement. On the sample run a stage 1 task took about 30 seconds and a stage 2 task about 45, with shuffle partitions set to 200 so each held close to 200MB. Task time depends on the bytes a task handles, and the sample's tasks handled the same sizes as the full run's will, so the durations carry over even though the sample had a tenth as many tasks.
Step 3: pick the slot count
| Slots | Stage 1 waves | Stage 1 time | Stage 2 waves | Stage 2 time | Total |
|---|---|---|---|---|---|
| 100 | 82 | 41 min | 20 | 15 min | 56 min |
| 150 | 55 | 27.5 min | 14 | 10.5 min | 38 min |
| 200 | 41 | 20.5 min | 10 | 7.5 min | 28 min |
| 300 | 28 | 14 min | 7 | 5.3 min | 19.3 min |
The 200-slot row is the smallest that meets the 30-minute target, and its stage 2 runs exactly 10 full waves. Stage 1's last wave holds 192 tasks on 200 slots, so even its tail keeps 96% of the slots busy. The 300-slot row finishes under 9 minutes sooner at almost the same cost: 300 slots for 19.3 minutes is about 5,790 slot-minutes against 5,600, roughly 3% more. That 3% is idle time in partial waves, since stage 2's seventh wave holds only 200 tasks and a third of the cluster waits through it. Both rows meet the deadline, so take the smaller cluster: fewer nodes to place, and no partial wave in stage 2.
- 93 task-hours
Spread across 200 slots, that work comes to about 28 minutes, which agrees with the wave arithmetic when every wave is full.
Step 4: slots to executors to nodes
At 5 cores each, 200 slots are 40 executors. The node from the previous section, 16 cores and 128GB with 1 core and 8GB reserved, holds 3 executors with 36GB heaps, which gives each task about 4.3GB of execution memory; the sample run showed no spill at that size. Forty executors need 14 nodes, since 40 ÷ 3 rounds up to 14. Those nodes hold 42 executor spaces, the driver takes 1 in cluster mode, and 41 remain for the 40 the plan needs.
| Decision | Value | Where it came from |
|---|---|---|
| Read tasks | 8,192 | 1TB ÷ 128MB splits |
| Shuffle partitions | 2,000 | 400GB at about 200MB each |
| Slots | 200 | Smallest count inside 30 minutes |
| Executors | 40 × 5 cores, 36GB heap | The 5-core rule and the node fit |
| Nodes | 14, each 16 cores and 128GB | 3 executors per node, plus the driver |
| Expected runtime | 28 min | 20.5 min + 7.5 min |
Step 5: check the first real run
Planning numbers are predictions, so set them beside the first full run in the Spark UI: the task count of each stage, the median task duration in each, and any spill. If stage 2 shows fewer than 2,000 tasks, AQE merged small partitions after measuring them. If median task times came in above 30 and 45 seconds, redo the slot arithmetic with the measured values before adding nodes; if spill appears, revisit memory per core.
Next quarter the events grow to 2TB. Per-task times stay the same, and the shuffle write doubles to 800GB at the same partition size. Which plan keeps the run near 28 minutes?
- Forty executors of 10 cores on the same 14 nodes, since doubling cores doubles the slots
- Eighty executors of 5 cores on 27 nodes with 4,000 shuffle partitions, giving the same 41 and 10 waves
- Eighty executors on 27 nodes with shuffle partitions left at 2,000, since partition count ignores data size
- Forty executors with 72GB heaps on the same 14 nodes, since larger heaps make each task finish twice as fast
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.