1. Home
  2. Data Engineering
  3. PySpark Memory & Container Sizing Calculator

PySpark Memory & Container Sizing Calculator

Enter your node RAM, vCPUs, node count and workload type — get sized executor.memory, executor.cores, executor.instances and memoryOverhead, plus a ready spark-submit command and EMR configuration JSON.

Fixes Container Killed Errors Runs in Browser No Signup Required Deterministic Formula
Cluster resource manager
Workload type

Executors

29

Total cores used

145

Total memory used

599 GB

spark-defaults.conf

spark.executor.instances 29
spark.executor.cores 5
spark.executor.memory 18.6g
spark.executor.memoryOverhead 2.1g
spark.driver.memory 18.6g
spark.driver.memoryOverhead 1.9g

spark-submit

spark-submit \
  --master yarn --deploy-mode cluster \
  --conf spark.executor.instances=29 \
  --conf spark.executor.cores=5 \
  --conf spark.executor.memory=18.6g \
  --conf spark.executor.memoryOverhead=2.1g \
  --conf spark.driver.memory=18.6g \
  --conf spark.driver.memoryOverhead=1.9g \
  your_job.py

EMR configuration JSON

[
  {
    "Classification": "spark-defaults",
    "Properties": {
      "spark.executor.instances": "29",
      "spark.executor.cores": "5",
      "spark.executor.memory": "18.6g",
      "spark.executor.memoryOverhead": "2.1g",
      "spark.driver.memory": "18.6g",
      "spark.driver.memoryOverhead": "1.9g"
    }
  }
]

Paste into the EMR console's "Edit software settings" JSON box, or pass with --configurations when creating the cluster via CLI.

How to size your Spark executors

1

Describe your cluster

RAM and vCPUs per node, number of worker nodes, and which resource manager runs it — EMR, Kubernetes, Databricks or standalone.

2

Pick your workload type

JVM-only Scala/Java, heavy PySpark/Pandas UDFs, or ML/vector training — each needs a different cores-per-executor and memoryOverhead balance.

3

Copy the config and deploy it

Copy the spark-defaults.conf block, the matching spark-submit command, or (on EMR) the configuration JSON straight into your cluster.

Frequently Asked Questions

What causes "YARN Container killed: Container limit exceeded"?

Spark's off-heap usage — Python worker processes, JVM overhead, native buffers — grows past spark.executor.memoryOverhead, so YARN kills the container for exceeding its total physical memory limit. The fix is almost always a bigger memoryOverhead relative to executor.memory, not a bigger executor.memory alone. This calculator sizes overhead as a percentage of the executor's memory budget, and raises that percentage automatically for Python-heavy and ML workloads.

Why does this recommend fewer than 5 cores per executor for PySpark UDFs?

Every core running a Python UDF spawns its own Python worker process outside the JVM heap. Packing 5 cores onto one executor means 5 concurrent Python processes competing for the same memoryOverhead budget — the classic cause of container kills. Using 2–3 cores per executor for Python-heavy workloads keeps that off-heap pressure bounded, at the cost of slightly more executors.

Where do the "1 core, 1 GB for the OS" numbers come from?

It's the standard Spark-on-YARN sizing heuristic (originally from Cloudera's tuning guide): every node needs some capacity reserved for the operating system and its own daemons — the YARN NodeManager on EMR, the kubelet on Kubernetes — before Spark can claim the rest for executors.

Does this work for Kubernetes and Databricks, not just EMR?

Yes. The core executor/driver memory and core math is the same everywhere — only the reserved overhead, the Application Master slot (YARN-only) and the deployment snippet change. Kubernetes and standalone get a spark-submit command with the right --master flag; Databricks gets a note to paste the config into the cluster's Spark Config box instead, since it doesn't use spark-submit.

Is this the same as the Spark Config Optimizer?

No — the Spark Config Optimizer is an AI tool that reads a free-text description of your cluster and job. This calculator is a fixed formula: the same inputs always produce the same output, so you can reproduce and explain every number it gives you.