- 2074 Magh · 8 marks
MapReduce working with example
Short answer
MapReduce divides input, applies map to produce key-value pairs, shuffles by key, then reduces to aggregate. Example word count: 'to be or not to be' -> map: (to,1),(be,1),(or,1),(not,1),(to,1),(be,1) -> reduce sum: (be,2), (not,1), (or,1), (to,2).
Explain the working mechanisms of Map Reduce for big data with example.
MapReduce is a programming model and framework for processing very large datasets in parallel on a cluster of commodity machines. The user writes two functions:
- map(key, value) -> list of (key2, value2)
- reduce(key2, list of values) -> result
The framework handles splitting of data, scheduling, communication, and fault tolerance.
Working mechanism
- Input splitting: the input file stored in a distributed file system (GFS/HDFS) is divided into blocks (for example 64/128 MB).
- Map phase: each split is given to a map task running (where possible) on the node holding the data. It reads records and emits intermediate key-value pairs.
- Shuffle and sort: pairs are partitioned by key, moved across the network and sorted so that all values of the same key come together.
- Reduce phase: a reduce task takes each key and its list of values and combines them into a final result.
- Output: results are written back to the distributed file system.
- Fault tolerance: a master (job tracker) monitors workers; if a worker fails, its task is re-run on another node.
Input -> Split1 -> Map -+
Split2 -> Map -+-> Shuffle/Sort -> Reduce -> Out1
Split3 -> Map -+ Reduce -> Out2
Example: word count
Input: "to be or not to be"
- Map output: (to,1) (be,1) (or,1) (not,1) (to,1) (be,1)
- Shuffle/sort: be -> [1,1]; not -> [1]; or -> [1]; to -> [1,1]
- Reduce (sum): (be,2) (not,1) (or,1) (to,2)
map(String line):
for each word w in line: emit(w, 1)
reduce(String w, List counts):
emit(w, sum(counts))
Advantages
Scales to thousands of machines, hides parallel programming complexity, tolerates failures and moves computation to data.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Big data and its processing · Information System, chapter 8
- MapReduce vs Hadoop; IR process · Information System, chapter 8
- MapReduce with GFS and HDFS · Information System, chapter 8
- MapReduce data flow technique · Big Data Technologies, chapter 3
- Optimization and data locality in MapReduce · Big Data Technologies, chapter 3
- MapReduce worker failure tolerance · Big Data Technologies, chapter 3
- Breakdown mechanisms in solids under working conditions · High Voltage Engineering, chapter 6