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.

The 6MB country table is under the 10MB broadcast threshold, so it joins inside stage 1 without a shuffle. Stage 1 also runs the partial aggregation, and the groupBy adds the job's only shuffle, about 400GB, between the 2 stages.
  • 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

SlotsStage 1 wavesStage 1 timeStage 2 wavesStage 2 timeTotal
1008241 min2015 min56 min
1505527.5 min1410.5 min38 min
2004120.5 min107.5 min28 min
3002814 min75.3 min19.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.

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.

DecisionValueWhere it came from
Read tasks8,1921TB ÷ 128MB splits
Shuffle partitions2,000400GB at about 200MB each
Slots200Smallest count inside 30 minutes
Executors40 × 5 cores, 36GB heapThe 5-core rule and the node fit
Nodes14, each 16 cores and 128GB3 executors per node, plus the driver
Expected runtime28 min20.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?

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.