YARN: Resource Manager for Big data applications
YARN (Yet Another Resource Negotiator) is a resource management layer for the Hadoop ecosystem. It is a core component of Hadoop 2.x and beyond, enabling more flexible and efficient resource management compared to the original Hadoop 1.x version. YARN decouples the resource management and job scheduling functions, allowing different types of data processing frameworks to run on a Hadoop cluster.
Key Components of YARN:
ResourceManager (RM):
- The global authority that arbitrates resources among all applications in the system.
- It consists of two main components:
- Scheduler: Allocates resources to various running applications based on the constraints of capacities, queues, and user limits.
- ApplicationManager: Manages the application lifecycle, such as accepting job submissions, negotiating the first container for executing the ApplicationMaster, and restarting the ApplicationMaster on failure.
NodeManager (NM):
- Runs on each node in the cluster.
- Manages the execution of containers on its node.
- Monitors resource usage (CPU, memory, disk, network) and reports this information to the ResourceManager.
- Handles container management, including starting and stopping containers, and reporting container statuses to the ResourceManager.
ApplicationMaster (AM):
- A per-application entity that coordinates the execution of an application in the cluster.
- Each application has its own ApplicationMaster, which negotiates resources from the ResourceManager and works with the NodeManager(s) to execute and monitor tasks.
- The ApplicationMaster is responsible for task scheduling, fault tolerance, and monitoring the progress of its tasks.
Containers:
- The fundamental unit of resource allocation in YARN.
- Containers encapsulate a specified amount of resources (CPU, memory, etc.) and run application-specific processes.
- Managed by the NodeManager on each node, containers are allocated by the ResourceManager based on the application’s needs.
How YARN Works:
1. Job Submission:
- A client submits an application (job) to the ResourceManager.
- The ResourceManager assigns an Application ID and starts the ApplicationManager.
2. ApplicationMaster Allocation:
- The ResourceManager allocates the first container for the ApplicationMaster and starts it on an appropriate NodeManager.
- The ApplicationMaster initializes and registers with the ResourceManager, indicating its requirements and capabilities.
3. Resource Request and Allocation:
- The ApplicationMaster negotiates additional resources (containers) with the ResourceManager based on the application’s needs.
- The ResourceManager’s Scheduler allocates containers on various nodes, ensuring fair and efficient resource utilization.
- The ApplicationMaster is informed of container allocations and communicates with the respective NodeManagers to launch the tasks.
4. Task Execution:
- The NodeManagers launch containers as per the instructions from the ApplicationMaster.
- The tasks run inside these containers, performing the actual data processing.
Get Himanshu Singh’s stories in your inbox
Join Medium for free to get updates from this writer.
5. Monitoring and Reporting:
- The NodeManagers monitor the resource usage of each container and report this information to the ResourceManager.
- The ApplicationMaster monitors the progress of its tasks and handles any task failures by rescheduling them if necessary.
6. Job Completion:
- Once all tasks are completed, the ApplicationMaster informs the ResourceManager of the job completion.
- The ApplicationMaster and its resources are cleaned up, and the final status is reported back to the client.
Advantages of YARN:
Scalability:
- YARN allows for better scalability by distributing the resource management and job scheduling functions.
- It can handle large clusters more efficiently.
Multi-Tenancy:
- YARN supports running multiple types of applications (e.g., MapReduce, Spark, Flink) on the same cluster, making it suitable for multi-tenant environments.
Resource Utilization:
- YARN’s fine-grained resource allocation and dynamic resource management lead to better resource utilization.
- Applications can request and release resources as needed, optimizing cluster usage.
Fault Tolerance:
- YARN provides fault tolerance by automatically restarting failed ApplicationMasters and tasks.
- NodeManagers continuously monitor container health and report issues to the ResourceManager.
Important Configurations in yarn-site.xml
ResourceManager Configuration:
- Specifies the hostname and port of the ResourceManager using
yarn.resourcemanager.address
<property>
<name>yarn.resourcemanager.address</name>
<value>rm-hostname:8032</value>
</property>2. Specifies the address where the scheduler is running using yarn.resourcemanager.scheduler.address
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>rm-hostname:8030</value>
</property>NodeManager Configuration:
- Specifies the total amount of physical memory (in MB) that can be allocated for containers using
yarn.nodemanager.resource.memory-mb
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>8192</value>
</property>2. Specifies the number of CPU cores that can be allocated for containers using yarn.nodemanager.resource.cpu-vcores
<property>
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>4</value>
</property>3. Specifies the local directories used by the NodeManager to store local files and intermediate data using yarn.nodemanager.local-dirs
<property>
<name>yarn.nodemanager.local-dirs</name>
<value>/var/lib/hadoop/yarn/local</value>
</property>4. Specifies the local directories used by the NodeManager to store logs using yarn.nodemanager.log-dirs
<property>
<name>yarn.nodemanager.log-dirs</name>
<value>/var/log/hadoop/yarn/container-logs</value>
</property>Container Configuration:
- Specifies the maximum memory allocation for a single container using
yarn.scheduler.maximum-allocation-mb
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>8192</value>
</property>2. Specifies the maximum number of CPU cores allocation for a single container using yarn.scheduler.maximum-allocation-vcores
<property>
<name>yarn.scheduler.maximum-allocation-vcores</name>
<value>4</value>
</property>




