Why your Spark app gets no YARN resources

Do not start with the settings. Start with the symptom. Run one command and read the state of the app. The state tells you which of five cases you have. Each case has one diagram, one cause and one fix.

Summary

Start here

Read the spark-submit output first. If spark-submit did not fail, run yarn application -status <appId> and read State and Diagnostics. Then select your case in the diagram.

Decision tree. The output of spark-submit and of yarn application -status leads to one of five cases. spark-submit output, then yarn application -status <appId> Fails at submit "is above the max threshold of this cluster" State: ACCEPTED "Queue's (or User's) AM resource limit exceeded" RUNNING, few executors Your usage stops at the queue capacity. Cluster is idle. RUNNING, executors wait The queue has free memory, but no node has enough. Case 1 Container too big Case 2 or Case 3 AM pool full (3 = Oozie) Case 4 User limit Case 5 No node has room
executor memory ApplicationMaster (AM) used by other apps free request that waits or fails

Case 1: One container is too big

fails at once
A 24 GB executor plus 2.4 GB overhead goes past the 24 GB cap and is rejected. A 20 GB executor plus 2 GB overhead fits. maximum-allocation-mb = 24 GB --executor-memory 24g 24 GB executor memory +2.4 ✗ rejected (26.4 GB) --executor-memory 20g 20 GB executor memory +2 ✓ fits (22 GB) Spark adds overhead: max(384 MB, 10% of the memory). YARN rounds each request up to a multiple of yarn.scheduler.minimum-allocation-mb (1 GB by default).

What you see

spark-submit stops before the app starts. The error is Required executor memory (...) is above the max threshold (... MB) of this cluster! The same check applies to the driver AM.

Why

YARN does not give one container more than the cap. Spark asks for memory plus overhead, so --executor-memory must be smaller than the cap.

Fix

Make the executor or driver smaller, and use more executors. Or ask the admin to increase the cap.

yarn.scheduler.maximum-allocation-mb, yarn.scheduler.capacity.<queue-path>.maximum-allocation-mb

Case 2: The AM pool is full

ACCEPTED
Queue etl has 48 GB with 23 GB free. Its AM pool is 5 GB and is full with two AMs. A third AM waits in ACCEPTED. Queue etl: 48 GB executors 20 GB AMs 5 free 23 GB AM pool = maximum-am-resource-percent 0.1 × 48 GB ≈ 5 GB App 1 AM · 2 GB App 2 AM (driver) · 3 GB App 3 AM (driver) · 3 GB ✗ ACCEPTED: waits for room The queue has 23 GB free, but App 3 waits. Its AM does not fit in the 5 GB AM pool. In yarn-cluster mode the driver is the AM, so spark.driver.memory + overhead uses this pool. YARN always lets the first app in an empty queue start. The second and third apps wait.

What you see

State is ACCEPTED for a long time. Diagnostics: Queue's AM resource limit exceeded or User's AM resource limit exceeded. The queue does not look full.

Why

All AMs in a queue share a small pool: 10% of the queue by default. Normal containers cannot use this pool, and AMs cannot use the rest of the queue.

Fix

  • Find and kill old or stuck apps in the queue.
  • Use a smaller spark.driver.memory.
  • Ask the admin to increase yarn.scheduler.capacity.<queue-path>.maximum-am-resource-percent (for example to 0.3).

Case 3: Oozie launchers lock the AM pool

ACCEPTED, forever
Two Oozie launchers use 4 GB of a 5 GB AM pool. Each launcher waits for its Spark job. Each Spark driver AM needs 3 GB and waits for room. Nothing ends. AM pool of the queue: 5 GB Launcher A · 2 GB Launcher B · 2 GB 1 GB free Oozie launcher A RUNNING · runs spark-submit Oozie launcher B RUNNING · runs spark-submit starts, then waits for it starts, then waits for it Spark driver AM A · 3 GB ACCEPTED Spark driver AM B · 3 GB ACCEPTED needs 3 GB, only 1 GB free The launchers wait for the Spark jobs. The Spark jobs wait for the launchers to free the pool. Nothing ends.

What you see

The Oozie launcher app is RUNNING. Its Spark app is ACCEPTED with "AM resource limit exceeded". It often starts when several workflows start at the same time.

Why

One Oozie Spark action uses two AMs. The launcher (2 GB by default) keeps its AM until the Spark job ends. In yarn-cluster mode the Spark driver is the second AM.

Fix

  • Send the launchers to a different queue: <launcher><queue>oozie</queue></launcher> in the action.
  • Make the launcher smaller: oozie.launcher.memory.mb (older name: oozie.launcher.yarn.app.mapreduce.am.resource.mb). It only runs spark-submit.
  • Increase the AM percent of the queue (Case 2).

Case 4: You reached your user limit

RUNNING, few executors
A 96 GB cluster. With user-limit-factor 1, one user stops at the queue capacity of 48 GB while 48 GB is idle. With factor 2 the user can grow to 96 GB. user-limit-factor = 1 (default) your app · 48 GB idle · 48 GB limit = 1 × queue capacity (48 GB) user-limit-factor = 2 your app can grow to 96 GB limit = 2 × 48 GB, never above maximum-capacity Cluster 96 GB · queue etl capacity 50% (48 GB) · maximum-capacity 100%

What you see

The app is RUNNING with fewer executors than you asked for. Your usage stops at the queue capacity. Other parts of the cluster are idle.

Why

With user-limit-factor = 1, one user can never use more than the queue capacity, "irrespective of how idle the cluster is". On EMR most jobs run as the user hadoop, so all of them share this one limit.

Fix

First, make sure that you did not set the limit yourself: check spark.executor.instances and spark.dynamicAllocation.maxExecutors.

Then ask the admin to increase yarn.scheduler.capacity.<queue-path>.user-limit-factor (for example to 2), or use a queue with more capacity. Check that maximum-capacity is also larger than capacity.

Case 5: No single node has room

RUNNING, executors wait
Four nodes of 24 GB. Each node has 4 GB free, 16 GB in total. A 6 GB executor does not fit on any node. yarn.nodemanager.resource.memory-mb = 24 GB on each node 4 free used 20 node 1 4 free used 20 node 2 4 free used 20 node 3 4 free used 20 node 4 New executor · 6 GB Free in total: 16 GB Largest free on one node: 4 GB ✗ does not fit on any node A container must fit on one node. YARN cannot join 4 GB from node 1 and 2 GB from node 2.

What you see

The app is RUNNING. Some executors start, others wait. The queue and the user are below their limits.

Why

Each node gives YARN only yarn.nodemanager.resource.memory-mb. Large containers need one node with that much free memory. The free memory is in small parts on many nodes.

Fix

Use smaller executors (more of them), wait for other apps to end, or add nodes. Run yarn node -list -showDetails to see the free memory on each node.


How the five cases fit together

Each container request goes through four checks in this order. The Oozie case is Check 2 with two AMs for each job.

A container request goes through four checks: size cap, AM pool, user share, free space on one node. Each check has its own failure symptom. Request memory + overhead 1 · Size cap one container must be below the cap 2 · AM pool AMs only: room in 10% of the queue 3 · User share your usage is below your limit 4 · One node one node has this much free memory ✓ fails at submit Case 1 ACCEPTED Case 2, Case 3 few executors Case 4 executors wait Case 5 Only memory counts by default. The default DefaultResourceCalculator ignores vcores.

Commands to find the case

# 1. State and Diagnostics of one app (Cases 2, 3)
yarn application -status <appId>

# 2. All apps that wait or run, to see who uses the queue (Cases 2, 3, 4)
yarn application -list -appStates ACCEPTED,RUNNING

# 3. Capacity and usage of a queue (Case 4)
yarn queue -status <queue>

# 4. Free memory on each node (Case 5)
yarn node -list -showDetails

The ResourceManager web UI shows the same data. The Scheduler page shows each queue with its AM limit and user limit.

See all these settings on your EMR cluster

The script yarn_resource_config.py reads yarn-site.xml, capacity-scheduler.xml, spark-defaults.conf and oozie-site.xml. It shows each setting with its value, its meaning and its case. On EMR it also shows the cluster ID and the instance groups, and it reads the AM pool, the queue usage and the free memory on each node from the ResourceManager. It uses only Python 3 and changes nothing.

Option 1: on the primary node. Connect with SSM or SSH, then run:

aws ssm start-session --target <primary-node-instance-id>   # or: ssh hadoop@<primary-node-dns>
curl -fsSLO https://github.com/ryandam9/yarn-resource-config/releases/latest/download/yarn_resource_config.py
python3 yarn_resource_config.py | less

If the node has no internet access, copy the script through S3 with aws s3 cp.

Option 2: as an EMR step. The step runs on the primary node. Read the output in the console (Steps, then stdout) or in the step's log folder in S3.

aws s3 cp yarn_resource_config.py s3://<bucket>/tools/
aws emr add-steps --cluster-id j-XXXXXXXX --steps \
  'Type=CUSTOM_JAR,Name=yarn-resource-config,ActionOnFailure=CONTINUE,Jar=command-runner.jar,Args=[bash,-c,"aws s3 cp s3://<bucket>/tools/yarn_resource_config.py /tmp/ && python3 /tmp/yarn_resource_config.py"]'

All related settings, by case

Look at a setting only when a case points to it. On EMR, read the real values in /etc/hadoop/conf/. EMR sets the node memory for each instance type, so the Hadoop defaults do not apply.

SettingWhat it limitsFileCase
Spark: what your app asks for (all cases)
spark.executor.memory
spark.driver.memory
Heap of each executor and of the driver. In yarn-cluster mode the driver memory is the AM size.spark-submit, spark-defaults.conf1, 2, 5
spark.executor.memoryOverhead
spark.driver.memoryOverhead
spark.executor.memoryOverheadFactor
Memory that Spark adds to each container. Default: max(384 MB, 0.10 × memory).spark-submit1
spark.executor.pyspark.memoryMemory for Python workers. Spark adds it to the executor request when you set it. Not set by default.spark-submit1
spark.executor.cores
spark.driver.cores
vcores for each container. They count only when the scheduler uses DominantResourceCalculator.spark-submit1
spark.executor.instances
spark.dynamicAllocation.maxExecutors
Your own limit on the number of executors. Check these first when you see few executors. Default for maxExecutors: no limit.spark-submit4
spark.yarn.am.memoryAM size in yarn-client mode only (default 512m). The driver then runs outside YARN.spark-submit2
spark.yarn.queueThe YARN queue for the app. Default: default.spark-submit2, 4
Case 1: size of one container
yarn.scheduler.maximum-allocation-mb
yarn.scheduler.maximum-allocation-vcores
Largest one container in the cluster. Hadoop defaults: 8192 MB, 4 vcores.yarn-site.xml1
yarn.scheduler.capacity.<queue-path>.maximum-allocation-mb
yarn.scheduler.capacity.<queue-path>.maximum-allocation-vcores
Largest one container in this queue. Must not be more than the cluster cap.capacity-scheduler.xml1
yarn.scheduler.minimum-allocation-mb
yarn.scheduler.minimum-allocation-vcores
Smallest container. YARN rounds each request up to a multiple of this value. Defaults: 1024 MB, 1 vcore.yarn-site.xml1, 5
yarn.scheduler.capacity.maximum-applications
yarn.scheduler.capacity.<queue-path>.maximum-applications
Number of running and waiting apps. Above it, YARN rejects the new app at submit. Default 10000.capacity-scheduler.xml1
Cases 2 and 3: the AM pool and the number of apps
yarn.scheduler.capacity.maximum-am-resource-percentShare of each queue for all AMs. Default 0.1 (10%).capacity-scheduler.xml2, 3
yarn.scheduler.capacity.<queue-path>.maximum-am-resource-percentThe same share, for one queue.capacity-scheduler.xml2, 3
yarn.scheduler.capacity.max-parallel-apps
yarn.scheduler.capacity.<queue-path>.max-parallel-apps
yarn.scheduler.capacity.user.max-parallel-apps
Number of apps that run at the same time. More apps stay in ACCEPTED. Default: no limit.capacity-scheduler.xml2
yarn.node-labels.am.default-node-label-expression
spark.yarn.am.nodeLabelExpression
Nodes where AMs can run. Some EMR releases set it to CORE, so AMs run only on core nodes. Check your yarn-site.xml.yarn-site.xml, spark-submit2
oozie.launcher.memory.mb
oozie.launcher.yarn.app.mapreduce.am.resource.mb (older name)
Memory of the Oozie launcher AM for one action.workflow.xml (action configuration)3
oozie.launcher.vcoresvcores of the Oozie launcher AM for one action.workflow.xml (action configuration)3
oozie.launcher.queue or <launcher><queue>Queue of the Oozie launcher. Use a different queue from the Spark job.workflow.xml3
oozie.launcher.default.memory.mb
oozie.launcher.default.vcores
oozie.launcher.default.queue
Server defaults for all launchers: 2048 MB, 1 vcore, queue default.oozie-site.xml3
Case 4: share of the queue
yarn.scheduler.capacity.<queue-path>.capacityGuaranteed share of the parent queue, in %. The AM pool and the user limit are calculated from it.capacity-scheduler.xml2, 4
yarn.scheduler.capacity.<queue-path>.maximum-capacityLargest share the queue can grow to when other queues are idle. Default: no limit (100%).capacity-scheduler.xml4
yarn.scheduler.capacity.<queue-path>.user-limit-factorHow many times the queue capacity one user can use. Default 1.capacity-scheduler.xml4
yarn.scheduler.capacity.<queue-path>.minimum-user-limit-percentSmallest share for each user when many users wait. With 25 and two users, each user gets at most 50%. Default 100.capacity-scheduler.xml4
Case 5: size of each node
yarn.nodemanager.resource.memory-mb
yarn.nodemanager.resource.cpu-vcores
Memory and vcores that each node gives to YARN.yarn-site.xml5
yarn.scheduler.capacity.resource-calculatorDefaultResourceCalculator (default) uses memory only. DominantResourceCalculator also uses vcores.capacity-scheduler.xml1, 5

To change a capacity-scheduler.xml value without a restart, edit the file on the primary node and run yarn rmadmin -refreshQueues. On EMR you can also set the values with the yarn-site and capacity-scheduler configuration classifications.

Checked against: Hadoop 3.3.6 yarn-default.xml, CapacityScheduler.md and LeafQueue.java (AM limit, "at least one application" rule); Spark 3.5.1 Client.scala (max threshold check); Oozie oozie-default.xml, JavaActionExecutor.java and LauncherAM.java (launcher memory and queue). The EMR notes come from general EMR knowledge.