Understanding Map-Reduce Framework
Understanding Map-Reduce Framework
Map-Reduce
• Design pattern to take advantage of clustered machines
to do processing in parallel
• While keeping as much work and data as possible local to a single
machine
• Widely used open source implementation and is the part
of Hadoop project.
• Map function- Reads the records from the database
and emits key-value pairs.
• Reduce function- Takes several key-value pairs with the
same key and aggregates them with one.
2
Map-Reduce Example
• Let’s assume we have chosen orders as our aggregate, with each
order having line items.
• Each line item has a product ID, quantity, and the price charged. This
aggregate makes a lot of sense as usually people want to see the
whole order in one access.
• Sales analysis people want to see a product and its total revenue for
the last seven days. This report doesn’t fit the aggregate structure
• Such situation that calls for map-reduce.
• A map is a function whose input is a single aggregate and whose
output is a bunch of key value pairs.
• Reduce function takes multiple map outputs with the same key and
combines their values. It would reduce down to one, with the totals for
the quantity and revenue.
3
Map function
• Each instance of the map function is independent of all the others.
Takes a single aggregate record as input
• A map function might yield 1000 line items from orders for “Database
Refactoring”
• While the map function is limited to working only on data from a single
aggregate
Map function
• Each application of the map function is independent of all
the others.
• Takes a single aggregate record as input
• Outputs a set of relevant key-value pairs
• Each instance of the map function is independent from all
others
5
Reduce function
• Takes multiple map outputs with the same key as input
• Summarizes (or reduces) there values to a single output,
uses all values emitted for a single key
6
Map-reduce framework
• The map-reduce framework arranges for map tasks to be
run on the correct nodes to process all the documents and
for data to be moved to the reduce function
• Arranges for map function to be applied to pertinent
documents on all nodes.
• Moves data to the location of the reduce function.
• Collects all values for a single pair and calls the reduce
function on the key and value collection.
• To run map-reduce job, programmers only need to supply
the map and reduce functions.
7
Partitioning
9
Combining
11
Composing Map-Reduce
Calculations
13