Introduction to Cloud Computing · Unit 4 · 12 hrs
Cloud Programming Models
Exam-focused notes for Cloud Programming Models (Introduction to Cloud Computing, CSC481): what the TU syllabus asks and how it has actually been tested, with 3 solved past questions from this unit.
Cloud Programming Models in short
This unit covers the programming models used to write applications that run efficiently on cloud infrastructure: thread-based and task-based parallelism within a single application, and the MapReduce model for processing very large datasets across many machines at once.
What this unit covers
- Thread programming
- Task programming
- Map-reduce programming
- Parallel efficiency of Map-Reduce
- Enterprise batch processing using Map-Reduce
- Comparisons between Thread, Task and Map reduce
Map-reduce programming
2081 · 10 marks
What is Map Reduce? Using an example, discuss how Map function, shuffling, and sorting, and Reduce function work in Map Reduce.[10]
Show solved answerHide answer
MapReduce: Concept, Components, and Working
Definition of MapReduce
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 works by breaking a large computation into two main phases:
- Map Phase - processes input data and produces intermediate key-value pairs
- 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:
| Split | Content |
|---|---|
| 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
| Phase | Input | Operation | Output |
|---|---|---|---|
| Map | Raw key-value pairs | Extract and emit intermediate pairs | Intermediate (key, value) pairs |
| Shuffle & Sort | Intermediate (key, value) pairs | Group by key, sort | Grouped (key, [list of values]) |
| Reduce | (key, [list of values]) | Aggregate/summarize | Final (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
Thread programming
2080 · 10 marks
What is thread? Why multi-threading is used? Describe how thread programming is done in cloud.[10]
Parallel efficiency of Map-Reduce
2079 · 10 marks
What is parallel efficiency of map-reduce means? Compare between thread, task and map-reduce.[10]
Make Unit 4 stick
Practice CSC481 with flashcards & quizzes