1/25
Looks like no tags are added yet.
Map reduce
When a large amount of data is processed on a single computer, it may take a lot of time.
MapReduce solves this problem by dividing the data into smaller parts and processing them on multiple computers simultaneously.
It consists of two main functions:
Map: Processes input data and generates intermediate key-value pairs.
Reduce: Combines intermediate values to generate the final result.
Phases of MapReduce
1. Input Splitting: Divides the input data into smaller logical parts called input splits.
2. Mapping: Processes input records and generates intermediate key-value pairs.
3. Shuffle and Sort: Groups intermediate values according to their keys and transfers them to the appropriate reducers.
4. Reducing: Processes grouped values to generate the final results.
5. Output: Stores the final results, usually in HDFS.
working
Input Data
↓
Input Splitting
↓
Map Phase
↓
Intermediate Key-Value Pairs
↓
Shuffle and Sort
↓
Reduce Phase
↓
Final Output
Anatomy of a MapReduce Job Run.
The Anatomy of a MapReduce Job Run describes the complete process through which a MapReduce job is submitted, initialized, executed, and completed in Hadoop to process large datasets.
Steps Involved in a MapReduce Job Run
1. Job Submission
The user submits the MapReduce program along with the input and output paths to Hadoop.
2. Job Initialization
Hadoop checks the job configuration and prepares the job for execution.
3. Input Splitting
The input data is divided into logical input splits. Each split is generally processed by one map task.
4. Map Task Execution
The mapper processes input records and generates intermediate key-value pairs.
5. Shuffle and Sort
Intermediate data is transferred to the reducers, grouped by key, and sorted.
6. Reduce Task Execution
The reducer processes each key and its associated values to generate the final results.
7. Output Generation
The final output is written to the specified output directory, usually in HDFS.
8. Job Completion
Hadoop reports whether the job completed successfully or failed.
Failures in MapReduce.
Failures in MapReduce refer to errors that occur during the execution of a MapReduce job due to problems in tasks, worker nodes, or network communication. Hadoop handles these failures using task re-execution, data replication, and other recovery mechanisms.
Types of Failures in MapReduce
1. Task Failure
A map or reduce task may fail due to programming errors, exceptions, or insufficient resources.
Hadoop can retry the failed task on the same or another node.
If the task continues to fail beyond the allowed limit, the job may fail.
2. Node Failure
A worker node may stop working due to hardware problems, power failure, or system crashes.
Hadoop detects the unavailable node through its monitoring mechanisms.
Tasks running on that node can be rescheduled on other available nodes.
3. ApplicationMaster Failure
The ApplicationMaster coordinates the execution of a MapReduce job.
If it fails, YARN may attempt to restart it, subject to its configured retry limit.
The job may fail if recovery is unsuccessful.
4. Network Failure
Network problems can interrupt communication between nodes.
Data transfer during shuffle and sort may fail or become delayed.
Hadoop retries certain operations and may reschedule tasks when necessary.
5. Data Failure
Data blocks may become unavailable because of disk failures or corruption.
HDFS uses replicated copies of blocks to recover from many such failures.
If all usable copies are lost, the affected data may become unavailable.
Fault-Tolerance Mechanisms in MapReduce
1. Task Re-execution: Failed tasks are executed again to obtain the required results.
2. Data Replication: HDFS stores multiple copies of data blocks to protect against node or disk failures.
3. Failure Detection: Hadoop monitors task execution and worker-node availability to identify failures.
4. Task Rescheduling: Failed tasks can be assigned to other available nodes.
Job Scheduling in MapReduce
Job Scheduling in MapReduce is the process of assigning and managing MapReduce jobs and their tasks on available cluster resources to ensure efficient execution and better utilization of computing resources.
Types of Job Scheduling in Hadoop
1. FIFO Scheduler (First In, First Out)
Executes jobs in the order in which they are submitted.
Simple to understand and manage.
A large job may delay smaller jobs submitted later.
2. Fair Scheduler
Attempts to distribute available resources fairly among running jobs.
Allows multiple jobs to make progress simultaneously.
Helps prevent one long-running job from occupying all resources for an extended period.
3. Capacity Scheduler
Divides cluster resources into queues with configured capacities.
Each queue receives a guaranteed share of resources.
Suitable for organizations where multiple teams share a Hadoop cluster.
Advantages of Job Scheduling
1. Efficient Resource Utilization: Allocates available computing resources to jobs.
2. Reduced Waiting Time: Suitable scheduling can prevent smaller jobs from waiting unnecessarily.
3. Fair Resource Sharing: Allows multiple users and jobs to share cluster resources.
4. Priority Management: Supports policies for handling jobs with different priorities.
5. Better Performance: Helps improve the overall efficiency of cluster execution.
Shuffle and Sort
Shuffle and Sort is a process in MapReduce that collects data from Mappers, groups the same keys together, and arranges the keys before sending them to Reducers.
Mapper takes input data, processes it, and produces intermediate key-value pair
Reducer collects values having the same key and processes them to produce the final output.
Shuffle
Shuffle transfers intermediate key-value pairs from the Mapper to the appropriate Reducer.
It groups all values having the same key.
It ensures that pairs with the same key reach the same Reducer.
example
mapper o/p-
(Apple, 1)
(Banana, 1)
(Apple, 1)
(Banana, 1)
after suffling-
(Apple, [1, 1])
(Banana, [1, 1])
Sort
Sort arranges the intermediate keys in sorted order before they reach the Reducer.
By default, Hadoop sorts keys in ascending order.
All values belonging to the same key are grouped together.
example-
(Apple, [1, 1])
(Banana, [1, 1])
keys are arranged alphabetically
Working of Shuffle and Sort
The Mapper generates intermediate key-value pairs.
The Partitioner decides which Reducer will receive each key.
Shuffle transfers the intermediate data to the Reducers.
Sort arranges the keys and groups values belonging to the same key.
The Reducer processes each key and its list of values.
Task Execution in MapReduce
Task Execution is the process of running Map and Reduce tasks on different machines to process large amounts of data.
working—
Input Splitting: Input data is divided into smaller parts called splits.
Map Task: Each Map Task processes one input split and produces key-value pairs.
Shuffle and Sort: Data with the same key is grouped together and keys are sorted.
Reduce Task: The Reducer processes the grouped data.
Final Output: The result is stored in output files.
2. Types of Tasks
1. Map Task
A Map Task processes a part of the input data and produces intermediate key-value pairs.
2. Reduce Task
A Reduce Task processes grouped values with the same key and produces the final output.
MapReduce Types and Formats
MapReduce Types and Formats define the types of data used by Mapper and Reducer and the way input and output data are read and written.
There are three main parts:
Types in MapReduce
Input Formats
Output Formats
Types in MapReduce
Types define what kind of data is stored in the key-value pairs used by Mapper and Reducer.
Important types are:
1. Text: Used to store text or words.
Example: "Apple"
2. IntWritable: Used to store integer numbers.
Example: 10
3. LongWritable: Used to store large integer numbers.
Example: 100000
4. FloatWritable: Used to store decimal numbers.
Example: 10.5
5. DoubleWritable: Used to store decimal numbers with greater precision.
Example: 125.5678
6. BooleanWritable: Used to store true or false values.
Example: true
Input Formats
Input Format decides how input data is divided into splits and read by Mapper.
Types of Input Formats:
1. TextInputFormat: Reads input data one line at a time. It is the default input format.
2. KeyValueTextInputFormat: Reads each line as a key-value pair, usually separated by a tab.
3. NLineInputFormat: Places a fixed number of lines into each input split.
4. SequenceFileInputFormat: Reads data stored in SequenceFile format, which stores binary key-value pairs.
Output Formats
Output Format decides how the final result of a MapReduce job is written and stored.
Types of Output Formats:
1. TextOutputFormat: Writes output as text. It is the default output format.
2. SequenceFileOutputFormat: Writes output as binary key-value pairs in a SequenceFile.
3. MapFileOutputFormat: Writes output in MapFile format, which stores sorted key-value pairs and supports lookup by key.
4. NullOutputFormat: Does not write output to a file.
MapReduce Features
Main Features of MapReduce
1. Parallel Processing
MapReduce divides data into smaller parts and processes them at the same time using multiple machines.
2. Scalability
It can handle increasing amounts of data by adding more machines to the system.
3. Fault Tolerance
If a task or machine fails, Hadoop can run the failed task again to complete the job.
4. Data Locality
MapReduce tries to process data near where it is stored. This reduces data transfer over the network.
5. Automatic Task Scheduling
Hadoop automatically assigns tasks to available machines.
6. Load Balancing
Work is distributed among different machines to improve processing efficiency.
7. Cost Effectiveness
It can run on ordinary computers, reducing the need for expensive hardware.
8. Flexibility
It can process different types of data, such as text, logs, and structured data.
Failures
Failures in MapReduce occur when a task, machine, or system component stops working properly while processing data.
Hadoop detects these failures and tries to recover so that the job can finish successfully.
Types of Failures
1. Task Failure
It occurs when a Map or Reduce task cannot complete its work due to an error.
Recovery: Hadoop runs the failed task again.
2. NodeManager Failure
It occurs when the machine running tasks stops working or becomes unavailable.
Recovery: Hadoop detects the failure and reschedules the tasks on another available machine.
3. ApplicationMaster Failure
It occurs when the ApplicationMaster, which manages the MapReduce job, stops working.
Recovery: Hadoop can start a new ApplicationMaster and recover the job if the required recovery settings are enabled.
4. ResourceManager Failure
It occurs when the ResourceManager, which manages cluster resources, stops working.
Recovery: If High Availability (HA) is configured, another ResourceManager can take over.
5. Network Failure
It occurs when network problems interrupt communication between machines.
Recovery: Hadoop may retry communication or rerun affected tasks after the connection is restored.
(optional) ailure Handling Techniques
Task Re-execution: Runs a failed task again.
Failure Detection: Detects tasks or machines that stop responding.
Task Rescheduling: Assigns failed tasks to other available machines.
Data Replication: Keeps multiple copies of data so it can still be accessed if one machine fails.