How this calculator works
Spark sizing fails in two familiar ways. Someone divides a node's RAM by the executor count, forgets the JVM heap is not the whole container, and YARN kills the job at 90% with Container killed by YARN for exceeding memory limits. Or spark.sql.shuffle.partitions stays at 200 on a 600-core cluster and most of it idles through every shuffle. This is the arithmetic I kept re-deriving while tuning Spark on EMR and Databricks.
Reserve first, then divide
A node's advertised specification is not what YARN can hand out. The operating system, the NodeManager and, on EMR, the instance agent take cores and memory first, so the model reserves one core and 8% of RAM per node — floored at 1 GiB, capped at 16 GiB. That 8% is a convention, not a reading of your cluster, and EMR is markedly more conservative on smaller nodes: an m5.2xlarge has 32 GiB, of which 8% leaves 29 GiB, while EMR's default yarn.nodemanager.resource.memory-mb hands out 24,576 MB. Read that property off your own cluster, subtract it from the node's RAM, and type the difference in as the reservation — every number downstream moves with it.
Why five cores
spark.executor.cores is how many tasks share one JVM. Around five, one HDFS or S3 client stops gaining throughput from more concurrency while GC, lock contention and the blast radius of losing an executor keep growing. Five is a ceiling, not an answer: the model starts there and drops to four or three only when five would strand more than 10% of a node's cores, and never below three on a node with six or more, because narrow executors duplicate broadcast data and lose intra-executor parallelism.
Memory is the second constraint on how many executors fit, but a deliberately weak one: the model only shrinks the count when a node cannot give every container the cores would have allowed a whole 1 GiB YARN allocation increment. At the default reservation that takes a node with under roughly a third of a GiB of RAM per vCPU — some six times leaner than a c5, and leaner than anything in the table below. No catalogue instance trips it, so the packing you see there is decided entirely by cores. On a hand-entered shape that does trip it, the model drops to the executor count memory allows and widens each one back out toward the target.
The memory formula
overhead = max(384 MB, factor × executorMemory) // factor defaults to 0.10
container = executorMemory + overhead
⇒ factor branch — when factor × container ÷ (1 + factor) ≥ 384 MB
(at factor 0.10, that is every container ≥ 4224 MB)
executorMemory = container ÷ (1 + factor)
rounded down to a whole GiB — or to a 128 MB
step when the quotient is under 2 GiB
⇒ floor branch — when it lands under 384 MB, the factor is moot
executorMemory = container − 384 MB
rounded down to a 128 MB step
The container is what YARN allocates; the heap is only part of it, and solving backwards from the container budget is the step people skip. Which branch you land in matters more than it looks. The 384 MB floor dominates small containers — nearly 40% of a 1 GiB one — which is why tiny executors waste so much, and once the floor binds the overhead cannot grow, so rounding the heap to a whole GiB would strand up to 1 GiB of the container that nothing could ever claim. That is why the floor branch rounds in 128 MB steps instead: a 3 GiB container becomes 2688m of heap plus 384 MB of overhead, filling it exactly, rather than 2g plus 384 MB and 640 MB of dead space. The c5.large row in the table below is this case. YARN rounds requests up to a whole allocation increment, so the budget itself is trimmed to a whole GiB first; otherwise containers that each "fit" get rounded up and no longer do.
Partitions come from the data
Shuffle partitions are sized from the data you are moving: 128–200 MB each, rounded up to a whole multiple of the task slots so the last wave is full rather than a few tasks holding the stage open. That rounding is cheap when the job runs many waves, because it only shaves a few MB off each partition. It is not cheap when the data does not fill even one wave — rounding 8 partitions up to 145 slots multiplies the task count 18-fold and leaves ~7 MB per task, and the calculator says so rather than pretending the rounding was free. Since Spark 3.2, adaptive query execution coalesces them at runtime, so treat the number as an upper bound and let spark.sql.adaptive.advisoryPartitionSizeInBytes tune it.
What the model does not know
It does not know your join skew, whether you cache DataFrames, or that one key holds 40% of the rows. It assumes YARN, whole-GiB increments, a shuffle roughly the size of the input, and no off-heap allocation beyond the overhead. Every number is a starting point to take into the Spark UI: read the task duration spread, the spill columns and GC time, then move one setting at a time.
Starting points by EC2 instance type
Derived by this calculator for a ten-node cluster in cluster deploy mode, reserving one core and the default memory slice per node. m5 gives 4 GiB per vCPU, r5 gives 8 and c5 gives 2, and that ratio does not change the shape of the packing at all: at any given vCPU count all three families land on the same executor.cores and the same executors per node — 16 vCPU gives 5 cores and 3 executors on m5.4xlarge, r5.4xlarge and c5.4xlarge alike. What the ratio changes is the heap inside each executor: 17g, 35g and 8g respectively. A c5 does not run out of executor slots before it runs out of cores; it runs out of room to shuffle, join and cache in, which shows up as spilling rather than as idle cores.
Check before you copyThe usable-RAM column is an assumption, not a fact about your clusterEvery figure in this table is derived from the default reservation — one core and 8% of RAM — not from what your NodeManager actually advertises. On several instance types EMR is markedly more conservative than 8%. On m5.2xlarge this table assumes 29 GiB usable, while EMR's default yarn.nodemanager.resource.memory-mb is 24,576 MB. Two of the 14 GiB containers below need 28 GiB, so on a real EMR node only one of them fits: YARN quietly schedules half the executors you sized for and nothing in the logs says why. Read yarn.nodemanager.resource.memory-mb off your own cluster, subtract it from the node's RAM, type that in as the reservation, and use the numbers the calculator gives you then.
Frequently asked questions
Why five cores per executor and not more?
Every task in an executor shares one JVM, one garbage collector and one HDFS/S3 client. Beyond roughly five concurrent tasks the client stops delivering more read throughput while GC pauses, lock contention and the cost of losing a single executor all keep rising. Five is not sacred — it is the point where the returns flatten on most storage backends. Fewer cores are fine; a lot more usually is not.
How is spark.executor.memoryOverhead calculated?
Overhead is max(384 MB, overheadFactor × spark.executor.memory), and this calculator defaults the factor to 0.10, which is Spark’s own default on YARN. The heap and the overhead have to fit inside one YARN container together, so the calculator solves backwards for the heap — and which side of that max() wins changes the arithmetic. When the factor wins, the heap is container ÷ (1 + factor), rounded down to a whole GiB, or to a 128 MB step when the quotient is under 2 GiB. When the 384 MB floor wins — at the default factor that is every container below 4,224 MB — the factor stops mattering and the heap is container − 384 MB, rounded down to a 128 MB step. The finer rounding there is deliberate: the overhead is pinned at 384 MB and cannot grow into whatever a whole-GiB rounding would shave off, so that memory would simply be lost. A 3 GiB container therefore gives 2688m of heap plus 384 MB of overhead, not 2g. Overhead pays for JVM metaspace, thread stacks, Netty shuffle buffers and Python worker processes — none of which come out of the heap.
My PySpark job keeps getting killed by YARN. What should I change?
Raise the overhead factor. Python workers are separate OS processes that live entirely outside the JVM heap and are charged against the container, so a job that is fine in Scala at 0.10 will be killed at the same setting in PySpark. Try 0.15 for plain PySpark and 0.20 to 0.25 when pandas UDFs, Arrow or ML libraries are involved, then re-derive the heap from the same container budget — which is what this calculator does when you change the factor.
How many shuffle partitions should I set?
Aim for 128 to 200 MB of shuffle data per partition, then round up to a whole multiple of your total task slots so the last wave is full rather than a long tail of idle cores. That rounding is close to free while there are several waves to spread it over — the partitions shrink by a few MB each. It is not free when the data is smaller than one wave: rounding 8 partitions up to 145 does not fill a tail, it multiplies the task count 18-fold and cuts every task to a few MB, and the honest fix is fewer nodes or more data. Spark’s default of 200 knows nothing about your data or your cluster either: it starves a 500-core cluster and shreds a 10 GiB job into thousands of tiny tasks.
Does adaptive query execution make this unnecessary?
No, but it changes what the number means. On Spark 3.2 and later AQE is on by default and coalesces partitions at runtime from real shuffle statistics, so spark.sql.shuffle.partitions becomes an upper bound rather than an exact count, and spark.sql.adaptive.advisoryPartitionSizeInBytes does the fine tuning. Executor cores, memory and overhead are still fixed when the JVM starts — AQE cannot help you there.
Why did my --num-executors get ignored on EMR?
EMR enables dynamic allocation by default, and it does so in the cluster’s spark-defaults, so it is on in client mode exactly as it is in cluster mode — the deploy mode has nothing to do with it. While spark.dynamicAllocation.enabled is true, Spark scales executors itself and the static count is ignored. Either set it to false, or keep dynamic allocation and feed these numbers into spark.dynamicAllocation.minExecutors and maxExecutors instead. The generated spark-submit command sets it to false so the sizing actually takes effect.
Is any of this stored or uploaded?
No. The whole calculator is a few hundred lines of arithmetic running in your browser. There is no server, no API and no analytics on the numbers you type. Your inputs are remembered in this browser’s local storage so the page comes back the way you left it, and clearing site data removes them.