1. Client Submits MapReduce Job
The process begins with the Client, which is typically a user running a Hadoop command or a program that uses Hadoop's API (e.g., a Java application, a Python script using a Hadoop client library).
Job Definition: The client application first defines the MapReduce job. This involves:
Specifying the input and output paths in HDFS.
Identifying the Mapper, Reducer, Combiner (optional), and Partitioner (optional) classes.
Setting various job configuration parameters (e.g., number of reducers, memory limits for tasks).
Job Submission: The client then sends the job definition, along with the necessary JAR files containing the application code, to the YARN ResourceManager. This submission effectively tells YARN, "Here's a job I want to run; please manage its execution."
2. YARN ResourceManager Coordinates Resource Allocation
The YARN ResourceManager (RM) is the central authority in a Hadoop cluster responsible for managing and allocating computing resources. It's like the air traffic controller for all applications running on the cluster.
Receives Job Submission: The RM receives the job submission from the client.
Schedules ApplicationMaster: For each MapReduce job (or any YARN application), the RM initiates a dedicated process called the ApplicationMaster (AM). The RM finds a suitable NodeManager to launch this AM.
Resource Negotiation: The AM, once launched, is responsible for negotiating resources (CPU, memory, disk I/O) with the RM on behalf of its application. It tells the RM, "I need X number of Map tasks and Y number of Reduce tasks, each requiring Z amount of memory."
Tracking Resources: The RM maintains a global view of all available resources in the cluster and tracks which resources are being used by which applications.
Granting Resources: Based on its scheduling policies (e.g., fairness, capacity), the RM grants resource containers to the AM. A "container" is a logical bundle of resources (CPU, memory) on a specific NodeManager.
3. YARN NodeManager(s): Launch & Monitor Containers on Machines in the Cluster
The YARN NodeManager (NM) runs on each data node (or worker node) in the Hadoop cluster. It's the "agent" that interacts directly with the physical machine's resources.
Registers with ResourceManager: Each NodeManager periodically sends "heartbeat" messages to the ResourceManager, reporting its resource availability and the status of its containers.
Receives Container Launch Commands: When the ResourceManager grants a container to an ApplicationMaster, the ApplicationMaster then instructs a specific NodeManager (that was assigned the container by the RM) to launch that container.
Launches & Manages Containers: The NodeManager is responsible for:
Launching Containers: It creates isolated environments (containers) on its machine, allocating the specified CPU and memory.
Downloading Code: It pulls the necessary JAR files (containing the Mapper, Reducer, etc.) from HDFS to run the application code within the container.
Executing Tasks: It then launches the actual Map or Reduce task (a Java Virtual Machine process) inside the container.
Monitoring Resources: It continuously monitors the resource consumption (CPU, memory) of the running tasks within its containers. If a task exceeds its allocated resources, the NodeManager can terminate it.
Reporting Status: It reports the status and progress of the tasks running in its containers back to the ApplicationMaster.
Health Checks: It constantly checks the health of the physical machine and reports any issues to the ResourceManager.
Flow Summary:
Client submits job to ResourceManager.
ResourceManager launches ApplicationMaster on a NodeManager.
ApplicationMaster negotiates resources with ResourceManager.
ResourceManager grants containers to ApplicationMaster.
ApplicationMaster instructs NodeManagers to launch Map/Reduce tasks in allocated containers.
NodeManagers launch and monitor Map/Reduce tasks.
Map/Reduce tasks process data, write intermediate output, and send status updates back through NodeManagers to the ApplicationMaster.
ApplicationMaster oversees the entire job, handling failures, tracking progress, and reporting overall job status back to the ResourceManager (and eventually the Client).