Mapreduce: Theory and Implementation: Cse 490H - Intro To Distributed Computing, Modified by George Lee
Mapreduce: Theory and Implementation: Cse 490H - Intro To Distributed Computing, Modified by George Lee
Outline
Lisp/ML map/fold review MapReduce overview Example
Map
map f lst: (a->b) -> (a list) -> (b list) Creates a new list by applying f to each element of the input list; returns output in order.
Fold
fold f x0 lst: ('a*'b->'b)->'b->('a list)->'b Moves across a list, applying f to each element plus an accumulator. f returns the next accumulator value, which is combined with the next element of the list
In a purely functional setting, elements of a list being computed by map cannot see the effects of the computations on other elements If order of application of f to elements in list is commutative, we can reorder or parallelize execution This is the secret that MapReduce exploits
MapReduce
MapReduce
Automatic parallelization & distribution Fault-tolerant Provides status and monitoring tools Clean abstraction for programmers
Programming Model
Borrows from functional programming Users implement interface of two functions:
map
Records from the data source (lines out of files, rows of a database, etc) are fed into the map function as key*value pairs: e.g., (filename, line). map() produces one or more intermediate values along with an output key from the input.
reduce
After the map phase is over, all the intermediate values for a given output key are combined together into a list reduce() combines those intermediate values into one or more final values for that same output key (in practice, usually only one final value per key)
Parallelism
map() functions run in parallel, creating different intermediate values from different input data sets reduce() functions also run in parallel, each working on a different output key All values are processed independently Bottleneck: reduce phase cant start until map phase is completely finished.
int result = 0;
for each v in intermediate_values: result += ParseInt(v); Emit(AsString(result));
Locality
Master program divvies up tasks based on location of data: tries to have map() tasks on same machine as physical file data, or at least same rack map() task inputs are divided into 64 MB blocks: same size as Google File System chunks
Fault Tolerance
Master notices particular input key/values cause crashes in map(), and skips those values on re-execution.
Effect:
Optimizations
Master redundantly executes slowmoving map tasks; uses results of first copy to finish
Optimizations
Combiner functions can run on same machine as a mapper Causes a mini-reduce phase to occur before the real reduce phase, to save bandwidth
MapReduce Conclusions
MapReduce has proven to be a useful abstraction Greatly simplifies large-scale computations at Google Functional programming paradigm can be applied to large-scale applications Fun to use: focus on problem, let library deal w/ messy details
21
PageRank: Formula
Given page A, and pages T1 through Tn linking to A, PageRank is defined as:
PR(A) = (1-d) + d (PR(T1)/C(T1) + ... + PR(Tn)/C(Tn)) C(P) is the cardinality (out-degree) of page P d is the damping (random URL) factor
PageRank: Intuition
Calculation is iterative: PRi+1 is based on PRi Each page distributes its PRi to all pages it links to. Linkees add up their awarded rank fragments to find their PRi+1 d is a tunable parameter (usually = 0.85) encapsulating the random jump factor
'next' table depends on 'current', but not on any other rows of 'next' Individual rows of the adjacency matrix can be processed in parallel Sparse matrix rows are relatively small
Consequences of insights:
We
can map each row of 'current' to a list of PageRank fragments to assign to linkees These fragments can be reduced into a single PageRank value for a page by summing Graph representation can be even more compact; since each element is simply 0 or 1, only transmit column numbers where it's 1
Map task takes (URL, page content) pairs and maps them to (URL, (PRinit, list-of-urls))
PRinit is the seed PageRank for URL list-of-urls contains all pages pointed to
by URL
Reduce task gets (URL, url_list) and many (URL, val) values
Sum vals and fix up with d Emit (URL, (new_rank, url_list))
Finishing up...
A non-parallelizable component determines whether convergence has been achieved (Fixed number of iterations? Comparison of key values?) If so, write out the PageRank lists - done! Otherwise, feed output of Phase 2 into another Phase 2 iteration
Conclusions
MapReduce isn't the greatest at iterated computation, but still helps run the heavy lifting Key element in parallelization is independent PageRank computations in a given step Parallelization requires thinking about minimum data partitions to transmit (e.g., compact representations of graph rows)
Even
the implementation shown today doesn't actually scale to the whole Internet; but it works for intermediate-sized graphs
Controversial Views
http://databasecolumn.vertica.com/databas e-innovation/mapreduce-a-major-stepbackwards/ http://databasecolumn.vertica.com/databas e-innovation/mapreduce-ii/
33