Map-Reduce and The New Software Stack: Mining of Massive Datasets Jure Leskovec, Anand Rajaraman, Jeff Ullman
Map-Reduce and The New Software Stack: Mining of Massive Datasets Jure Leskovec, Anand Rajaraman, Jeff Ullman
material useful in giving your own lectures. Feel free to use these slides verbatim, or to modify
them to fit your own needs. If you make use of a significant portion of these slides in your own
lecture, please include this message, or a link to our web site: http://www.mmds.org
Map-Reduce and
the New Software
Stack
Mining of Massive Datasets
Jure Leskovec, Anand Rajaraman, Jeff
Ullman Stanford University
http://www.mmds.org
MapReduce
Much
CPU
Motivation: Google
Example
20+
Cluster Architecture
2-10 Gbps backbone between racks
1 Gbps between
any pair of nodes
in a rack
Switch
Switch
CPU
Mem
Disk
Switch
CPU
CPU
Mem
Mem
Disk
Disk
CPU
Mem
Disk
Large-scale Computing
Large-scale
mining
problems on commodity hardware
Challenges:
How do you distribute computation?
How can we make it easy to write
distributed programs?
Machines fail:
One server may stay up 3 years (1,000 days)
If you have 1,000 servers, expect to loose 1/day
People estimated Google had ~1M machines in
2011
1,000 machines fail every day!
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org
Programming model
Map-Reduce
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org
Storage Infrastructure
Problem:
Typical
usage pattern
servers
Master
node
Client
10
Chunk server 1
Chunk server 2
Chunk server 3
Chunk server N
11
Sample
application:
12
Case 2:
Count occurrences of words:
words(doc.txt) | sort | uniq -c
where words takes a file and outputs the words in
it, one per a line
Case
13
MapReduce: Overview
Sequentially
Map:
the result
14
Intermediate
key-value pairs
k
map
map
15
Key-value groups
k
Group
by key
reduce
reduce
Output
key-value pairs
16
More Specifically
Input: a set
Programmer
of key-value pairs
specifies two methods:
17
MapReduce: Word
Counting
Read input and
produces a set
of key-value
pairs
The crew of the space
shuttle Endeavor recently
returned to Earth as
ambassadors, harbingers
of a new era of space
exploration. Scientists at
NASA are saying that the
recent assembly of the
Dextre bot is the first step
in a long-term space-based
man/mache
partnership.
'"The work we're doing now
-- the robotics we're doing
-- is what we're going to
need ..
Big document
(The, 1)
(crew, 1)
(of, 1)
(the, 1)
(space, 1)
(shuttle, 1)
(Endeavor,
1)
(recently, 1)
.
(key, value)
Group by
key:
Collect all pairs
with same key
Provided by the
programmer
Reduce:
Collect all
values
belonging to
the key and
output
(crew, 1)
(crew, 1)
(space, 1)
(the, 1)
(the, 1)
(the, 1)
(shuttle, 1)
(recently, 1)
(crew, 2)
(space, 1)
(the, 3)
(shuttle, 1)
(recently, 1)
(key, value)
(key, value)
Only
sequential
reads
Sequentially
read the
data
Provided by the
programmer
MAP:
18
reduce(key, values):
// key: a word; value: an iterator over counts
result = 0
for each count v in values:
result += v
emit(key, result)
19
Map-Reduce: Environment
Map-Reduce environment takes
care of:
Partitioning the input data
Scheduling the programs execution
across a
set of machines
Performing the group by key step
Handling machine failures
Managing required inter-machine
communication
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org
20
Map-Reduce: A diagram
Big document
MAP:
Read input and
produces a set
of key-value
pairs
Group by
key:
Collect all pairs
with same key
(Hash merge,
Shuffle, Sort,
Partition)
Reduce:
Collect all
values
belonging to the
key and output
21
Map-Reduce: In Parallel
22
Map-Reduce
Programmer
specifies:
Input 0
Input 1
Input 2
Workflow:
Out 0
Out 1
23
Data Flow
Input
Intermediate
on local FS
of Map and Reduce workers
Output
24
Coordination: Master
Master
Master
25
worker failure
worker failure
failure
26
tasks
R is smaller than M
27
28
Refinements: Backup
Tasks
Problem
Solution
Effect
29
Refinement: Combiners
Often
Can
Works
only if reduce
function is commutative and associative
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org
30
Refinement: Combiners
Back
31
Refinement: Partition
Function
Want
System
Sometimes
function:
32
Other
examples:
34
Example: Language
Model
Statistical
machine translation:
Need to count number of times every 5word sequence occurs in a large corpus
of documents
Very
Map:
Extract (5-word sequence, count) from
document
Reduce:
Combine the counts
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org
35
S(B,C)
R and S are each stored in files
Tuples are pairs (a,b) or (b,c)
A
a1
b1
b2
c1
a2
b1
a3
c1
b2
c2
a3
b2
a3
c2
b3
c3
a4
b3
a4
c3
36
Map-Reduce Join
Use
37
1.
2.
3.
Note that here the big-O notation is not the most useful
(adding more machines is always an option)
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org
38
a map-reduce algorithm:
39
Total
from
your friendly neighborhood cloud
Elapsed
40
communication cost
= O(|R|+|S|+|R S|)
Elapsed communication cost = O(s)
Were going to pick k and the number of Map
processes so that the I/O limit s is respected
We put a limit s on the amount of input or
output that any one process can have. s could
be:
What fits in main memory
What fits on local disk
With
41
Implementations
Google
Hadoop
43
Cloud Computing
Ability
(EC2)
Aster
For
44
Reading
Jeffrey
Sanjay
45
Resources
Hadoop
Wiki
Introduction
http://wiki.apache.org/lucene-hadoop/
Getting Started
http://wiki.apache.org/lucene-hadoop/GettingSta
rtedWithHadoop
Map/Reduce Overview
http://wiki.apache.org/lucene-hadoop/HadoopMap
Reduce
http://wiki.apache.org/lucene-hadoop/HadoopMap
RedClasses
Eclipse Environment
http://wiki.apache.org/lucene-hadoop/EclipseEnvi
ronment J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org
46
Resources
http://people.apache.org/dist/lucene/had
oop/nightly/
http://lucene.apache.org/hadoop/version
_control.html
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org
47
Further Reading
Programming
primitives
Partitioning/shuffling similar to many large-scale sorting
systems
NOW-Sort ['97]
Re-execution
Backup
system
Charlotte ['96]
Dynamic
48