0% found this document useful (0 votes)
30 views39 pages

MapReduce - 1

Uploaded by

rsumaira80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views39 pages

MapReduce - 1

Uploaded by

rsumaira80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

DS-5008

Big Data Analytics


Topic 3: Hadoop

“there is no alternative to patience and hard work”

"Effort does not betray you”


Outline
• Background
• Components and Architecture
• Running Examples
• Word Count
• Weather Data Analysis
• PageRank
• Hands-on: using Hadoop in Docker + Demos in Class + Assignment
• Hadoop Docker Image shared with the class

Slides Courtesy: Mining of Massive Datasets (http://www.mmds.org )


+ Others
◾ Servers are computers that provide “services” to “clients”

◾ They are typically designed for reliability and to service a large


number of requests

◾ Organizations typically require many physical servers to


provide various services (Web, Email, Database, etc.)

◾ Server hardware is becoming more powerful and compact

3
◾ Organizations would like to conserve the amount of floor
space dedicated to their computer infrastructure

◾ For large-scale installations, compact servers are used

◾ This helps with


 Floor Space
 Manageability
 Scalability
 Power and Cooling
4
◾ Equipments (e.g., servers) are typically placed in racks

5
◾ A facility
used to house computer systems and components,
such as networking and storage systems, cooling, UPS, air
filters

◾ A data center typically houses a large number of


heterogeneous networked computer systems

◾ A data center can occupy one room of a building, one or more


floors, or an entire building

6
7
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 8
◾ A framework for distributed processing
of large data sets
across clusters of commodity computers using simple
programming models

◾ Can scale up from single servers to thousands of machines


 each offering local computation and storage

◾ Designed to detect and handle failures at the application layer


 delivering a highly-available service on top of a cluster of computers,
each of which may be prone to failures
Amazon, Facebook, Google,Twitter, NewYorkTimes,Yahoo! …. many more
12
◾ 20+ billion web pages x 20KB = 400+ TB
◾ 1 computer reads 30-35 MB/sec from disk
 ~4 months to read the web
◾ ~1,000 hard drives to store the web
◾ Takes even more to do something useful
with the data!
◾ Today, a standard architecture for such problems is emerging:
 Cluster of commodity Linux nodes
 Commodity network (ethernet) to connect them

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 13


◾ Challenges:
 How to distribute computation?
 Distributed/parallel programming is hard

◾ Map-reduce addresses all of the above


 Google’s computational/data manipulation model
 Elegant way to work with big data

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 14


CPU
Machine Learning, Statistics
Memory

“Classical” Data Mining


Disk

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 15


2-10 Gbps backbone between racks
1 Gbps between Switch
any pair of nodes
in a rack
Switch Switch

CPU CPU CPU CPU

Mem … Mem Mem … Mem

Disk Disk Disk Disk

Each rack contains 16-64 nodes

In 2011 it was estimated that Google had 1M machines, http://bit.ly/Shh0RO


J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 16
◾ Large-scale computing for data 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 17


◾ Issue: Copying data over a network takes time
◾ Idea:
 Bring computation close to the data
 Store files multiple times for reliability
◾ Map-reduce addresses these problems
 Google’s computational/data manipulation model
 Elegant way to work with big data
 Storage Infrastructure – File system
 Google: GFS. Hadoop: HDFS
 Programming model
 Map-Reduce J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 18
19
◾ The project includes these modules:
 Hadoop Common: The common utilities that support the other
Hadoop modules.
 Hadoop Distributed File System (HDFS™): A distributed file system
that provides high-throughput access to application data.
 Hadoop YARN: A framework for job scheduling and cluster resource
management.
 Hadoop MapReduce: A programming model for large scale data
processing.

20
◾ Problem:
 If nodes fail, how to store data persistently?
◾ Answer:
 Distributed File System:
 Provides global file namespace
 Google GFS; Hadoop HDFS;
◾ Typical usage pattern
 Huge files (100s of GB to TB)
 Data is rarely updated in place
 Reads and appends are common
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 21
◾ Chunk servers
 File is split into contiguous chunks
 Typically each chunk is 16-64MB (the # may have been updated by now)
 Each chunk replicated (usually 2x or 3x) (hdfs-site.xml)
 Try to keep replicas in different racks
◾ Master node
 a.k.a. Name Node in Hadoop’s HDFS
 Stores metadata about where files are stored
 Might be replicated
◾ Client library for file access
 Talks to master to find chunk servers
 Connects directly to chunk servers to access data

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 22


23
◾ Reliable distributed file system
◾ Data kept in “chunks” spread across machines
◾ Each chunk replicated on different machines
 Seamless recovery from disk or machine failure

C0 C1 D0 C1 C2 C5 C0 C5

C5 C2 C5 C3 D0 D1 … D0 C2
Chunk server 1 Chunk server 2 Chunk server 3 Chunk server N

Bring computation directly to the data!


Chunk servers also serve as compute servers
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 24
Warm-up task:
◾ We have a huge text document

◾ Count the number of times each


distinct word appears in the file
◾ Sample application:
 Analyze web server logs to find popular URLs

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 25


Case 1:
 File too large for memory, but all <word, count> pairs fit in memory
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 2 captures the essence of MapReduce
 Great thing is that it is naturally parallelizable

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 26


◾ Sequentially read a lot of data
◾ Map:
 Extract something you care about
◾ Group by key: Sort and Shuffle
◾ Reduce:
 Aggregate, summarize, filter or transform
◾ Write the result

Outline stays the same, Map and Reduce


change to fit the problem

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 27


Input Intermediate
key-value pairs key-value pairs

k v
map
k v
k v
map
k v
k v

… …

v k v
k

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 28


Output
Intermediate Key-value groups key-value pairs
key-value pairs
reduce
k v k v v v k v
reduce
Group k v
k v by key k v v

k v

… … …

k v k v k v

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 29


◾ Input: a set of key-value pairs
◾ Programmer specifies two methods:
 Map(k, v)  <k’, v’>*
 Takes a key-value pair and outputs a set of key-value pairs
 E.g., key is the filename, value is a single line in the file
 There is one Map call for every (k,v) pair
 Reduce(k’, <v’>*)  <k’, v’’>*
 All values v’ with same key k’ are reduced together
and processed in v’ order
 There is one Reduce function call per unique key k’

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 30


MapReduce: Word Counting
Provided by the Provided by the
programmer programmer
MAP: Group by key: Reduce:
Read input and Collect all values
Collect all pairs
produces a set of belonging to the
with same key
key-value pairs key and output

data
The crew of the space
(The, 1) (crew, 1)

reads
shuttle Endeavor recently
(crew, 1) (crew, 1)

read the
returned to Earth as
ambassadors, harbingers of (crew, 2)
a new era of space (of, 1) (space, 1)
(space, 1)

sequential
exploration. Scientists at (the, 1) (the, 1)
NASA are saying that the (the, 3)
(space, 1) (the, 1)

Sequentially
recent assembly of the
Dextre bot is the first step in (shuttle, 1)
(shuttle, 1) (the, 1)
a long-term space-based
(recently, 1)
man/mache partnership. (Endeavor, 1) (shuttle, 1)
'"The work we're doing now …

Only
-- the robotics we're doing - (recently, 1) (recently, 1)
- is what we're going to
need …………………….. …. …
Big document (key, value) (key, value) (key, value)
J. Leskovec, A. Rajaraman, J. Ullman:
Mining of Massive Datasets, 31
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 32
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 33
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 34
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 35
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 36
J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 37
map(key, value):
// key: document name; value: text of the document
for each word w in value:
emit(w, 1)

reduce(key, values):
// key: a word; value: an iterator over counts
result = 0
for each count v in values:
result += v
emit(key, result)

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 38


Map-Reduce environment takes care of:
◾ Partitioning the input data
◾ Scheduling the program’s 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 39

You might also like