My Blog

November 24, 2008


Filed under: Miscellaneous — by enotebook @ 11:15 am

Copy from:
MapReduce is a software framework introduced by Google to support parallel computations over large (multiple petabyte[1]) data sets on clusters of computers. This framework is largely taken from map and reduce functions commonly used in functional programming,[2] although the actual semantics of the framework are not the same.[3]
MapReduce implementations have been written in C++, Java, Python and other languages.

Logical view
The Map and Reduce functions of MapReduce are both defined with respect to data structured in (key, value) pairs. Map takes one pair of data with a type on a data domain, and returns a list of pairs in a different domain:
Map(k1,v1) -> list(k2,v2)
The map function is applied in parallel to every item in the input dataset. This produces a list of (k2,v2) pairs for each call. After that, the MapReduce framework collects all pairs with the same key from all lists and groups them together, thus creating one group for each one of the different generated keys.
The Reduce function is then applied in parallel to each group, which in turn produces a collection of values in the same domain:
Reduce(k2, list (v2)) -> list(v2)
Each Reduce call typically produces either one value v2 or an empty return, though one call is allowed to return more than one value. The returns of all calls are collected as the desired result list.
Thus the MapReduce framework transforms a list of (key, value) pairs into a list of values. This behavior is different from the functional programming map and reduce combination, which accepts a list of arbitrary values and returns one single value that combines all the values returned by map.
It is necessary but not sufficient to have implementations of the map and reduce abstractions in order to implement MapReduce. Furthermore effective implementations of MapReduce require a distributed file system to connect the processes performing the Map and Reduce phases.

The canonical example application of MapReduce is a process to count the appearances of each different word in a set of documents:
map(String name, String document):
// key: document name
// value: document contents
for each word w in document:
EmitIntermediate(w, 1);

reduce(String word, Iterator partialCounts):
// key: a word
// values: a list of aggregated partial counts
int result = 0;
for each v in partialCounts:
result += ParseInt(v);

Here, each document is split in words, and each word is counted initially with a “1” value by the Map function, using the word as the result key. The framework puts together all the pairs with the same key and feeds them to the same call to Reduce, thus this function just needs to sum all of its input values to find the total appearances of that word.

The frozen part of the MapReduce framework is a large distributed sort. The hot spots, which the application defines, are:
* an input reader
* a Map function
* a partition function
* a compare function
* a Reduce function
* an output writer
Input reader
The input reader divides the input into 16MB to 128MB splits and the framework assigns one split to each Map function. The input reader reads data from stable storage (typically a distributed file system like Google File System) and generates key/value pairs.
A common example will read a directory full of text files and return each line as a record.
Map function
Each Map function takes a series of key/value pairs, processes each, and generates zero or more output key/value pairs. The input and output types of the map can be (and often are) different from each other.
If the application is doing a word count, the map function would break the line into words and output the word as the key and “1” as the value.
Partition function
The output of all of the maps is allocated to particular reduces by the application’s partition function. The partition function is given the key and the number of reduces and returns the index of the desired reduce.
A typical default is to hash the key and modulo the number of reduces.
Comparison function
The input for each reduce is pulled from the machine where the map ran and sorted using the application’s comparison function.
Reduce function
The framework calls the application’s reduce function once for each unique key in the sorted order. The reduce can iterate through the values that are associated with that key and output 0 or more key/value pairs.
In the word count example, the reduce function takes the input values, sums them and generates a single output of the word and the final sum.
Output writer
The Output Writer writes the output of the reduce to stable storage, usually a distributed file system, such as Google File System.

Distribution and reliability
MapReduce achieves reliability by parceling out a number of operations on the set of data to each node in the network; each node is expected to report back periodically with completed work and status updates. If a node falls silent for longer than that interval, the master node (similar to the master server in the Google File System) records the node as dead, and sends out the node’s assigned work to other nodes. Individual operations use atomic operations for naming file outputs as a double check to ensure that there are not parallel conflicting threads running; when files are renamed, it is possible to also copy them to another name in addition to the name of the task (allowing for side-effects).
The reduce operations operate much the same way, but because of their inferior properties with regard to parallel operations, the master node attempts to schedule reduce operations on the same node, or in the same rack as the node holding the data being operated on; this property is desirable as it conserves bandwidth across the backbone network of the datacenter.
Implementations may not be highly-available; in Hadoop, for example, the NameNode is a Single Point of Failure for the distributed filesystem; if theJobTracker fails, all outstanding work is lost.

MapReduce is useful in a wide range of applications, including: “distributed grep, distributed sort, web link-graph reversal, term-vector per host, web access log stats, inverted index construction, document clustering, machine learning, statistical machine translation…” Most significantly, when MapReduce was finished, it was used to completely regenerate Google’s index of the World Wide Web, and replaced the old ad hoc programs that updated the index and ran the various analyses. [4]
MapReduce’s stable inputs and outputs are usually stored in a distributed file system. The transient data is usually stored on local disk and fetched remotely by the reduces.

David DeWitt and Michael Stonebraker, pioneering experts in parallel databases and shared nothing architectures, have made some controversial assertions about the breadth of problems that MapReduce can be used for. They called its interface too low-level, and questioned whether it really represents the paradigm shift its proponents have claimed it is.[5] They challenge the MapReduce proponents claims of novelty, citing Teradata as an example of prior art that has existed for over two decades; they compared MapReduce programmers to Codasyl programmers, noting both are “writing in a low-level language performing low-level record manipulation”.[5] MapReduce’s use of input files and lack of schema support prevents the perf
ance improvements enabled by common database system features such as B-trees and hash partitioning, though projects such as PigLatin and Sawzall are starting to address these problems.[6]

* The Google MapReduce framework is implemented in C++ with interfaces in Python and Java.
* The Hadoop project is a free open source Java MapReduce implementation.
* Greenplum is a commercial MapReduce implementation, with support for Python, Perl, SQL and other languages.[7]
* Phoenix [1] is a shared-memory implementation of MapReduce implemented in C.
* MapReduce has also been implemented for the Cell Broadband Engine, also in C. [2]
* MapReduce has been implemented on NVIDIA GPUs (Graphics Processors) using CUDA [3].
* Qt Concurrent is a simplified version of the framework, implemented in C++, used for distributing a task between multiple processor cores.
* CouchDB uses a MapReduce framework for defining views over distributed documents
* Skynet is an open source Ruby implementation of Google’s MapReduce framework
* Disco is an open source MapReduce implementation by Nokia. Its core is written in Erlang and jobs are normally written in Python.
* Aster Data Systems nCluster In-Database MapReduce implements MapReduce inside the database.
* The open-source Hive framework from Facebook (which provides a SQL-like language over files, layered on the open-source Hadoop MapReduce engine.)

Specific references:
1. ^ Google spotlights data center inner workings | Tech news blog – CNET
2. ^ “Our abstraction is inspired by the map and reduce primitives present in Lisp and many other functional languages.” -“MapReduce: Simplified Data Processing on Large Clusters”, by Jeffrey Dean and Sanjay Ghemawat; from Google Labs
3. ^ “Google’s MapReduce Programming Model — Revisited” — paper by Ralf Lammel; from Microsoft
4. ^ “How Google Works”. “As of October, Google was running about 3,000 computing jobs per day through MapReduce, representing thousands of machine-days, according to a presentation by Dean. Among other things, these batch routines analyze the latest Web pages and update Google’s indexes.”
5. ^ a b David DeWitt; Michael Stonebraker. “MapReduce: A major step backwards”. Retrieved on 2008-08-27.
6. ^ David DeWitt; Michael Stonebraker. “MapReduce II”. Retrieved on 2008-08-27.
7. ^ Parallel Programming in the Age of Big Data
General references:
* Dean, Jeffrey & Ghemawat, Sanjay (2004). “MapReduce: Simplified Data Processing on Large Clusters”. Retrieved Apr. 6, 2005.
* “High-performance analytics”.


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: