Skip to content

How do I resolve YARN resource allocation mismatches on my Amazon EMR cluster?

3 minute read
0

My Amazon EMR cluster runs on Amazon Elastic Compute Cloud (Amazon EC2) instances. YARN reports 90-100% resource utilization, but the physical CPU and memory on my instances stay at about 50% or lower.

Short description

In Amazon EMR, YARN can report high utilization even when physical CPU on Amazon EC2 instances remain underutilized. By default, Amazon EMR uses DefaultResourceCalculator, and then schedules containers on memory only. YARN marks a node as fully allocated when it reserves the node's memory, even when vCores and the underlying physical CPU remain free.

This most often shows up with Apache Spark, because Spark requests multiple cores per executor (executor-cores). However, YARN gives each container a single core.

Resolution

Switch to DominantResourceCalculator

DominantResourceCalculator evaluates memory and CPU together and schedules on each application's dominant, most constrained resource, so YARN honors both the memory and the core request.

To switch to DominantResourceCalculator, apply the following capacity-scheduler classification when you launch a cluster or reconfigure a running cluster:

[
  {
   "Classification": "capacity-scheduler",
   "Properties": {
    "yarn.scheduler.capacity.resource-calculator": "org.apache.hadoop.yarn.util.resource.DominantResourceCalculator"
   }
  }
] 

Reconfiguration initiates a rolling restart of the affected services. After the reconfiguration completes, confirm that the primary node reports DominantResourceCalculator.

For example, consider a 20-node cluster. Each node has 64 cores and 512 GB, and so a 20-node cluster has a total of 1,280 cores and 10,240 GB. You size the executors at 48 GB with executor-memory at 43 GB, spark.executor.memoryOverhead at 5 GB, and executor-cores set to 6:

213 executors consume all available memory because 213 x 48 GB = 10,240 GB.

The cluster expects about 1,280 cores (213 x 6), but YARN allocates only about 200 cores. That leaves about 1,000 cores idle.

With DefaultResourceCalculator, Spark requests 48 GB, 6 cores but YARN honors only memory and returns 48 GB, 1 core, the minimum YARN core allocation. Spark still launches 6 tasks in that container because executor-cores is set to 6, so one core does the work of six tasks, and that increases job latency. 

Right-size your executors

Note: These values are examples based on the preceding example 20-node cluster.

Tune the actual numbers to your instance type and workload.

In the preceding example, executors sized at 48 GB with 6 executor-cores gives roughly 8 GB per core.

Lower the executor memory and set executor-cores to 5. Then, monitor. More containers fit per node and reduce the wait time of pending jobs.

Confirm the result

Jobs that run between 2 and 3 minutes don't change much because of fixed overhead. Long-running jobs typically see a latency improvement.

After you increase effective vCores, monitor EC2 CPUUtilization in Amazon CloudWatch and confirm physical CPU stays below 80-90%.

Related information

Default values for task configuration settings

Using managed scaling in Amazon EMR

Configure Hadoop YARN CapacityScheduler on Amazon EMR on Amazon EC2 for multi-tenant heterogeneous workloads

AWS OFFICIALUpdated 19 days ago