The full answer
Work from the hardware down: leave each node some room for the operating system, size executors at about 5 cores each, divide the node's memory between them with room for overhead, then set partition counts from the data size so every core stays busy without spilling. For 40 nodes of 16 cores and 256 GB, that gives 3 executors per node, about 120 executors with 5 cores and about 72 GB of heap each, and input partitions of around 128 MB.
1. Capacity per node
- Reserve 1 core and about 16 GB for the OS, node manager and other services: 15 cores and 240 GB usable.
- Total usable: 600 cores and about 9.6 TB of memory. So 25 TB cannot sit in memory at once; the job must stream through stages, and caching should be selective.
2. Executor size
- 5 cores per executor: enough parallelism per JVM without the I/O and garbage collection problems of very large executors.
- 3 executors per node (15 cores), so 120 executors; on YARN, leave room for the application master, giving 119.
- Memory per executor container: 240 GB / 3 = 80 GB. Split into about 72 GB of heap (
spark.executor.memory) and 8 GB of overhead (spark.executor.memoryOverhead; the default is 10% of executor memory, and PySpark jobs with Python UDFs need more). That is about 14 GB per core. - If garbage collection pauses are long with 72 GB heaps, switch to more, smaller executors (for example 5 per node with 3 cores and about 40 GB each).
spark-submit \
--num-executors 119 \
--executor-cores 5 \
--executor-memory 72g \
--conf spark.executor.memoryOverhead=8g \
--driver-memory 16g \
--conf spark.sql.adaptive.enabled=true \
--conf spark.sql.files.maxPartitionBytes=256m \
--conf spark.sql.adaptive.coalescePartitions.initialPartitionNum=20000 \
--conf spark.sql.adaptive.coalescePartitions.parallelismFirst=false \
--conf spark.sql.adaptive.advisoryPartitionSizeInBytes=256m \
job.py
3. Partitions
- Input: with the default 128 MB
maxPartitionBytes, 25 TB is about 205,000 input partitions, or about 340 waves of 600 tasks. With large columnar files, 256 MB halves the task count and scheduling overhead; the actual bytes read are often far less than 25 TB thanks to column pruning and filters. - Shuffles: size them from the shuffle data, not the input. If a stage shuffles, say, 5 TB, partitions of about 256 MB need about 20,000 partitions. Set
initialPartitionNumhigh and let AQE coalesce down. - Keep partitions a multiple of the core count where possible, so the last wave isn't mostly idle.
4. Other factors
- Disk: shuffles on 25 TB jobs can write many terabytes; nodes need fast local SSDs with enough space for shuffle files and spill.
- Network: shuffle-heavy stages are limited by network bandwidth; reduce shuffled data (filter, project, pre-aggregate, broadcast small tables).
- Skew: AQE handles skewed sort-merge joins; check other stages for straggler tasks.
- Storage: read columnar formats with partition and file pruning, write output in files of roughly 128 MB to 1 GB.
- Dynamic allocation: enable it (with shuffle tracking or an external shuffle service) if the cluster is shared or the job's stages vary a lot in size.
- Driver: 16 GB is enough unless the job collects results or plans very large numbers of files.
- Fault tolerance: long jobs will see failures; write output atomically (Delta or Iceberg tables) and break the job into restartable steps, such as one per day of data.
5. Validate Run on a representative slice first (for example 1 TB), check the Spark UI for spill, garbage collection time, skew and idle cores, then scale. Size from what the stages actually do, not from the input total alone.
Last updated 16 October 2026
Sources