CS 764: Topics in Database Management Systems Lecture 14 ...
Transcript of CS 764: Topics in Database Management Systems Lecture 14 ...
![Page 1: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/1.jpg)
Xiangyao Yu10/21/2020
CS 764: Topics in Database Management SystemsLecture 14: MapReduce
1
![Page 2: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/2.jpg)
Announcement
2
Mid-term course evaluation DDL: 10/23
Please submit project proposal to the review website DDL: Oct 26
Please submit a review for the guest lecture within 3 days after the lecture DDL: Oct 28 11:59pm
![Page 3: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/3.jpg)
Today’s Paper: MapReduce
OSDI 2004 3
![Page 4: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/4.jpg)
OutlineBackgroundMapReduce• Programming model• Implementation• Optimizations
MapReduce vs. Databases
4
![Page 5: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/5.jpg)
Challenges in Distributed Programming[Within a server] Multi-threading[Across servers] Inter-server communication (MPI, RPC, etc.)Fault tolerance Load balancing Scalability
5
![Page 6: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/6.jpg)
Distributed Challenges in Databases?[Within a server] Multi-threading[Across servers] Inter-server communication (MPI, RPC, etc.)• The interface is SQL, parallelism is invisible to users
Fault tolerance • Logging and high availability, invisible to users
Load balancing Scalability • Shared-nothing databases are very scalable
6
![Page 7: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/7.jpg)
Limitations of Distributed DatabasesProgramming model: SQL
Data format: Relational (i.e., structured)
Lack of support for failures during an OLAP query
7
![Page 8: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/8.jpg)
MapReduce
8
![Page 9: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/9.jpg)
MapReduce Programming ModelA user of the MapReduce library writes two functions:
Map function• Input: <key, value>• Output: list(<key, value>)
Reduce function• Input: <key, list(value)>• Output: list(value)
9
![Page 10: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/10.jpg)
MapReduce Programming ModelA user of the MapReduce library writes two functions:
Map function• Input: <key, value>• Output: list(<key, value>)
Reducer function• Input: <key, list(value)>• Output: list(value)
10
Example: word count
![Page 11: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/11.jpg)
Other Application ExamplesGrep:• Map: emits a line if it matches the pattern• Reduce: identity function—copy input to output
11
![Page 12: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/12.jpg)
Other Application ExamplesGrep:• Map: emits a line if it matches the pattern• Reduce: identity function—copy input to output
Count of URL access frequency:• Map: emit ⟨URL, 1⟩• Reduce: adds values for the same URL and emits ⟨URL, total count⟩
12
![Page 13: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/13.jpg)
Other Application ExamplesGrep:• Map: emits a line if it matches the pattern• Reduce: identity function—copy input to output
Count of URL access frequency:• Map: emit ⟨URL, 1⟩• Reduce: adds values for the same URL and emits ⟨URL, total count⟩
Reverse web-link graph:• Map: outputs ⟨target, source⟩ for each target URL found in page source • Reduce: concatenates sources associated with a given target ⟨target,
list(source)⟩
13
![Page 14: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/14.jpg)
Other Application ExamplesGrep:• Map: emits a line if it matches the pattern• Reduce: identity function—copy input to output
Count of URL access frequency:• Map: emit ⟨URL, 1⟩• Reduce: adds values for the same URL and emits ⟨URL, total count⟩
Reverse web-link graph:• Map: outputs ⟨target, source⟩ for each target URL found in page source • Reduce: concatenates sources associated with a given target ⟨target,
list(source)⟩Inverted index:• Map: Emit ⟨word, doc ID⟩ for words in a document• Reduce: for a word, sorts document IDs and emits ⟨word,list(doc ID)⟩ 14
![Page 15: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/15.jpg)
Implementation
15
Network
CPU
Mem
CPU
Mem
CPU
Mem
Google File System (GFS)
… Thousands of servers
![Page 16: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/16.jpg)
Implementation
16
Network
CPU
Mem
CPU
Mem
CPU
Mem
Google File System (GFS)
… Thousands of servers
![Page 17: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/17.jpg)
Implementation – Step 1
17
Network
CPU
Mem
CPU
Mem
CPU
Mem
Google File System (GFS)
… Thousands of servers
Splits input files into Mpieces (16 to 64 MB per piece)
![Page 18: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/18.jpg)
Implementation – Step 2
18
Network
CPU
Mem
CPU
Mem
CPU
Mem
Google File System (GFS)
… Thousands of servers
Assign M map and Rreduce tasks to servers
map map mapreduce reduce
![Page 19: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/19.jpg)
Implementation – Step 3
19
Network
CPU
Mem
CPU
Mem
CPU
Mem
Google File System (GFS)
… Thousands of servers
Execute map tasks and write output to local memory
mapreduce reducemap map
output output output
![Page 20: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/20.jpg)
Implementation – Step 4
20
Network
CPU
Mem
CPU
Mem
CPU
Mem
Google File System (GFS)
… Thousands of servers
Partition the output into R regions and write them to disk
mapreduce reducemap map
![Page 21: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/21.jpg)
Implementation – Step 5
21
Network
CPU
Mem
CPU
Mem
CPU
Mem
Google File System (GFS)
… Thousands of servers
Reduce task reads corresponding intermediate data (i.e., output of map tasks) and sort them
mapmap mapreduce reduce
![Page 22: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/22.jpg)
Implementation – Step 6
22
Execute reduce tasks and write output to GFS
Network
CPU
Mem
CPU
Mem
CPU
Mem
Google File System (GFS)
… Thousands of servers
mapmap mapreduce reduce
![Page 23: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/23.jpg)
Implementation – Step 7
23
Wake up the user program after all map and reduce tasks finish
Network
CPU
Mem
CPU
Mem
CPU
Mem
Google File System (GFS)
… Thousands of servers
mapmap mapreduce reduce
![Page 24: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/24.jpg)
Master NodeOrchestrates the MapReduce job
For each map task and reduce task, maintains states (idle, in-progress, or complete) and identity of worker machine
Collect locations of map tasks’ outputs on disk and forward them to the reduce tasks
24
![Page 25: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/25.jpg)
Fault ToleranceThe master pings every worker periodically
At a timeout, reschedule tasks mapped to this worker to other workers• Map task: all map tasks are rescheduled • Reduce task: incomplete reduce tasks are rescheduled
Master failure• Unlikely since the master is a single machine• Abort the MapReduce computation if the master fails• Single point of failure
25
![Page 26: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/26.jpg)
Backup TasksA straggler task can take unusually long time to complete• Bad disk• Contention with other tasks on the server• Misconfiguration
Solution: Schedule backup execution for in-progress tasks when the MapReduce computation is close to finish• Overhead is small (a few percent)• Improvement is significant (44% for the sort program)
26
![Page 27: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/27.jpg)
Other OptimizationsLocality• Try to schedule a map task on a machine that contains (or is close to) a
replica of the corresponding input data
Combiner function• Local reduce function on each map task to reduce the intermediate data size • Similar to pushing down group-by in query optimization
27
![Page 28: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/28.jpg)
Performance Evaluation — GrepGrep• 1 TB of 100-byte records• Search for a rare three character pattern• Map: emits a line if it matches the pattern• Reduce: identity function—copy input to output
28
• Input data scan rate increases as more machines assigned to the MapReduce computation and peaks at over 30 GB/s when 1764 workers have been assigned
• The rate declines after map tasks finish reading the input data
![Page 29: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/29.jpg)
Performance Evaluation — SortSort• 1 TB of 100-byte records• Map: extract a 10-byte key and emit <key, original record in text>• Reduce: identity function• Partitioning function: range partition• Note that a reducer task by default sorts its input data
29
![Page 30: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/30.jpg)
Performance Evaluation — Sort
30
Two batches of reduce tasks
![Page 31: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/31.jpg)
Performance Evaluation — Sort
31
Straggler tasks increase the total runtime by 44%
![Page 32: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/32.jpg)
Performance Evaluation — Sort
32
Failure of processes has small performance impact
![Page 33: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/33.jpg)
MapReduce vs. Databases[1]
With user defined functions, Map and Reduce functions can be written in SQL; the shuffle between Map and Reduce is equivalent to a Group-By
Performance
33[1] Stonebraker, Michael, et al. "MapReduce and parallel DBMSs: friends or foes?." Communications of the ACM 2010
![Page 34: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/34.jpg)
MapReduce vs. Databases[1]
Technical differences• Repetitive parsing• Compression• Pipelining• Scheduling• Column-oriented storage• Query optimization
34[1] Stonebraker, Michael, et al. "MapReduce and parallel DBMSs: friends or foes?." Communications of the ACM 2010
![Page 35: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/35.jpg)
MapReduce vs. Databases[1]
Technical differences• Repetitive parsing• Compression• Pipelining• Scheduling• Column-oriented storage• Query optimization
Conclusions:• Parallel DBMSs excel at efficient querying of large data sets; MR-style systems
excel at complex analytics and ETL tasks. • High-level languages are invariably a good idea for data-processing systems• What can DBMS learn from MapReduce?
• Out-of-the-box experience (one-button install, auto tuning)• Semi-structured or un-structured data
35[1] Stonebraker, Michael, et al. "MapReduce and parallel DBMSs: friends or foes?." Communications of the ACM 2010
![Page 36: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/36.jpg)
Q/A – MapReduce
36
Computational models that do not work well with MapReduce?Is the master a single-point of failure and performance bottleneck?Why old papers have no performance evaluation?MapReduce used in DBMS? (e.g., Hadapt, Hive, SparkSQL)Why is the atomic rename necessary in the reducer? Other systems like MapReduce (e.g., Apache Hadoop, Spark)Why do we need sorting and shuffling?
![Page 37: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/37.jpg)
Discussion
37
How to implement the following joining query in MapReduce? SELECT * FROM S, RWHERE S.id = R.id
![Page 38: CS 764: Topics in Database Management Systems Lecture 14 ...](https://reader030.fdocuments.us/reader030/viewer/2022012600/61976a8476bbef11fa7cda95/html5/thumbnails/38.jpg)
Next LectureMid-term course evaluation DDL: 10/23
Please submit your proposal to the review website: (DDL Oct 26)• https://wisc-cs764-f20.hotcrp.com
Please submit a review for the guest lecture within 3 days after the lecture (by Oct 28 11:59pm)
38