2081 2

CSC481 ยท 2081 ยท 10 marks

What is Map Reduce? Using an example, discuss how Map function, shuffling, and sorting, and Reduce function work in Map Reduce.

What is Map Reduce? Using an example, discuss how Map function, shuffling, and sorting, and Reduce function work in Map Reduce.[10]

Introduction to Cloud ComputingChapter 4: Cloud Programming ModelsMap-reduce programming

Quick answer

MapReduce is a programming model and framework for processing and generating large datasets in a distributed computing environment. It allows developers to write programs that can process massive amounts of data in parallel across a cluster of computers, without worrying about the details of parallelization, fault tolerance, or load balancing.

MapReduce: Concept, Components, and Working

Definition of MapReduce

MapReduce works by breaking a large computation into two main phases:

  1. Map Phase - processes input data and produces intermediate key-value pairs
  2. Reduce Phase - aggregates and summarizes the intermediate key-value pairs to produce the final output

Between these two phases, Shuffling and Sorting acts as an intermediate step that organizes the data.


Core Components of MapReduce

1. Map Function

  • Takes an input key-value pair and produces a set of intermediate key-value pairs
  • Processes each record independently and in parallel
  • Output: a list of (key, value) pairs

2. Shuffling and Sorting

  • Groups all intermediate values associated with the same intermediate key together
  • Transfers the mapped output from mapper nodes to the appropriate reducer nodes
  • Sorts the intermediate key-value pairs by key so that all values for the same key are grouped

3. Reduce Function

  • Takes a key and a set of values associated with that key
  • Applies aggregation, summarization, or other operations
  • Produces the final output key-value pairs
  • As stated in the notes: "The reduce function combines the values associated with each key, performing operations like aggregation, summarization, or generating the final output."

Example: Word Count Problem

Problem: Count the number of occurrences of each word in the following input text:

"hello world hello"
"world hello world"

Step 1: Input Splitting

The input is split into chunks and distributed across multiple mappers:

SplitContent
Split 1"hello world hello"
Split 2"world hello world"

Step 2: Map Phase

Each mapper reads its input split and emits intermediate (word, 1) key-value pairs for every word encountered.

Mapper 1 processes "hello world hello":

Input:  (line1, "hello world hello")

Output (Intermediate Key-Value Pairs):
  (hello, 1)
  (world, 1)
  (hello, 1)

Mapper 2 processes "world hello world":

Input:  (line2, "world hello world")

Output (Intermediate Key-Value Pairs):
  (world, 1)
  (hello, 1)
  (world, 1)

Step 3: Shuffling and Sorting

All intermediate key-value pairs from all mappers are collected, sorted by key, and grouped so that all values for the same key are sent to the same reducer.

After Shuffling and Sorting:

(hello, [1, 1, 1])
(world, [1, 1, 1])
  • All (hello, 1) pairs from both mappers are grouped together
  • All (world, 1) pairs from both mappers are grouped together
  • The keys are sorted alphabetically

This step ensures that each reducer receives all values for a particular key, regardless of which mapper produced them.


Step 4: Reduce Phase

Each reducer receives a key and its list of values, then applies the reduce function to produce the final result.

Reducer 1 processes (hello, [1, 1, 1]):

Input:  (hello, [1, 1, 1])
Operation: sum(1 + 1 + 1) = 3
Output: (hello, 3)

Reducer 2 processes (world, [1, 1, 1]):

Input:  (world, [1, 1, 1])
Operation: sum(1 + 1 + 1) = 3
Output: (world, 3)

Final Output

hello  -->  3
world  -->  3

Complete Flow Diagram

INPUT DATA
    |
    v
[Splitting] --> Split 1, Split 2, ...
    |
    v
[MAP PHASE]
Mapper 1: (hello,1),(world,1),(hello,1)
Mapper 2: (world,1),(hello,1),(world,1)
    |
    v
[SHUFFLE & SORT]
(hello,[1,1,1])
(world,[1,1,1])
    |
    v
[REDUCE PHASE]
Reducer 1: (hello, 3)
Reducer 2: (world, 3)
    |
    v
FINAL OUTPUT: hello=3, world=3

Summary Table

PhaseInputOperationOutput
MapRaw key-value pairsExtract and emit intermediate pairsIntermediate (key, value) pairs
Shuffle & SortIntermediate (key, value) pairsGroup by key, sortGrouped (key, [list of values])
Reduce(key, [list of values])Aggregate/summarizeFinal (key, value) pairs

Advantages of MapReduce

  • Handles large-scale data processing efficiently
  • Provides fault tolerance automatically
  • Achieves parallel efficiency by distributing work across multiple processors
  • As noted: "Parallel efficiency of MapReduce measures how well the system scales and utilizes available resources to perform the required computation in parallel"
  • Developers do not need to manage low-level parallelism details

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.