Skip to main content

MapReduce & GFS (Google)

At a glance
  • Problem solved: store and process volumes larger than a single machine can handle, on commodity hardware where failure is the norm.
  • Era: GFS presented at SOSP in October 2003, MapReduce at OSDI in December 2004. First version of the MapReduce library written in February 2003.
  • Publisher: Google (academic publications, no open source code).
  • Created by: Sanjay Ghemawat, Howard Gobioff and Shun-Tak Leung (GFS); Jeffrey Dean and Sanjay Ghemawat (MapReduce).
  • Category: distributed storage + distributed computing model.

Historical context​

In the early 2000s, Google has to crawl and index the web. The MapReduce paper explains that, over five years, its authors wrote "hundreds of special-purpose computations" over crawled documents and request logs: inverted indexes, the link graph, the most frequent queries of the day. Each computation is simple, but has to run on hundreds or thousands of machines, and the code for parallelization, distribution and failure recovery ends up drowning the business logic.

Google builds on cheap machines, and the GFS paper (2003) turns this into its first assumption: "component failures are the norm rather than the exception". The authors saw failures caused by application bugs, operating system bugs, human errors, disks, memory, connectors, networking and power supplies. Files are huge (multi-GB is common), data is appended at the end rather than rewritten, and sustained bandwidth matters more than latency. Classic file systems are not designed for this profile.

GFS answers storage. In 2003, the largest GFS clusters have over 1,000 storage nodes and over 300 TB of disk. MapReduce answers compute: Dean and Ghemawat write the first version of the library in February 2003 and improve it in August 2003 (locality, dynamic load balancing). By September 2004, almost 900 distinct MapReduce programs are in Google's source tree, up from zero in early 2003.

The flagship use case is a complete rewrite of the web search indexing system: more than 20 TB of raw documents processed by a sequence of five to ten MapReduce operations. One phase shrinks from about 3,800 lines of C++ to about 700. Google publishes no code: the papers are what travels, and Doug Cutting and Mike Cafarella reimplement them inside the Nutch crawler, which will become Hadoop.

Key idea​

Separate distributed storage from the computing model, and make fault tolerance automatic by relying on one strong assumption: just rerun.

  • GFS splits files into large 64 MB chunks, replicated three times by default. A single master keeps all metadata in memory; data never flows through it.
  • MapReduce asks the developer for two functions inspired by Lisp: map turns each record into intermediate key/value pairs, reduce merges all values of the same key. The framework parallelizes, distributes, groups by key and reruns whatever fails. The paper promises that programmers "without any experience with parallel and distributed systems" can use a large cluster.

How it works​

GFS.

  • A cluster = one master + chunkservers (commodity Linux machines) + clients. Each chunk has a 64-bit identifier.
  • The client asks the master where the chunks are, caches the answer, then reads and writes directly with the chunkservers.
  • The master keeps less than 64 bytes of metadata per 64 MB chunk, so everything fits in RAM. An operation log makes it durable, and shadow masters provide read-only access if it goes down.
  • No POSIX API, but a record append operation: hundreds of producers can append to the same file at the same time.

MapReduce, the steps from the paper:

  1. The input is split into M pieces of 16 to 64 MB; a master assigns M map tasks and R reduce tasks to workers.
  2. Each map reads its piece, applies the map function and buffers the pairs in memory.
  3. Periodically, the pairs are written to local disk, partitioned into R regions (by default a hash of the key).
  4. Each reduce reads its region from every mapper over RPC and sorts by key (external sort if needed): this is what later became known as the shuffle.
  5. The reduce function is called once per key; output goes to GFS, one file per reduce task.
map(String key, String value): // key: document name
for each word w in value:
EmitIntermediate(w, "1");

reduce(String key, Iterator values): // key: a word
int result = 0;
for each v in values:
result += ParseInt(v);
Emit(AsString(result));

Word count, pseudo-code from the 2004 paper.

  • Failures: the master pings workers. A completed map task on a dead machine is rerun, because its output was on local disk; a completed reduce is not, its output is already in GFS. The master itself is not protected in 2004: its failure aborts the job.
  • Locality: the master places maps on a machine holding a replica of the block, otherwise on the same network switch.
  • Backup tasks: near the end of a job, the last tasks are launched twice, so as not to wait for a slow machine (straggler).
  • Typical scale: M = 200,000 and R = 5,000 on 2,000 machines.

By the numbers​

FigureContextSource
Over 1,000 nodes, over 300 TBLargest GFS clusters in 2003GFS paper, 2003
64 MB, 3 replicasGFS default chunk size and replication (2003)GFS paper, 2003
29,423 jobs, 3,288 TB readMapReduce jobs run at Google in August 2004MapReduce paper, 2004
891 secondsSorting about 1 TB on about 1,800 machines (2004)MapReduce paper, 2004
+44%Same sort's duration without backup tasks (2004)MapReduce paper, 2004
Only +5%Sort duration after killing 200 of 1,746 workers (2004)MapReduce paper, 2004
3,800 lines down to 700One web indexing phase rewritten in MapReduce (2004)MapReduce paper, 2004
100,000 jobs and over 20 PB per dayMapReduce usage at Google (CACM, January 2008)CACM 2008 [S]

Milestones​

  • February 2003: first version of the MapReduce library; major improvements in August 2003.
  • October 2003: GFS paper at SOSP (Bolton Landing, New York).
  • December 2004: MapReduce paper at OSDI (San Francisco).
  • 2004-2005: Cutting and Cafarella reimplement GFS and MapReduce in Nutch, which runs on 20 to 40 machines in 2005.
  • February 2006: the code leaves Nutch and becomes Hadoop.
  • January 2008: MapReduce article in Communications of the ACM, with 2007 figures.
  • 2010: according to Yahoo!'s HDFS paper, GFS "is also evolving into a distributed namespace implementation", with hundreds of masters.

Did you know?​

  • The name comes from Lisp: "Our abstraction is inspired by the map and reduce primitives present in Lisp and many other functional languages."
  • An initialization bug disabled processor caches on some machines: they computed more than a hundred times slower. This is one of the reasons for backup tasks.
  • During network maintenance, groups of 80 machines became unreachable for several minutes at a time; the master simply reran their work and the job finished.
  • The 2004 sort ran "on a weekend afternoon, when the CPUs, disks, and network were mostly idle", on machines with 4 GB of RAM, of which 1 to 1.5 GB were already taken by other tasks.

Strengths and limitations​

StrengthsLimitations
Scales on commodity hardwareRigid model: everything must fit into map then reduce
Fault tolerance through plain re-executionIntermediate outputs written to disk, chaining jobs is costly
Data locality (less network traffic)Poorly suited to iterative (ML) and interactive workloads
Short business code, hidden parallelismSingle master: GFS bounded by master RAM, job lost if the MapReduce master fails (2004)

Where it fits​

These two papers are the direct ancestor of Hadoop: HDFS takes over the GFS architecture (NameNode for master, DataNodes for chunkservers) and Hadoop's MapReduce engine takes over Google's. Hive will add SQL on top, HBase will follow another Google paper (Bigtable, 2006), and YARN will later separate resource management from the MapReduce model. The model's limits (disk at every step, no iteration) will motivate Spark and interactive SQL engines such as Impala or Trino.

Sources​

To do
  • Read the 2008 CACM article on the ACM page (only the abstract was read, through a relay).
  • Find a primary source for Colossus, the successor of GFS.
  • The word shuffle does not appear in the 2004 paper: here it refers to steps 3 and 4, following common usage.