PySpark / PerformanceFig_13 · Lesson 13 / 14
Fig_13 · Sizing · v1.0Partitions + cores + memory

Sizing Spark Work

PARTITIONS · WAVES · CLUSTER CAPACITY

Performance tuning is partly about making the work the right size: enough partitions to keep cores busy, small enough partitions to avoid spill, and enough memory/overhead for the chosen operators.

shuffle partitionsAQE coalesceDBR LTS

01 · What it is

Partitions create tasks; cores run tasks

A stage runs one task per partition. Executor cores are task slots. If a stage has fewer partitions than cores, the cluster waits idle; if it has millions of tiny partitions, scheduling overhead dominates.

The one rule to rememberPartition count controls parallelism; partition size controls memory pressure. Tune for enough full task waves, not the highest possible partition count.

02 · Interactive sizing

Estimate task waves

Partition wave calculator

Move the sliders and watch how partitions, cores, and average partition size change the stage shape.

7
task waves
307 MB
avg partition
192
AQE target partitions

03 · Key levers

Choose the smallest lever

analogyExecutor cores are checkout counters; partitions are customers. Too few customers leaves counters idle; too many tiny customers makes line management the bottleneck.

LeverUse it whenCost
coalesce(n)Reduce partitions cheaply for small outputCan preserve imbalance
repartition(n, col)Need a new balanced key distributionFull shuffle
AQE coalescePost-shuffle partitions are tinyNeeds shuffle stats
More workersEnough balanced tasks existDoes not fix skew or bad plans
More overheadPySpark/Pandas UDF memory pressureCluster resource increase
spark.conf.set("spark.sql.adaptive.enabled", "true")
spark.conf.set("spark.sql.shuffle.partitions", 400)  # upper bound before AQE

agg = events.groupBy("customer_id").sum("amount")
agg.explain(mode="formatted")
# VERIFY after action: AdaptiveSparkPlan + AQEShuffleRead coalesced

04 · Uses and gotchas

Sizing does not replace better plans