Skip to content

MapReduce: Simplified Data Processing on Large Clusters

22827字约76分钟

文献翻译

2024-11-26

相关信息

本文通过 MinerU 转换并通过豆包翻译,原文地址:MapReduce: Simplified Data Processing on Large ClustersLec1 MapReduce 的参考文献。

MapReduce: Simplified Data Processing on Large Clusters

MapReduce:在大型集群上简化的数据处理 Jeffrey Dean and Sanjay Ghemawat jeff@google.com, sanjay@google.com Google, Inc.

Abstract

摘要

MapReduce is a programming model and an associated implementation for processing and generating large data sets. Users specify a map function that processes a key/value pair to generate a set of intermediate key/value pairs, and a reduce function that merges all intermediate values associated with the same intermediate key. Many real world tasks are expressible in this model, as shown in the paper.

MapReduce 是一种编程模型以及用于处理和生成大型数据集的相关实现。用户指定一个映射函数,该函数处理键/值对以生成一组中间键/值对,以及一个归约函数,该函数合并与同一中间键相关联的所有中间值。正如论文中所示,许多现实世界的任务可以用这种模型来表达。

Programs written in this functional style are automatically parallelized and executed on a large cluster of commodity machines. The run-time system takes care of the details of partitioning the input data, scheduling the program’s execution across a set of machines, handling machine failures, and managing the required inter-machine communication. This allows programmers without any experience with parallel and distributed systems to easily utilize the resources of a large distributed system.

以这种函数式风格编写的程序会自动并行化,并在一组大规模的商用机器集群上执行。运行时系统负责处理输入数据分区的细节、在一组机器上安排程序的执行、处理机器故障以及管理所需的机器间通信。这使得没有任何并行和分布式系统经验的程序员能够轻松利用大型分布式系统的资源。

Our implementation of MapReduce runs on a large cluster of commodity machines and is highly scalable: a typical MapReduce computation processes many terabytes of data on thousands of machines. Programmers find the system easy to use: hundreds of MapReduce programs have been implemented and upwards of one thousand MapReduce jobs are executed on Google’s clusters every day.

我们的 MapReduce 实现运行在一个大型的商用机器集群上,并且具有高度可扩展性:一个典型的 MapReduce 计算会在数千台机器上处理数千兆字节的数据。程序员发现该系统易于使用:已经实现了数百个 MapReduce 程序,并且每天在谷歌的集群上执行超过一千个 MapReduce 作业。

1 Introduction

1 引言

Over the past five years, the authors and many others at Google have implemented hundreds of special-purpose computations that process large amounts of raw data, such as crawled documents, web request logs, etc., to compute various kinds of derived data, such as inverted indices, various representations of the graph structure of web documents, summaries of the number of pages crawled per host, the set of most frequent queries in a given day, etc. Most such computations are conceptually straightforward. However, the input data is usually large and the computations have to be distributed across hundreds or thousands of machines in order to finish in a reasonable amount of time. The issues of how to parallelize the computation, distribute the data, and handle failures conspire to obscure the original simple computation with large amounts of complex code to deal with these issues.

在过去的五年里,作者和谷歌的许多其他人已经实现了数百个特殊用途的计算,这些计算处理大量原始数据,例如抓取的文档、网络请求日志等,以计算各种衍生数据,例如倒排索引、网络文档图形结构的各种表示、每个主机抓取的页面数量摘要、给定一天中最常见查询的集合等等。大多数这样的计算在概念上是直接明了的。然而,输入数据通常很大,并且这些计算必须分布在成百上千台机器上,以便在合理的时间内完成。如何并行化计算、分布数据以及处理故障等问题共同使得原本简单的计算被大量复杂的代码所掩盖,以处理这些问题。

As a reaction to this complexity, we designed a new abstraction that allows us to express the simple computations we were trying to perform but hides the messy details of parallelization, fault-tolerance, data distribution and load balancing in a library. Our abstraction is inspired by the map and reduce primitives present in Lisp and many other functional languages. We realized that most of our computations involved applying a map operation to each logical “record” in our input in order to compute a set of intermediate key/value pairs, and then applying a reduce operation to all the values that shared the same key, in order to combine the derived data appropriately. Our use of a functional model with userspecified map and reduce operations allows us to parallelize large computations easily and to use re-execution as the primary mechanism for fault tolerance.

作为对这种复杂性的一种反应,我们设计了一种新的抽象,它允许我们表达我们试图执行的简单计算,但将并行化、容错、数据分布和负载均衡的杂乱细节隐藏在一个库中。我们的抽象受到了 Lisp 和许多其他函数式语言中存在的 map(映射)和 reduce(归约)原语的启发。我们意识到我们的大多数计算都涉及对输入中的每个逻辑“记录”应用一个映射操作,以便计算一组中间键/值对,然后对所有具有相同键的值应用一个归约操作,以便适当地组合派生数据。我们使用带有用户指定的映射和归约操作的函数模型,允许我们轻松地并行化大型计算,并使用重新执行作为容错的主要机制。

The major contributions of this work are a simple and powerful interface that enables automatic parallelization and distribution of large-scale computations, combined with an implementation of this interface that achieves high performance on large clusters of commodity PCs.

这项工作的主要贡献在于一个简单而强大的接口,该接口能够实现大规模计算的自动并行化和分布,再加上该接口的一个实现,其在由商用个人计算机组成的大型集群上实现了高性能。

Section 2 describes the basic programming model and gives several examples. Section 3 describes an implementation of the MapReduce interface tailored towards our cluster-based computing environment. Section 4 describes several refinements of the programming model that we have found useful. Section 5 has performance measurements of our implementation for a variety of tasks. Section 6 explores the use of MapReduce within Google including our experiences in using it as the basis for a rewrite of our production indexing system. Section 7 discusses related and future work.

第 2 节描述了基本编程模型并给出了几个示例。第 3 节描述了针对我们基于集群的计算环境定制的 MapReduce 接口的一种实现。第 4 节描述了我们发现有用的编程模型的几个改进。第 5 节有我们针对各种任务的实现的性能测量。第 6 节探讨了在谷歌内 MapReduce 的使用,包括我们将其用作重写我们生产索引系统的基础的经验。第 7 节讨论了相关和未来的工作。

2 Programming Model

2 编程模型

The computation takes a set of input key/value pairs, and produces a set of output key/value pairs. The user of the MapReduce library expresses the computation as two functions: Map and Reduce.

计算接收一组输入键/值对,并生成一组输出键/值对。MapReduce 库的用户将计算表示为两个函数:映射(Map)和归约(Reduce)。

Map, written by the user, takes an input pair and produces a set of intermediate key/value pairs. The MapReduce library groups together all intermediate values associated with the same intermediate key II and passes them to the Reduce function.

映射,由用户编写,接受一个输入对并生成一组中间键/值对。MapReduce 库将与同一中间键 II 相关联的所有中间值组合在一起,并将它们传递给归约函数。

The Reduce function, also written by the user, accepts an intermediate key II and a set of values for that key. It merges together these values to form a possibly smaller set of values. Typically just zero or one output value is produced per Reduce invocation. The intermediate values are supplied to the user’s reduce function via an iterator. This allows us to handle lists of values that are too large to fit in memory.

Reduce 函数,同样由用户编写,接收一个中间键 II 以及该键的一组值。它将这些值合并在一起以形成一个可能更小的值集。通常每次调用 Reduce 仅产生零个或一个输出值。中间值通过一个迭代器提供给用户的 Reduce 函数。这允许我们处理太大而无法在内存中容纳的值列表。

2.1 Example

2.1 示例

Consider the problem of counting the number of occurrences of each word in a large collection of documents. The user would write code similar to the following pseudo-code:

考虑在大量文档集合中计算每个单词出现次数的问题。用户将编写类似于以下伪代码的代码:

map(String key, String value):
    // key: document name
    // value: document contents
    for each word w in value:
        EmitIntermediate(w, "1")

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

The map function emits each word plus an associated count of occurrences (just ‘1’ in this simple example). The reduce function sums together all counts emitted for a particular word.

map 函数发出每个单词以及相关的出现次数(在这个简单示例中仅为“1”)。reduce 函数将为特定单词发出的所有计数相加。

In addition, the user writes code to fill in a mapreduce specification object with the names of the input and output files, and optional tuning parameters. The user then invokes the MapReduce function, passing it the specifi- cation object. The user’s code is linked together with the MapReduce library (implemented in C++C++ ). Appendix A contains the full program text for this example.

此外,用户编写代码以用输入和输出文件的名称以及可选的调优参数来填充一个 mapreduce 规范对象。然后用户调用 MapReduce 函数,将该规范对象传递给它。用户的代码与 MapReduce 库(用 C++C++ 实现)链接在一起。附录 A 包含此示例的完整程序文本。

2.2 Types

2.2 类型

Even though the previous pseudo-code is written in terms of string inputs and outputs, conceptually the map and reduce functions supplied by the user have associated types:

尽管前面的伪代码是根据字符串输入和输出编写的,但从概念上讲,用户提供的映射(map)和归约(reduce)函数具有相关类型:

I.e., the input keys and values are drawn from a different domain than the output keys and values. Furthermore, the intermediate keys and values are from the same domain as the output keys and values.

即,输入键和值来自与输出键和值不同的域。此外,中间键和值与输出键和值来自相同的域。

Our C++C++ implementation passes strings to and from the user-defined functions and leaves it to the user code to convert between strings and appropriate types.

我们的 C++C++ 实现将字符串传递给用户定义函数以及从用户定义函数传出,并将字符串和适当类型之间的转换留给用户代码。

2.3 More Examples

2.3 更多示例

Here are a few simple examples of interesting programs that can be easily expressed as MapReduce computations.

以下是一些简单有趣的程序示例,它们可以很容易地表示为 MapReduce 计算。

Distributed Grep: The map function emits a line if it matches a supplied pattern. The reduce function is an identity function that just copies the supplied intermediate data to the output.

分布式 Grep:如果匹配所提供的模式,映射函数会发出一行。归约函数是一个恒等函数,它只是将所提供的中间数据复制到输出。

Count of URL Access Frequency: The map function processes logs of web page requests and outputs URL,1\langle{\mathrm{URL}},{\mathrm{1}}\rangle . The reduce function adds together all values for the same URL and emits a URL, total count pair.

网址访问频率计数:映射函数处理网页请求日志并输出 网址,1\langle{\mathrm{网址}},{\mathrm{1}}\rangle。归约函数将相同网址的所有值相加,并发出一个网址、总计数对。

Reverse Web-Link Graph: The map function outputs target, source pairs for each link to a target URL found in a page named source. The reduce function concatenates the list of all source URLs associated with a given target URL and emits the pair: target, list(source)

反向网络链接图:映射函数为在名为源的页面中找到的每个指向目标 URL 的链接输出目标、源对。归约函数将与给定目标 URL 相关联的所有源 URL 的列表连接起来,并发出对:目标,列表(源)

Term-Vector per Host: A term vector summarizes the most important words that occur in a document or a set of documents as a list of word, frequency pairs. The map function emits a hostname, term vector pair for each input document (where the hostname is extracted from the URL of the document). The reduce function is passed all per-document term vectors for a given host. It adds these term vectors together, throwing away infrequent terms, and then emits a final hostname, term vector pair.

每主机的词向量:词向量将在一个文档或一组文档中出现的最重要的词汇总为一个词、频率对列表。映射函数为每个输入文档发出一个主机名、词向量对(其中主机名是从文档的 URL 中提取的)。归约函数接收给定主机的所有每个文档词向量。它将这些词向量相加,丢弃不常见的词,然后发出最终的主机名、词向量对。

Figure 1: Execution overview

Inverted Index: The map function parses each document, and emits a sequence of word, document ID\tt I D\rangle pairs. The reduce function accepts all pairs for a given word, sorts the corresponding document IDs and emits a word,list(document ID)\langle\mathtt{w o r d},l i s t(\mathtt{d o c u m e n t}\ \mathtt{I D})\rangle pair. The set of all output pairs forms a simple inverted index. It is easy to augment this computation to keep track of word positions.

倒排索引:映射函数会解析每个文档,并发出一系列的单词、文档 ID\tt ID\rangle 对。归约函数接收给定单词的所有对,对相应文档 ID 进行排序,并发出一个 word,list(document ID)\langle\mathtt{word},list(\mathtt{document}\ \mathtt{ID})\rangle 对。所有输出对的集合构成了一个简单的倒排索引。很容易扩充这种计算以跟踪单词位置。

Distributed Sort: The map function extracts the key from each record, and emits a key, record pair. The reduce function emits all pairs unchanged. This computation depends on the partitioning facilities described in Section 4.1 and the ordering properties described in Section 4.2.

分布式排序:映射函数从每条记录中提取键,并发出一个键、记录对。归约函数原封不动地发出所有对。此计算取决于 4.1 节中描述的分区设施和 4.2 节中描述的排序属性。

3 Implementation

3 实现

Many different implementations of the MapReduce interface are possible. The right choice depends on the environment. For example, one implementation may be suitable for a small shared-memory machine, another for a large NUMA multi-processor, and yet another for an even larger collection of networked machines.

MapReduce 接口的许多不同实现都是可能的。正确的选择取决于环境。例如,一种实现可能适合小型共享内存机器,另一种适合大型 NUMA 多处理器,还有一种适合更大的联网机器集合。

This section describes an implementation targeted to the computing environment in wide use at Google:

此部分描述了针对在谷歌广泛使用的计算环境的一种实现:

large clusters of commodity PCs connected together with switched Ethernet [4]. In our environment:

大量的商用个人计算机通过交换式以太网连接在一起 [4]。在我们的环境中:

(1) Machines are typically dual-processor x86\mathbf{x}86 processors running Linux, with 2-4 GB of memory per machine. (2) Commodity networking hardware is used – typically either 100 megabits/second or 1 gigabit/second at the machine level, but averaging considerably less in overall bisection bandwidth.
(3) A cluster consists of hundreds or thousands of machines, and therefore machine failures are common. (4) Storage is provided by inexpensive IDE disks attached directly to individual machines. A distributed file system [8] developed in-house is used to manage the data stored on these disks. The file system uses replication to provide availability and reliability on top of unreliable hardware.
(5) Users submit jobs to a scheduling system. Each job consists of a set of tasks, and is mapped by the scheduler to a set of available machines within a cluster.

(1) 机器通常是运行 Linux 的双处理器 x86\mathbf{x}86 处理器,每台机器有 2 至 4GB 的内存。(2) 使用商业网络硬件——在机器层面通常是每秒 100 兆位或每秒 1 千兆位,但在总体二等分带宽方面平均要低得多。(3) 一个集群由成百上千台机器组成,因此机器故障很常见。(4) 存储由直接连接到各个机器的廉价 IDE 磁盘提供。内部开发的一个分布式文件系统 [8] 用于管理存储在这些磁盘上的数据。该文件系统使用复制来在不可靠的硬件之上提供可用性和可靠性。(5) 用户向调度系统提交作业。每个作业由一组任务组成,并且由调度器映射到集群内的一组可用机器上。

3.1 Execution Overview

3.1 执行概述

The Map invocations are distributed across multiple machines by automatically partitioning the input data into a set of MM splits. The input splits can be processed in parallel by different machines. Reduce invocations are distributed by partitioning the intermediate key space into RR pieces using a partitioning function (e.g., hash(key)  mod  R)h a s h(k e y)\;\mathbf{mod}\;R) ). The number of partitions (R)(R) and the partitioning function are specified by the user.

通过将输入数据自动分割成一组 MM 个分割块,映射(Map)调用被分布在多台机器上。输入分割块可以由不同机器并行处理。归约(Reduce)调用通过使用一个分割函数(例如,hash(key)  mod  R)h a s h(k e y)\; \text{mod}\; R))将中间键空间分割成 RR 块来分布。分区的数量 (R)(R) 和分割函数由用户指定。

Figure 1 shows the overall flow of a MapReduce operation in our implementation. When the user program calls the MapReduce function, the following sequence of actions occurs (the numbered labels in Figure 1 correspond to the numbers in the list below):

图 1 展示了在我们的实现中一个 MapReduce 操作的总体流程。当用户程序调用 MapReduce 函数时,会发生以下一系列动作(图 1 中的编号标签与下面列表中的数字相对应):

  1. The MapReduce library in the user program first splits the input files into MM pieces of typically 16 megabytes to 64 megabytes (MB) per piece (controllable by the user via an optional parameter). It then starts up many copies of the program on a cluster of machines.

  2. 用户程序中的 MapReduce 库首先将输入文件分割成 MM 块,通常每块为 16 兆字节到 64 兆字节(MB)(可由用户通过一个可选参数进行控制)。然后它在一组机器上启动该程序的许多副本。

  3. One of the copies of the program is special – the master. The rest are workers that are assigned work by the master. There are MM map tasks and RR reduce tasks to assign. The master picks idle workers and assigns each one a map task or a reduce task.

  4. 该程序的副本之一是特殊的——主副本。其余的是由主副本分配工作的工作副本。有 MM 个映射任务和 RR 个归约任务要分配。主副本选择空闲的工作副本,并为每个工作副本分配一个映射任务或一个归约任务。

  5. A worker who is assigned a map task reads the contents of the corresponding input split. It parses key/value pairs out of the input data and passes each pair to the user-defined Map function. The intermediate key/value pairs produced by the Map function are buffered in memory.

  6. 被分配了一个映射任务的工作者会读取相应输入分割的内容。它从输入数据中解析出键/值对,并将每一对传递给用户定义的映射函数。由映射函数生成的中间键/值对在内存中进行缓冲。

  7. Periodically, the buffered pairs are written to local disk, partitioned into RR regions by the partitioning function. The locations of these buffered pairs on the local disk are passed back to the master, who is responsible for forwarding these locations to the reduce workers.

  8. 定期地,缓冲的键值对被写入本地磁盘,通过分区函数被划分成 RR 个区域。这些缓冲的键值对在本地磁盘上的位置被传递回主节点,主节点负责将这些位置转发给归约工作者。

  9. When a reduce worker is notified by the master about these locations, it uses remote procedure calls to read the buffered data from the local disks of the map workers. When a reduce worker has read all intermediate data, it sorts it by the intermediate keys so that all occurrences of the same key are grouped together. The sorting is needed because typically many different keys map to the same reduce task. If the amount of intermediate data is too large to fit in memory, an external sort is used.

  10. 当一个归约工作者(reduce worker)由主节点(master)通知有关这些位置时,它使用远程过程调用从映射工作者(map workers)的本地磁盘读取缓冲数据。当一个归约工作者已读取所有中间数据时,它按中间键进行排序,以便相同键的所有出现都组合在一起。之所以需要排序,是因为通常许多不同的键映射到相同的归约任务。如果中间数据的量太大而无法在内存中容纳,则使用外部排序。

  11. The reduce worker iterates over the sorted intermediate data and for each unique intermediate key encountered, it passes the key and the corresponding set of intermediate values to the user’s Reduce function. The output of the Reduce function is appended to a final output file for this reduce partition.

  12. reduce 工作器遍历排序后的中间数据,对于遇到的每个唯一中间键,它将该键以及相应的中间值集合传递给用户的 Reduce 函数。Reduce 函数的输出被附加到该 reduce 分区的最终输出文件。

  13. When all map tasks and reduce tasks have been completed, the master wakes up the user program. At this point, the MapReduce call in the user program returns back to the user code.

  14. 当所有的映射任务(map tasks)和归约任务(reduce tasks)都已完成时,主节点(master)唤醒用户程序。此时,用户程序中的 MapReduce 调用返回给用户代码。

After successful completion, the output of the mapreduce execution is available in the RR output files (one per reduce task, with file names as specified by the user). Typically, users do not need to combine these RR output files into one file – they often pass these files as input to another MapReduce call, or use them from another distributed application that is able to deal with input that is partitioned into multiple files.

成功完成后,mapreduce 执行的输出可在 RR 输出文件中获得(每个归约任务一个,文件名由用户指定)。通常,用户不需要将这些 RR 输出文件合并为一个文件——他们经常将这些文件作为另一个 MapReduce 调用的输入,或者在另一个能够处理被划分到多个文件的输入的分布式应用程序中使用它们。

3.2 Master Data Structures

3.2 主数据结构

The master keeps several data structures. For each map task and reduce task, it stores the state (idle, in-progress, or completed), and the identity of the worker machine (for non-idle tasks).

主节点维护着几个数据结构。对于每个映射任务和归约任务,它存储状态(空闲、进行中或已完成)以及工作机器的标识(对于非空闲任务)。

The master is the conduit through which the location of intermediate file regions is propagated from map tasks to reduce tasks. Therefore, for each completed map task, the master stores the locations and sizes of the RR intermediate file regions produced by the map task. Updates to this location and size information are received as map tasks are completed. The information is pushed incrementally to workers that have in-progress reduce tasks.

主节点(master)是中间文件区域位置从映射任务传播到归约任务的通道。因此,对于每个已完成的映射任务,主节点存储该映射任务生成的 RR 个中间文件区域的位置和大小。随着映射任务的完成,会接收到对此位置和大小信息的更新。该信息会逐步推送给有正在进行的归约任务的工作节点(workers)。

3.3 Fault Tolerance

3.3 容错性

Since the MapReduce library is designed to help process very large amounts of data using hundreds or thousands of machines, the library must tolerate machine failures gracefully.

由于 MapReduce 库旨在帮助使用成百上千台机器处理非常大量的数据,该库必须优雅地容忍机器故障。

Worker Failure

工人故障(Worker Failure)

The master pings every worker periodically. If no response is received from a worker in a certain amount of time, the master marks the worker as failed. Any map tasks completed by the worker are reset back to their initial idle state, and therefore become eligible for scheduling on other workers. Similarly, any map task or reduce task in progress on a failed worker is also reset to idle and becomes eligible for rescheduling.

主节点定期向每个工作节点发送 ping 消息。如果在特定时间内没有从某个工作节点收到响应,主节点就将该工作节点标记为失效。该工作节点完成的任何映射任务都将重置回其初始空闲状态,因此有资格在其他工作节点上进行调度。类似地,在失效工作节点上正在进行的任何映射任务或归约任务也都将重置为空闲状态,并有资格重新调度。

Completed map tasks are re-executed on a failure because their output is stored on the local disk(s) of the failed machine and is therefore inaccessible. Completed reduce tasks do not need to be re-executed since their output is stored in a global file system.

已完成的映射任务(map tasks)在出现故障时会被重新执行,因为它们的输出存储在故障机器的本地磁盘上,因此无法访问。已完成的归约任务(reduce tasks)不需要重新执行,因为它们的输出存储在一个全局文件系统中。

When a map task is executed first by worker AA and then later executed by worker BB (because AA failed), all workers executing reduce tasks are notified of the reexecution. Any reduce task that has not already read the data from worker AA will read the data from worker BB .

当一个映射任务首先由工作节点 AA 执行,然后稍后由工作节点 BB 执行(因为 AA 失败)时,所有执行归约任务的工作节点都会收到重新执行的通知。任何尚未从工作节点 AA 读取数据的归约任务都将从工作节点 BB 读取数据。

MapReduce is resilient to large-scale worker failures. For example, during one MapReduce operation, network maintenance on a running cluster was causing groups of 80 machines at a time to become unreachable for several minutes. The MapReduce master simply re-executed the work done by the unreachable worker machines, and continued to make forward progress, eventually completing the MapReduce operation.

MapReduce 对大规模工作节点故障具有弹性。例如,在一次 MapReduce 操作期间,正在运行的集群上的网络维护导致一次有 80 台机器的组在几分钟内无法访问。MapReduce 主节点只需重新执行无法访问的工作节点机器所做的工作,并继续向前推进,最终完成 MapReduce 操作。

Master Failure

主故障(Master Failure)

It is easy to make the master write periodic checkpoints of the master data structures described above. If the master task dies, a new copy can be started from the last checkpointed state. However, given that there is only a single master, its failure is unlikely; therefore our current implementation aborts the MapReduce computation if the master fails. Clients can check for this condition and retry the MapReduce operation if they desire.

很容易让主节点写入上述主数据结构的定期检查点。如果主任务死亡,可以从最后一个检查点状态启动一个新副本。然而,鉴于只有一个主节点,它的故障不太可能发生;因此,我们当前的实现如果主节点失败则中止 MapReduce 计算。客户端可以检查这种情况,如果他们愿意,可以重试 MapReduce 操作。

Semantics in the Presence of Failures

故障情况下的语义

When the user-supplied map and reduce operators are deterministic functions of their input values, our distributed implementation produces the same output as would have been produced by a non-faulting sequential execution of the entire program.

当用户提供的映射(map)和归约(reduce)操作符是其输入值的确定性函数时,我们的分布式实现所产生的输出与整个程序无故障顺序执行所产生的输出相同。

We rely on atomic commits of map and reduce task outputs to achieve this property. Each in-progress task writes its output to private temporary files. A reduce task produces one such file, and a map task produces RR such files (one per reduce task). When a map task completes, the worker sends a message to the master and includes the names of the RR temporary files in the message. If the master receives a completion message for an already completed map task, it ignores the message. Otherwise, it records the names of RR files in a master data structure.

我们依靠映射(map)和归约(reduce)任务输出的原子提交来实现此属性。每个进行中的任务将其输出写入私有临时文件。一个归约任务生成一个这样的文件,而一个映射任务生成 RR 个这样的文件(每个归约任务一个)。当一个映射任务完成时,工作节点向主节点发送一条消息,并在消息中包含 RR 个临时文件的名称。如果主节点收到一个已完成映射任务的完成消息,它将忽略该消息。否则,它将 RR 个文件的名称记录在主数据结构中。

When a reduce task completes, the reduce worker atomically renames its temporary output file to the final output file. If the same reduce task is executed on multiple machines, multiple rename calls will be executed for the same final output file. We rely on the atomic rename operation provided by the underlying file system to guarantee that the final file system state contains just the data produced by one execution of the reduce task.

当一个归约任务完成时,归约工作者会自动地将其临时输出文件重命名为最终输出文件。如果在多台机器上执行同一个归约任务,对于同一个最终输出文件将执行多次重命名调用。我们依赖底层文件系统提供的原子重命名操作来确保最终文件系统状态仅包含由归约任务的一次执行所产生的数据。

The vast majority of our map and reduce operators are deterministic, and the fact that our semantics are equivalent to a sequential execution in this case makes it very easy for programmers to reason about their program’s behavior. When the map and/or reduce operators are nondeterministic, we provide weaker but still reasonable semantics. In the presence of non-deterministic operators, the output of a particular reduce task R1R_{1} is equivalent to the output for R1R_{1} produced by a sequential execution of the non-deterministic program. However, the output for a different reduce task R2R_{2} may correspond to the output for R2R_{2} produced by a different sequential execution of the non-deterministic program.

我们的绝大多数映射和归约操作符是确定性的,并且在这种情况下我们的语义等同于顺序执行这一事实使得程序员很容易推断他们程序的行为。当映射和/或归约操作符是非确定性的,我们提供较弱但仍然合理的语义。在存在非确定性操作符的情况下,特定归约任务 R1R_1 的输出等同于由非确定性程序的顺序执行产生的 R1R_1 的输出。然而,不同的归约任务 R2R_2 的输出可能对应于由非确定性程序的不同顺序执行产生的 R2R_2 的输出。

Consider map task MM and reduce tasks R1R_{1} and R2R_{2} .Let e(Ri)e(R_{i}) be the execution of RiR_{i} that committed (there is exactly one such execution). The weaker semantics arise because e(R1)e(R_{1}) may have read the output produced by one execution of MM and e(R2)e(R_{2}) may have read the output produced by a different execution of MM .

考虑映射任务 MM 以及归约任务 R1R_{1}R2R_{2} 。设 e(Ri)e(R_{i}) 是已提交的 RiR_{i} 的执行(恰好有这样一个执行)。较弱的语义出现是因为 e(R1)e(R_{1}) 可能已经读取了 MM 的一次执行所产生的输出,而 e(R2)e(R_{2}) 可能已经读取了 MM 的不同执行所产生的输出。

3.4 Locality

3.4 局部性

Network bandwidth is a relatively scarce resource in our computing environment. We conserve network bandwidth by taking advantage of the fact that the input data (managed by GFS [8]) is stored on the local disks of the machines that make up our cluster. GFS divides each file into 64MB64\,\mathrm{MB} blocks, and stores several copies of each block (typically 3 copies) on different machines. The MapReduce master takes the location information of the input files into account and attempts to schedule a map task on a machine that contains a replica of the corresponding input data. Failing that, it attempts to schedule a map task near a replica of that task’s input data (e.g., on a worker machine that is on the same network switch as the machine containing the data). When running large MapReduce operations on a significant fraction of the workers in a cluster, most input data is read locally and consumes no network bandwidth.

网络带宽在我们的计算环境中是一种相对稀缺的资源。我们通过利用输入数据(由 GFS[8] 管理)存储在构成我们集群的机器的本地磁盘上这一事实来节省网络带宽。GFS 将每个文件分成 64MB64\,\mathrm{MB} 块,并在不同机器上存储每个块的多个副本(通常为 3 个副本)。MapReduce 主节点考虑输入文件的位置信息,并尝试在包含相应输入数据副本的机器上调度一个映射任务。如果做不到这一点,它会尝试在该任务输入数据副本附近调度一个映射任务(例如,在与包含数据的机器位于同一网络交换机上的工作机器上)。当在集群中相当一部分工作者上运行大型 MapReduce 操作时,大多数输入数据是在本地读取的,不会消耗网络带宽。

3.5 Task Granularity

3.5 任务粒度

We subdivide the map phase into MM pieces and the reduce phase into RR pieces, as described above. Ideally, MM and RR should be much larger than the number of worker machines. Having each worker perform many different tasks improves dynamic load balancing, and also speeds up recovery when a worker fails: the many map tasks it has completed can be spread out across all the other worker machines.

我们将映射(map)阶段细分为 MM 个部分,将归约(reduce)阶段细分为 RR 个部分,如上文所述。理想情况下,MMRR 应该比工作机器的数量大得多。让每个工作者执行许多不同的任务可以改善动态负载均衡,并且当一个工作者出现故障时也能加快恢复:它已经完成的许多映射任务可以分布在所有其他工作机器上。

There are practical bounds on how large MM and RR can be in our implementation, since the master must make O(M+R)O(M+R) scheduling decisions and keeps O(MR)O(M*R) state in memory as described above. (The constant factors for memory usage are small however: the O(MR)O(M*R) piece of the state consists of approximately one byte of data per map task/reduce task pair.)

在我们的实现中,MMRR 能有多大存在实际的限制,因为如前所述,主节点必须做出 O(M+R)O(M+R) 个调度决策,并在内存中保留 O(MR)O(M*R) 的状态。(然而,内存使用的常量因子较小:状态的 O(MR)O(M*R) 部分大约每个映射任务/归约任务对包含一个字节的数据。)

Furthermore, RR is often constrained by users because the output of each reduce task ends up in a separate output file. In practice, we tend to choose MM so that each individual task is roughly 16MB16\,\mathrm{MB} to 64MB64\,\mathrm{MB} of input data (so that the locality optimization described above is most effective), and we make RR a small multiple of the number of worker machines we expect to use. We often perform MapReduce computations with M=200,000M=200,000 and R=5,000R=5,000 , using 2,000 worker machines.

此外,RR 通常会受到用户的限制,因为每个归约任务的输出最终会在一个单独的输出文件中。在实践中,我们倾向于选择 MM,使得每个单独的任务大约有 16MB16\,\mathrm{MB}64MB64\,\mathrm{MB} 的输入数据(以便上述的局部性优化最为有效),并且我们让 RR 是我们预期使用的工作机器数量的一个小倍数。我们经常使用 20002000 台工作机器进行 M=200000M=200000R=5000R=5000 的 MapReduce 计算。

3.6 Backup Tasks

3.6 备份任务

One of the common causes that lengthens the total time taken for a MapReduce operation is a “straggler”: a machine that takes an unusually long time to complete one of the last few map or reduce tasks in the computation. Stragglers can arise for a whole host of reasons. For example, a machine with a bad disk may experience frequent correctable errors that slow its read performance from 30 MB/s30~\mathrm{MB/s} to 1 MB/s1~\mathrm{MB/s} . The cluster scheduling system may have scheduled other tasks on the machine, causing it to execute the MapReduce code more slowly due to competition for CPU, memory, local disk, or network bandwidth. A recent problem we experienced was a bug in machine initialization code that caused processor caches to be disabled: computations on affected machines slowed down by over a factor of one hundred.

MapReduce 操作总耗时延长的常见原因之一是“落后者”:一台机器在计算中完成最后几个映射或归约任务之一时花费异常长的时间。落后者可能由于多种原因而出现。例如,一台磁盘有问题的机器可能会频繁出现可纠正的错误,使其读取性能从 3030 兆字节/秒降至 11 兆字节/秒。集群调度系统可能在该机器上调度了其他任务,由于对 CPU、内存、本地磁盘或网络带宽的竞争,导致其执行 MapReduce 代码更慢。我们最近遇到的一个问题是机器初始化代码中的一个错误,导致处理器缓存被禁用:受影响机器上的计算速度减慢了一百多倍。

We have a general mechanism to alleviate the problem of stragglers. When a MapReduce operation is close to completion, the master schedules backup executions of the remaining in-progress tasks. The task is marked as completed whenever either the primary or the backup execution completes. We have tuned this mechanism so that it typically increases the computational resources used by the operation by no more than a few percent. We have found that this significantly reduces the time to complete large MapReduce operations. As an example, the sort program described in Section 5.3 takes 44%44\% longer to complete when the backup task mechanism is disabled.

我们有一种通用机制来缓解掉队者的问题。当一个 MapReduce 操作接近完成时,主节点会安排剩余进行中任务的备份执行。只要主执行或备份执行中的任何一个完成,该任务就会被标记为已完成。我们已经对这种机制进行了调整,使其通常不会使操作使用的计算资源增加超过几个百分点。我们发现这显著减少了完成大型 MapReduce 操作的时间。例如,在第 5.3 节中描述的排序程序在禁用备份任务机制时需要多花费 44% 的时间来完成。

4 Refinements

4 项改进

Although the basic functionality provided by simply writing Map and Reduce functions is sufficient for most needs, we have found a few extensions useful. These are described in this section.

尽管仅通过编写 Map 和 Reduce 函数所提供的基本功能对于大多数需求而言已经足够,但我们发现了一些有用的扩展。本节将对这些进行描述。

4.1 Partitioning Function

4.1 划分函数

The users of MapReduce specify the number of reduce tasks/output files that they desire (R)(R) . Data gets partitioned across these tasks using a partitioning function on the intermediate key. A default partitioning function is provided that uses hashing (e.g. hash(key)\cdot h a s h(k e y) mod RR^{\bullet} ). This tends to result in fairly well-balanced partitions. In some cases, however, it is useful to partition data by some other function of the key. For example, sometimes the output keys are URLs, and we want all entries for a single host to end up in the same output file. To support situations like this, the user of the MapReduce library can provide a special partitioning function. For example, using hash(Hostname(urlkey))^{*}h a s h(H o s t n a m e(u r l k e y)) ) mod RR^{\ast} as the partitioning function causes all URLs from the same host to end up in the same output file.

MapReduce 的用户指定他们期望的归约任务/输出文件的数量 (R)(R)。数据使用中间键上的分区函数在这些任务中进行分区。提供了一个默认的分区函数,该函数使用哈希(例如 \cdot 哈希(键)模 RR^{\cdot})。这往往会导致相当均衡的分区。然而,在某些情况下,根据键的其他函数对数据进行分区是有用的。例如,有时输出键是 URL,并且我们希望单个主机的所有条目最终都在同一个输出文件中。为了支持这样的情况,MapReduce 库的用户可以提供一个特殊的分区函数。例如,使用 ^{*} 哈希(主机名(url 键)))模 RR^{\ast} 作为分区函数会导致来自同一主机的所有 URL 最终都在同一个输出文件中。

4.2 Ordering Guarantees

4.2 排序保证

我们保证在给定的分区内,中间键/值对按键递增顺序进行处理。这种排序保证使得为每个分区生成一个已排序的输出文件变得容易,这在输出文件格式需要支持按键进行高效随机访问查找时非常有用,或者当输出的用户发现数据已排序很方便时也很有用。

4.3 Combiner Function

4.3 合并器函数

In some cases, there is significant repetition in the intermediate keys produced by each map task, and the userspecified Reduce function is commutative and associative. A good example of this is the word counting example in Section 2.1. Since word frequencies tend to follow a Zipf distribution, each map task will produce hundreds or thousands of records of the form <the<\tt t h e ,>_{\perp>} . All of these counts will be sent over the network to a single reduce task and then added together by the Reduce function to produce one number. We allow the user to specify an optional Combiner function that does partial merging of this data before it is sent over the network.

在某些情况下,每个映射任务生成的中间键存在显著的重复,并且用户指定的归约函数是可交换和可结合的。这方面的一个很好的例子是 2.1 节中的单词计数示例。由于单词频率往往遵循齐普夫分布,每个映射任务将产生成百上千个形式为 <the<\tt t h e,>_{\perp>} 的记录。所有这些计数都将通过网络发送到单个归约任务,然后由归约函数相加在一起以产生一个数字。我们允许用户指定一个可选的合并器函数,在数据通过网络发送之前对其进行部分合并。

The Combiner function is executed on each machine that performs a map task. Typically the same code is used to implement both the combiner and the reduce functions. The only difference between a reduce function and a combiner function is how the MapReduce library handles the output of the function. The output of a reduce function is written to the final output file. The output of a combiner function is written to an intermediate file that will be sent to a reduce task.

合并器(Combiner)函数在执行映射(map)任务的每台机器上执行。通常,用于实现合并器和化简(reduce)函数的是相同的代码。化简函数和合并器函数之间的唯一区别在于 MapReduce 库如何处理该函数的输出。化简函数的输出被写入最终输出文件。合并器函数的输出被写入一个中间文件,该中间文件将被发送到化简任务。

Partial combining significantly speeds up certain classes of MapReduce operations. Appendix A contains an example that uses a combiner.

部分合并显著加快了某些类别的 MapReduce 操作。附录 A 包含一个使用合并器(combiner)的示例。

4.4 Input and Output Types

4.4 输入和输出类型

The MapReduce library provides support for reading input data in several different formats. For example, “text”

MapReduce 库为以几种不同格式读取输入数据提供支持。例如,“文本”

mode input treats each line as a key/value pair: the key is the offset in the file and the value is the contents of the line. Another common supported format stores a sequence of key/value pairs sorted by key. Each input type implementation knows how to split itself into meaningful ranges for processing as separate map tasks (e.g. text mode’s range splitting ensures that range splits occur only at line boundaries). Users can add support for a new input type by providing an implementation of a simple reader interface, though most users just use one of a small number of predefined input types.

模式输入将每行视为键/值对:键是文件中的偏移量,值是该行的内容。另一种常见的支持格式存储按键排序的一系列键/值对。每个输入类型实现都知道如何将自身拆分成有意义的范围,以便作为单独的映射任务进行处理(例如,文本模式的范围拆分确保范围拆分仅在行边界处发生)。用户可以通过提供一个简单读取器接口的实现来添加对新输入类型的支持,尽管大多数用户只是使用少量预定义输入类型中的一个。

A reader does not necessarily need to provide data read from a file. For example, it is easy to define a reader that reads records from a database, or from data structures mapped in memory.

一个读取器并不一定需要提供从文件读取的数据。例如,定义一个从数据库或内存中映射的数据结构读取记录的读取器是很容易的。

In a similar fashion, we support a set of output types for producing data in different formats and it is easy for user code to add support for new output types.

同样地,我们支持一组用于以不同格式生成数据的输出类型,并且用户代码很容易添加对新输出类型的支持。

4.5 Side-effects

4.5 副作用

In some cases, users of MapReduce have found it convenient to produce auxiliary files as additional outputs from their map and/or reduce operators. We rely on the application writer to make such side-effects atomic and idempotent. Typically the application writes to a temporary file and atomically renames this file once it has been fully generated.

在某些情况下,MapReduce 的用户发现从他们的映射和/或归约操作符生成辅助文件作为额外输出是很方便的。我们依靠应用程序编写者使此类副作用是原子性的和幂等的。通常,应用程序写入一个临时文件,并且一旦该文件完全生成,就原子地重命名该文件。

We do not provide support for atomic two-phase commits of multiple output files produced by a single task. Therefore, tasks that produce multiple output files with cross-file consistency requirements should be deterministic. This restriction has never been an issue in practice.

我们不提供对单个任务生成的多个输出文件的原子两阶段提交的支持。因此,生成具有跨文件一致性要求的多个输出文件的任务应该是确定性的。实际上,这种限制从未成为一个问题。

4.6 Skipping Bad Records

4.6 跳过不良记录

Sometimes there are bugs in user code that cause the Map or Reduce functions to crash deterministically on certain records. Such bugs prevent a MapReduce operation from completing. The usual course of action is to fix the bug, but sometimes this is not feasible; perhaps the bug is in a third-party library for which source code is unavailable. Also, sometimes it is acceptable to ignore a few records, for example when doing statistical analysis on a large data set. We provide an optional mode of execution where the MapReduce library detects which records cause deterministic crashes and skips these records in order to make forward progress.

有时用户代码中存在错误,会导致映射(Map)或归约(Reduce)函数在某些记录上确定性地崩溃。此类错误会阻止一个 MapReduce 操作完成。通常的行动方案是修复该错误,但有时这并不可行;也许该错误在第三方库中,而其源代码不可用。此外,有时忽略一些记录是可以接受的,例如在对大型数据集进行统计分析时。我们提供了一种可选的执行模式,其中 MapReduce 库会检测哪些记录导致确定性崩溃,并跳过这些记录以取得进展。

Each worker process installs a signal handler that catches segmentation violations and bus errors. Before invoking a user Map or Reduce operation, the MapReduce library stores the sequence number of the argument in a global variable. If the user code generates a signal, the signal handler sends a “last gasp” UDP packet that contains the sequence number to the MapReduce master. When the master has seen more than one failure on a particular record, it indicates that the record should be skipped when it issues the next re-execution of the corresponding Map or Reduce task.

每个工作进程安装一个信号处理程序,该程序捕获段错误和总线错误。在调用用户的 Map 或 Reduce 操作之前,MapReduce 库将参数的序列号存储在一个全局变量中。如果用户代码产生一个信号,信号处理程序会向 MapReduce 主节点发送一个包含该序列号的“最后一口气”UDP 数据包。当主节点在特定记录上看到不止一次失败时,它表示在发出下一次相应的 Map 或 Reduce 任务的重新执行时,该记录应被跳过。

4.7 Local Execution

4.7 本地执行

Debugging problems in Map or Reduce functions can be tricky, since the actual computation happens in a distributed system, often on several thousand machines, with work assignment decisions made dynamically by the master. To help facilitate debugging, profiling, and small-scale testing, we have developed an alternative implementation of the MapReduce library that sequentially executes all of the work for a MapReduce operation on the local machine. Controls are provided to the user so that the computation can be limited to particular map tasks. Users invoke their program with a special flag and can then easily use any debugging or testing tools they find useful (e.g. gdb).

MapReduce 函数中调试问题可能会很棘手,因为实际计算是在分布式系统中进行的,通常是在数千台机器上,工作分配决策由主节点动态做出。为了帮助促进调试、分析和小规模测试,我们开发了 MapReduce 库的另一种实现,它在本地机器上顺序执行 MapReduce 操作的所有工作。向用户提供了控制,以便可以将计算限制在特定的映射任务上。用户使用一个特殊标志调用他们的程序,然后可以轻松地使用他们觉得有用的任何调试或测试工具(例如 gdb)。

4.8 Status Information

4.8 状态信息

The master runs an internal HTTP server and exports a set of status pages for human consumption. The status pages show the progress of the computation, such as how many tasks have been completed, how many are in progress, bytes of input, bytes of intermediate data, bytes of output, processing rates, etc. The pages also contain links to the standard error and standard output files generated by each task. The user can use this data to predict how long the computation will take, and whether or not more resources should be added to the computation. These pages can also be used to figure out when the computation is much slower than expected.

主进程运行一个内部 HTTP 服务器,并导出一组状态页面供人使用。这些状态页面显示计算的进展,例如已完成多少任务,有多少任务正在进行,输入字节数,中间数据字节数,输出字节数,处理速率等。页面还包含指向每个任务生成的标准错误和标准输出文件的链接。用户可以使用此数据来预测计算将花费多长时间,以及是否应该向计算添加更多资源。这些页面还可用于确定计算何时比预期慢得多。

In addition, the top-level status page shows which workers have failed, and which map and reduce tasks they were processing when they failed. This information is useful when attempting to diagnose bugs in the user code.

此外,顶级状态页面会显示哪些工作器出现了故障,以及它们在出现故障时正在处理哪些映射和归约任务。当尝试诊断用户代码中的错误时,此信息非常有用。

4.9 Counters

4.9 计数器

The MapReduce library provides a counter facility to count occurrences of various events. For example, user code may want to count total number of words processed or the number of German documents indexed, etc.

MapReduce 库提供了一个计数器工具来计算各种事件的发生次数。例如,用户代码可能想要计算处理的单词总数或已索引的德文文档数量等等。

To use this facility, user code creates a named counter object and then increments the counter appropriately in the Map and/or Reduce function. For example:

要使用此功能,用户代码创建一个命名的计数器对象,然后在 Map 和/或 Reduce 函数中适当地递增该计数器。例如:

map(String name, String contents): for each word w in contents: if (IsCapitalized(w)): uppercase->Increment(); EmitIntermediate(w, "1");

map(字符串 name, 字符串 contents):对于 contents 中的每个单词 w:如果 (是大写的 (w)):大写 ->递增 ();发出中间结果 (w, "1");

The counter values from individual worker machines are periodically propagated to the master (piggybacked on the ping response). The master aggregates the counter values from successful map and reduce tasks and returns them to the user code when the MapReduce operation is completed. The current counter values are also displayed on the master status page so that a human can watch the progress of the live computation. When aggregating counter values, the master eliminates the effects of duplicate executions of the same map or reduce task to avoid double counting. (Duplicate executions can arise from our use of backup tasks and from re-execution of tasks due to failures.)

各个工作机器的计数器值会定期传播到主节点(搭载在 ping 响应上)。主节点汇总来自成功的映射和归约任务的计数器值,并在 MapReduce 操作完成时将其返回给用户代码。当前计数器值也会显示在主节点状态页面上,以便人类可以观察实时计算的进展。在汇总计数器值时,主节点消除同一映射或归约任务重复执行的影响,以避免重复计数。(重复执行可能源于我们对备份任务的使用以及由于故障导致的任务重新执行。)

Some counter values are automatically maintained by the MapReduce library, such as the number of input key/value pairs processed and the number of output key/value pairs produced.

一些计数器的值由 MapReduce 库自动维护,比如已处理的输入键/值对的数量以及生成的输出键/值对的数量。

Users have found the counter facility useful for sanity checking the behavior of MapReduce operations. For example, in some MapReduce operations, the user code may want to ensure that the number of output pairs produced exactly equals the number of input pairs processed, or that the fraction of German documents processed is within some tolerable fraction of the total number of documents processed.

用户发现计数器功能对于理智检查 MapReduce 操作的行为很有用。例如,在某些 MapReduce 操作中,用户代码可能想要确保生成的输出键值对的数量恰好等于处理的输入键值对的数量,或者处理的德语文档的比例在处理的文档总数的某个可容忍比例范围内。

5 Performance

5 性能

In this section we measure the performance of MapReduce on two computations running on a large cluster of machines. One computation searches through approximately one terabyte of data looking for a particular pattern. The other computation sorts approximately one terabyte of data.

在这一部分,我们在一个大型机器集群上运行的两个计算中测量 MapReduce 的性能。一个计算在大约 1 太字节的数据中搜索寻找特定模式。另一个计算对大约 1 太字节的数据进行排序。

These two programs are representative of a large subset of the real programs written by users of MapReduce – one class of programs shuffles data from one representation to another, and another class extracts a small amount of interesting data from a large data set.

这两个程序代表了 MapReduce 用户编写的实际程序的很大一部分子集——一类程序将数据从一种表示形式转换为另一种表示形式,而另一类程序从大数据集中提取少量有趣的数据。

5.1 Cluster Configuration

5.1 集群配置

All of the programs were executed on a cluster that consisted of approximately 1800 machines. Each machine had two 2GHz Intel Xeon processors with HyperThreading enabled, 4GB of memory, two 160GB IDE disks, and a gigabit Ethernet link. The machines were arranged in a two-level tree-shaped switched network with approximately 100-200 Gbps of aggregate bandwidth available at the root. All of the machines were in the same hosting facility and therefore the round-trip time between any pair of machines was less than a millisecond.

所有程序都在一个由大约 1800 台机器组成的集群上执行。每台机器都有两个启用了超线程技术的 2GHz 英特尔至强处理器、4GB 内存、两个 160GB IDE 磁盘和一个千兆以太网链路。这些机器被布置在一个两级树状交换网络中,在根节点处大约有 100-200 Gbps 的总带宽可用。所有机器都在同一个托管设施中,因此任意两台机器之间的往返时间都小于一毫秒。

Figure 2: Data transfer rate over time

Out of the 4GB of memory, approximately 1-1.5GB was reserved by other tasks running on the cluster. The programs were executed on a weekend afternoon, when the CPUs, disks, and network were mostly idle.

在 4GB 的内存中,大约 1 到 1.5GB 被在集群上运行的其他任务预留。这些程序是在一个周末下午执行的,当时中央处理器(CPU)、磁盘和网络大多处于闲置状态。

5.2 Grep

5.2 Grep

Grep(全局正则表达式打印)是一种强大的文本搜索工具,常用于在文件或输入流中查找特定的模式。

它的基本用法如下:

grep [选项] 模式 [文件列表]

以下是一些常见的选项:

  • -i:忽略大小写。
  • -v:反转匹配,即显示不匹配的行。
  • -n:显示行号。

例如,要在文件 file.txt 中查找包含单词 "hello" 的行,可以使用:

grep "hello" file.txt

要忽略大小写查找,可以添加 -i 选项:

grep -i "hello" file.txt

Grep 在处理大量文本数据时非常有用,可以快速筛选出感兴趣的内容。

The grep program scans through 101010^{10} 100-byte records, searching for a relatively rare three-character pattern (the pattern occurs in 92,337 records). The input is split into approximately 64MB pieces ( M=15000)M=15000) ), and the entire output is placed in one file (R=1)(R=1) ).

grep 程序会扫描 101010^{10} 个 100 字节的记录,搜索一个相对罕见的三字符模式(该模式出现在 92337 个记录中)。输入被分割成大约 64MB 的块(M=15000M=15000),并且整个输出被放置在一个文件中(R=1R=1)。

Figure 2 shows the progress of the computation over time. The Y-axis shows the rate at which the input data is scanned. The rate gradually picks up as more machines are assigned to this MapReduce computation, and peaks at over 30GB/s30\,\mathrm{GB}/\mathrm{s} when 1764 workers have been assigned. As the map tasks finish, the rate starts dropping and hits zero about 80 seconds into the computation. The entire computation takes approximately 150 seconds from start to finish. This includes about a minute of startup overhead. The overhead is due to the propagation of the program to all worker machines, and delays interacting with GFS to open the set of 1000 input files and to get the information needed for the locality optimization.

图 2 展示了随着时间推移计算的进展。Y 轴显示输入数据的扫描速率。随着更多机器被分配到这个 MapReduce 计算中,速率逐渐上升,当分配了 1764 个工作者时达到超过 30 吉字节/秒的峰值。随着映射任务完成,速率开始下降,并在计算进行约 80 秒时降为零。整个计算从开始到结束大约需要 150 秒。这包括大约一分钟的启动开销。该开销是由于程序传播到所有工作机器,以及与 GFS 交互以打开 1000 个输入文件集并获取本地优化所需信息的延迟造成的。

5.3 Sort

5.3 排序

The sort program sorts 101010^{10} 100-byte records (approximately 1 terabyte of data). This program is modeled after the TeraSort benchmark [10].

排序程序对 101010^{10} 个 100 字节的记录进行排序(大约 1 太字节的数据)。这个程序是仿照 TeraSort 基准测试 [10] 建模的。

The sorting program consists of less than 50 lines of user code. A three-line Map function extracts a 10-byte sorting key from a text line and emits the key and the original text line as the intermediate key/value pair. We used a built-in Identity function as the Reduce operator. This functions passes the intermediate key/value pair unchanged as the output key/value pair. The final sorted output is written to a set of 2-way replicated GFS files (i.e., 2 terabytes are written as the output of the program).

排序程序由不到 50 行用户代码组成。一个三行的 Map 函数从文本行中提取一个 10 字节的排序键,并将该键和原始文本行作为中间键/值对发出。我们使用内置的恒等函数作为 Reduce 操作符。该函数将中间键/值对原封不动地作为输出键/值对传递。最终排序后的输出被写入一组双向复制的 GFS 文件(即,作为程序的输出写入 2 太字节)。

Figure 3: Data transfer rates over time for different executions of the sort program

As before, the input data is split into 64MB pieces M=15000M=15000 ). We partition the sorted output into 4000 files [R=4000][R=4000] ). The partitioning function uses the initial bytes of the key to segregate it into one of RR pieces.

和之前一样,输入数据被分割成 64MB 的块(M=15000M=15000)。我们将排序后的输出划分到 4000 个文件中([R=4000][R=4000])。划分函数使用键的初始字节将其划分到 RR 个块中的一个。

Our partitioning function for this benchmark has builtin knowledge of the distribution of keys. In a general sorting program, we would add a pre-pass MapReduce operation that would collect a sample of the keys and use the distribution of the sampled keys to compute splitpoints for the final sorting pass.

我们用于此基准测试的分区函数具有键分布的内置知识。在一般的排序程序中,我们将添加一个预传递的 MapReduce 操作,该操作将收集键的样本,并使用采样键的分布来计算最终排序传递的分割点。

Figure 3 (a) shows the progress of a normal execution of the sort program. The top-left graph shows the rate at which input is read. The rate peaks at about 13  GB/s13\;\mathrm{GB/s} and dies off fairly quickly since all map tasks finish before 200 seconds have elapsed. Note that the input rate is less than for grep. This is because the sort map tasks spend about half their time and I/O bandwidth writing intermediate output to their local disks. The corresponding intermediate output for grep had negligible size.

图 3 (a) 展示了排序程序正常执行的进展情况。左上角的图表显示了输入读取的速率。该速率在约 13 吉字节每秒达到峰值,并且相当快地下降,因为所有映射任务在 200 秒过去之前就完成了。请注意,输入速率小于 grep 的。这是因为排序映射任务大约将其一半时间和 I/O 带宽用于将中间输出写入其本地磁盘。而 grep 对应的中间输出规模可忽略不计。

The middle-left graph shows the rate at which data is sent over the network from the map tasks to the reduce tasks. This shuffling starts as soon as the first map task completes. The first hump in the graph is for the first batch of approximately 1700 reduce tasks (the entire MapReduce was assigned about 1700 machines, and each machine executes at most one reduce task at a time). Roughly 300 seconds into the computation, some of these first batch of reduce tasks finish and we start shuffling data for the remaining reduce tasks. All of the shuffling is done about 600 seconds into the computation.

中左图表展示了数据通过网络从映射任务发送到归约任务的速率。这种混洗一旦第一个映射任务完成就开始。图表中的第一个驼峰是用于第一批大约 1700 个归约任务(整个 MapReduce 被分配给大约 1700 台机器,并且每台机器一次最多执行一个归约任务)。在计算大约 300 秒时,这些第一批归约任务中的一些完成,我们开始为剩余的归约任务混洗数据。所有的混洗在计算大约 600 秒时完成。

The bottom-left graph shows the rate at which sorted data is written to the final output files by the reduce tasks. There is a delay between the end of the first shuffling period and the start of the writing period because the machines are busy sorting the intermediate data. The writes continue at a rate of about 2-4 GB/s for a while. All of the writes finish about 850 seconds into the computation. Including startup overhead, the entire computation takes 891 seconds. This is similar to the current best reported result of 1057 seconds for the TeraSort benchmark [18].

左下角的图表展示了归约任务将已排序的数据写入最终输出文件的速率。在第一个混洗周期结束与写入周期开始之间存在一个延迟,因为机器正忙于对中间数据进行排序。写入以大约 2 到 4GB/s 的速率持续了一段时间。所有写入在计算进行到大约 850 秒时完成。包括启动开销在内,整个计算花费了 891 秒。这与当前报道的 TeraSort 基准测试的最佳结果 1057 秒相似 [18]。

A few things to note: the input rate is higher than the shuffle rate and the output rate because of our locality optimization – most data is read from a local disk and bypasses our relatively bandwidth constrained network. The shuffle rate is higher than the output rate because the output phase writes two copies of the sorted data (we make two replicas of the output for reliability and availability reasons). We write two replicas because that is the mechanism for reliability and availability provided by our underlying file system. Network bandwidth requirements for writing data would be reduced if the underlying file system used erasure coding [14] rather than replication.

一些需要注意的点:由于我们的本地性优化——大部分数据是从本地磁盘读取并绕过我们相对带宽受限的网络,所以输入速率高于混洗速率和输出速率。混洗速率高于输出速率,是因为输出阶段会写入已排序数据的两份副本(出于可靠性和可用性的原因,我们为输出制作两份副本)。我们写入两份副本,是因为这是我们底层文件系统提供的用于可靠性和可用性的机制。如果底层文件系统使用纠删码 [14] 而不是复制,那么写入数据的网络带宽需求将会降低。

5.4 Effect of Backup Tasks

5.4 备份任务的影响

In Figure 3 (b), we show an execution of the sort program with backup tasks disabled. The execution flow is similar to that shown in Figure 3 (a), except that there is a very long tail where hardly any write activity occurs. After 960 seconds, all except 5 of the reduce tasks are completed. However these last few stragglers don’t finish until 300 seconds later. The entire computation takes 1283 seconds, an increase of 44%44\% in elapsed time.

在图 3(b) 中,我们展示了禁用备份任务时排序程序的一次执行。执行流程与图 3(a) 中所示的类似,只是存在一个非常长的尾部,几乎没有任何写入活动发生。在 960 秒后,除了 5 个归约任务之外的所有任务都已完成。然而,这最后几个掉队者直到 300 秒后才完成。整个计算花费 1283 秒,经过时间增加了 44%44\%

5.5 Machine Failures

5.5 机器故障

In Figure 3 (c), we show an execution of the sort program where we intentionally killed 200 out of 1746 worker processes several minutes into the computation. The underlying cluster scheduler immediately restarted new worker processes on these machines (since only the processes were killed, the machines were still functioning properly).

在图 3(c)中,我们展示了排序程序的一次执行,在计算进行了几分钟后,我们故意在 1746 个工作进程中终止了 200 个。底层的集群调度器立即在这些机器上重新启动了新的工作进程(因为只是进程被终止了,机器仍然正常运行)。

The worker deaths show up as a negative input rate since some previously completed map work disappears (since the corresponding map workers were killed) and needs to be redone. The re-execution of this map work happens relatively quickly. The entire computation finishes in 933 seconds including startup overhead (just an increase of 5%5\% over the normal execution time).

工人死亡显示为负输入速率,因为一些先前完成的映射工作消失了(因为相应的映射工人被杀死了)并且需要重新进行。这种映射工作的重新执行相对较快。整个计算在 933 秒内完成,包括启动开销(仅比正常执行时间增加了 5%)。

6 Experience

6 经验

We wrote the first version of the MapReduce library in February of 2003, and made significant enhancements to it in August of 2003, including the locality optimization, dynamic load balancing of task execution across worker machines, etc. Since that time, we have been pleasantly surprised at how broadly applicable the MapReduce library has been for the kinds of problems we work on. It has been used across a wide range of domains within Google, including:

我们在 2003 年 2 月编写了 MapReduce 库的第一个版本,并在 2003 年 8 月对其进行了重大改进,包括局部性优化、跨工作机器的任务执行的动态负载均衡等。从那时起,我们惊喜地发现 MapReduce 库对于我们所处理的各类问题具有多么广泛的适用性。它已在谷歌内部的广泛领域得到应用,包括:

large-scale machine learning problems,

大规模机器学习问题,

clustering problems for the Google News and Froogle products,
extraction of data used to produce reports of popular queries (e.g. Google Zeitgeist),
extraction of properties of web pages for new experiments and products (e.g. extraction of geographical locations from a large corpus of web pages for localized search), and

谷歌新闻和 Froogle 产品的聚类问题, 用于生成热门查询报告(例如谷歌时代精神)的数据提取, 新实验和产品的网页属性提取(例如从大量网页语料库中提取地理位置以用于本地化搜索),以及

large-scale graph computations.

大规模图计算。

Figure 4: MapReduce instances over time

Table 1: MapReduce jobs run in August 2004 Figure 4 shows the significant growth in the number of separate MapReduce programs checked into our primary source code management system over time, from 0 in early 2003 to almost 900 separate instances as of late September 2004. MapReduce has been so successful because it makes it possible to write a simple program and run it efficiently on a thousand machines in the course of half an hour, greatly speeding up the development and prototyping cycle. Furthermore, it allows programmers who have no experience with distributed and/or parallel systems to exploit large amounts of resources easily.

表 1:2004 年 8 月运行的 MapReduce 任务 图 4 展示了随着时间推移,签入我们主要源代码管理系统的单独 MapReduce 程序数量的显著增长,从 2003 年初的 0 到 2004 年 9 月底的近 900 个单独实例。MapReduce 如此成功,是因为它使得编写一个简单程序并在半小时内在一千台机器上高效运行成为可能,大大加快了开发和原型设计周期。此外,它允许没有分布式和/或并行系统经验的程序员轻松利用大量资源。

At the end of each job, the MapReduce library logs statistics about the computational resources used by the job. In Table 1, we show some statistics for a subset of MapReduce jobs run at Google in August 2004.

在每个任务结束时,MapReduce 库会记录该任务所使用的计算资源的统计信息。在表 1 中,我们展示了 2004 年 8 月在谷歌运行的一部分 MapReduce 任务的一些统计信息。

6.1 Large-Scale Indexing

6.1 大规模索引

One of our most significant uses of MapReduce to date has been a complete rewrite of the production indexing system that produces the data structures used for the Google web search service. The indexing system takes as input a large set of documents that have been retrieved by our crawling system, stored as a set of GFS files. The raw contents for these documents are more than 20 terabytes of data. The indexing process runs as a sequence of five to ten MapReduce operations. Using MapReduce (instead of the ad-hoc distributed passes in the prior version of the indexing system) has provided several benefits:

到目前为止,我们对 MapReduce 的最重要用途之一是对生产索引系统进行了彻底重写,该系统生成用于谷歌网络搜索服务的数据结构。索引系统以我们的爬虫系统检索到的一整套文档作为输入,这些文档存储为一组 GFS 文件。这些文档的原始内容超过 20 太字节的数据。索引过程作为五到十个 MapReduce 操作的序列运行。使用 MapReduce(而不是索引系统先前版本中的特别分布式遍历)带来了几个好处:

The indexing code is simpler, smaller, and easier to understand, because the code that deals with fault tolerance, distribution and parallelization is hidden within the MapReduce library. For example, the size of one phase of the computation dropped from approximately 3800 lines of C++C++ code to approximately 700 lines when expressed using MapReduce.

索引代码更简单、更小且更易于理解,因为处理容错、分布和并行化的代码隐藏在 MapReduce 库内。例如,当使用 MapReduce 来表示时,计算的一个阶段的规模从大约 3800 行的 C++C++ 代码减少到大约 700 行。

The performance of the MapReduce library is good enough that we can keep conceptually unrelated computations separate, instead of mixing them together to avoid extra passes over the data. This makes it easy to change the indexing process. For example, one change that took a few months to make in our old indexing system took only a few days to implement in the new system.

MapReduce 库的性能足够好,以至于我们可以在概念上保持不相关的计算分开,而不是将它们混合在一起以避免对数据进行额外的遍历。这使得索引过程的更改变得容易。例如,在我们的旧索引系统中需要花费数月时间才能做出的一项更改,在新系统中仅需几天即可实施。

The indexing process has become much easier to operate, because most of the problems caused by machine failures, slow machines, and networking hiccups are dealt with automatically by the MapReduce library without operator intervention. Furthermore, it is easy to improve the performance of the indexing process by adding new machines to the indexing cluster.

索引过程变得更容易操作,因为由机器故障、机器缓慢和网络小故障引起的大多数问题都由 MapReduce 库自动处理,无需操作员干预。此外,通过向索引集群添加新机器来提高索引过程的性能是很容易的。

7 相关工作

Many systems have provided restricted programming models and used the restrictions to parallelize the computation automatically. For example, an associative function can be computed over all prefixes of an NN element array in logN\log N time on NN processors using parallel prefix computations [6, 9, 13]. MapReduce can be considered a simplification and distillation of some of these models based on our experience with large real-world computations. More significantly, we provide a fault-tolerant implementation that scales to thousands of processors. In contrast, most of the parallel processing systems have only been implemented on smaller scales and leave the details of handling machine failures to the programmer.

许多系统提供了受限的编程模型,并利用这些限制自动并行化计算。例如,使用并行前缀计算 [6, 9, 13],可以在 NN 个处理器上在 logN\log N 时间内对一个 NN 元素数组的所有前缀计算一个关联函数。根据我们在大型现实世界计算中的经验,MapReduce 可以被视为对其中一些模型的简化和提炼。更重要的是,我们提供了一种容错实现,可以扩展到数千个处理器。相比之下,大多数并行处理系统仅在较小规模上实现,并将处理机器故障的细节留给程序员。

Bulk Synchronous Programming [17] and some MPI primitives [11] provide higher-level abstractions that make it easier for programmers to write parallel programs. A key difference between these systems and MapReduce is that MapReduce exploits a restricted programming model to parallelize the user program automatically and to provide transparent fault-tolerance.

批量同步编程 [17] 和一些 MPI 原语 [11] 提供了更高级别的抽象,使程序员更容易编写并行程序。这些系统与 MapReduce 的一个关键区别在于,MapReduce 利用受限的编程模型自动并行化用户程序并提供透明的容错性。

Our locality optimization draws its inspiration from techniques such as active disks [12, 15], where computation is pushed into processing elements that are close to local disks, to reduce the amount of data sent across I/O subsystems or the network. We run on commodity processors to which a small number of disks are directly connected instead of running directly on disk controller processors, but the general approach is similar.

我们的本地性优化从诸如主动磁盘 [12, 15] 等技术中汲取灵感,在这些技术中,计算被推送到靠近本地磁盘的处理元素中,以减少通过 I/O 子系统或网络发送的数据量。我们在商品处理器上运行,少量磁盘直接连接到这些处理器,而不是直接在磁盘控制器处理器上运行,但总体方法是相似的。

Our backup task mechanism is similar to the eager scheduling mechanism employed in the Charlotte System [3]. One of the shortcomings of simple eager scheduling is that if a given task causes repeated failures, the entire computation fails to complete. We fix some instances of this problem with our mechanism for skipping bad records.

我们的备份任务机制类似于在夏洛特系统 [3] 中采用的急切调度机制。简单急切调度的一个缺点是,如果给定任务导致反复失败,整个计算就无法完成。我们通过我们的跳过不良记录机制来修复此问题的一些实例。

The MapReduce implementation relies on an in-house cluster management system that is responsible for distributing and running user tasks on a large collection of shared machines. Though not the focus of this paper, the cluster management system is similar in spirit to other systems such as Condor [16].

MapReduce 实现依赖于一个内部的集群管理系统,该系统负责在大量共享机器上分发和运行用户任务。虽然这不是本文的重点,但该集群管理系统在精神上与其他系统(如 Condor [16])相似。

The sorting facility that is a part of the MapReduce library is similar in operation to NOW-Sort [1]. Source machines (map workers) partition the data to be sorted and send it to one of RR reduce workers. Each reduce worker sorts its data locally (in memory if possible). Of course NOW-Sort does not have the user-definable Map and Reduce functions that make our library widely applicable.

MapReduce 库中的排序设施在操作上与 NOW-Sort[1] 相似。源机器(映射工作器)对要排序的数据进行划分,并将其发送给 RR 个归约工作器中的一个。每个归约工作器在本地(如果可能的话在内存中)对其数据进行排序。当然,NOW-Sort 没有使我们的库广泛适用的用户可定义的 Map 和 Reduce 函数。

River [2] provides a programming model where processes communicate with each other by sending data over distributed queues. Like MapReduce, the River system tries to provide good average case performance even in the presence of non-uniformities introduced by heterogeneous hardware or system perturbations. River achieves this by careful scheduling of disk and network transfers to achieve balanced completion times. MapReduce has a different approach. By restricting the programming model, the MapReduce framework is able to partition the problem into a large number of finegrained tasks. These tasks are dynamically scheduled on available workers so that faster workers process more tasks. The restricted programming model also allows us to schedule redundant executions of tasks near the end of the job which greatly reduces completion time in the presence of non-uniformities (such as slow or stuck workers).

River [2] 提供了一种编程模型,在该模型中,进程通过在分布式队列上发送数据来相互通信。与 MapReduce 类似,River 系统即使在异构硬件或系统扰动引入的不均匀性存在的情况下,也试图提供良好的平均情况性能。River 通过仔细安排磁盘和网络传输来实现平衡的完成时间来实现这一点。MapReduce 有不同的方法。通过限制编程模型,MapReduce 框架能够将问题分割成大量细粒度的任务。这些任务在可用的工作者上动态调度,以便更快的工作者处理更多的任务。受限制的编程模型还允许我们在作业接近尾声时调度任务的冗余执行,这在不均匀性(例如缓慢或卡住的工作者)存在的情况下大大减少了完成时间。

BAD-FS [5] has a very different programming model from MapReduce, and unlike MapReduce, is targeted to the execution of jobs across a wide-area network. However, there are two fundamental similarities. (1) Both systems use redundant execution to recover from data loss caused by failures. (2) Both use locality-aware scheduling to reduce the amount of data sent across congested network links.

BAD-FS [5] 的编程模型与 MapReduce 有很大不同,并且与 MapReduce 不同的是,它面向在广域网中执行作业。然而,有两个基本的相似之处。(1)两个系统都使用冗余执行来从故障导致的数据丢失中恢复。(2)两者都使用位置感知调度来减少通过拥塞网络链路发送的数据量。

TACC [7] is a system designed to simplify construction of highly-available networked services. Like MapReduce, it relies on re-execution as a mechanism for implementing fault-tolerance.

TACC [7] 是一个旨在简化高可用网络服务构建的系统。与 MapReduce 一样,它依赖于重新执行作为实现容错的一种机制。

8 Conclusions

8 结论

The MapReduce programming model has been successfully used at Google for many different purposes. We attribute this success to several reasons. First, the model is easy to use, even for programmers without experience with parallel and distributed systems, since it hides the details of parallelization, fault-tolerance, locality optimization, and load balancing. Second, a large variety of problems are easily expressible as MapReduce computations. For example, MapReduce is used for the generation of data for Google’s production web search service, for sorting, for data mining, for machine learning, and many other systems. Third, we have developed an implementation of MapReduce that scales to large clusters of machines comprising thousands of machines. The implementation makes efficient use of these machine resources and therefore is suitable for use on many of the large computational problems encountered at Google.

MapReduce 编程模型已在谷歌成功用于许多不同目的。我们将此成功归因于几个原因。首先,该模型易于使用,即使对于没有并行和分布式系统经验的程序员也是如此,因为它隐藏了并行化、容错、局部性优化和负载均衡的细节。其次,各种各样的问题很容易表示为 MapReduce 计算。例如,MapReduce 用于为谷歌的生产网络搜索服务生成数据、排序、数据挖掘、机器学习以及许多其他系统。第三,我们已经开发了一种 MapReduce 的实现,它可以扩展到包含数千台机器的大型机器集群。该实现有效地利用了这些机器资源,因此适用于谷歌遇到的许多大型计算问题。

We have learned several things from this work. First, restricting the programming model makes it easy to parallelize and distribute computations and to make such computations fault-tolerant. Second, network bandwidth is a scarce resource. A number of optimizations in our system are therefore targeted at reducing the amount of data sent across the network: the locality optimization allows us to read data from local disks, and writing a single copy of the intermediate data to local disk saves network bandwidth. Third, redundant execution can be used to reduce the impact of slow machines, and to handle machine failures and data loss.

我们从这项工作中学到了几件事。首先,限制编程模型使得并行化和分布计算变得容易,并且使此类计算具有容错性。其次,网络带宽是一种稀缺资源。因此,我们系统中的许多优化都旨在减少通过网络发送的数据量:本地性优化允许我们从本地磁盘读取数据,将中间数据的单一副本写入本地磁盘可节省网络带宽。第三,冗余执行可用于减少慢机器的影响,并处理机器故障和数据丢失。

Acknowledgements

鸣谢

Josh Levenberg has been instrumental in revising and extending the user-level MapReduce API with a number of new features based on his experience with using MapReduce and other people’s suggestions for enhancements. MapReduce reads its input from and writes its output to the Google File System [8]. We would like to thank Mohit Aron, Howard Gobioff, Markus Gutschke, David Kramer, Shun-Tak Leung, and Josh Redstone for their work in developing GFS. We would also like to thank Percy Liang and Olcan Sercinoglu for their work in developing the cluster management system used by MapReduce. Mike Burrows, Wilson Hsieh, Josh Levenberg, Sharon Perl, Rob Pike, and Debby Wallach provided helpful comments on earlier drafts of this paper. The anonymous OSDI reviewers, and our shepherd, Eric Brewer, provided many useful suggestions of areas where the paper could be improved. Finally, we thank all the users of MapReduce within Google’s engineering organization for providing helpful feedback, suggestions, and bug reports.

乔什·莱文伯格(Josh Levenberg)根据他使用 MapReduce 的经验以及其他人提出的改进建议,在修订和扩展用户级 MapReduce API 方面发挥了重要作用,并添加了许多新功能。MapReduce 从谷歌文件系统 [8] 读取输入并将其输出写入该系统。我们要感谢莫希特·阿隆(Mohit Aron)、霍华德·戈比奥夫(Howard Gobioff)、马库斯·古施克(Markus Gutschke)、大卫·克莱默(David Kramer)、梁信德(Shun-Tak Leung)和乔什·雷德斯通(Josh Redstone)在开发 GFS 方面所做的工作。我们还要感谢珀西·梁(Percy Liang)和奥尔坎·塞尔西诺格鲁(Olcan Sercinoglu)在开发 MapReduce 使用的集群管理系统方面所做的工作。迈克·伯罗斯(Mike Burrows)、威尔逊·谢(Wilson Hsieh)、乔什·莱文伯格、沙龙·佩尔(Sharon Perl)、罗布·派克(Rob Pike)和黛比·沃勒克(Debby Wallach)对本文的早期草稿提供了有用的评论。匿名的 OSDI 评审人员以及我们的指导者埃里克·布鲁尔(Eric Brewer)就本文可以改进的方面提供了许多有用的建议。最后,我们感谢谷歌工程组织内所有 MapReduce 的用户提供了有用的反馈、建议和错误报告。

References

参考文献

[1] Andrea C. Arpaci-Dusseau, Remzi H. Arpaci-Dusseau, David E. Culler, Joseph M. Hellerstein, and David A. Patterson. High-performance sorting on networks of workstations. In Proceedings of the 1997 ACM SIGMOD International Conference on Management of Data, Tucson, Arizona, May 1997.
[2] Remzi H. Arpaci-Dusseau, Eric Anderson, Noah Treuhaft, David E. Culler, Joseph M. Hellerstein, David Patterson, and Kathy Yelick. Cluster I/O with River: Making the fast case common. In Proceedings of the Sixth Workshop on Input/Output in Parallel and Distributed Systems (IOPADS ’99), pages 10–22, Atlanta, Georgia, May 1999.
[3] Arash Baratloo, Mehmet Karaul, Zvi Kedem, and Peter Wyckoff. Charlotte: Metacomputing on the web. In Proceedings of the 9th International Conference on Parallel and Distributed Computing Systems, 1996.
[4] Luiz A. Barroso, Jeffrey Dean, and Urs H¨olzle. Web search for a planet: The Google cluster architecture. IEEE Micro, 23(2):22–28, April 2003.
[5] John Bent, Douglas Thain, Andrea C.Arpaci-Dusseau, Remzi H. Arpaci-Dusseau, and Miron Livny. Explicit control in a batch-aware distributed file system. In Proceedings of the 1st USENIX Symposium on Networked Systems Design and Implementation NSDI, March 2004.
[6] Guy E. Blelloch. Scans as primitive parallel operations. IEEE Transactions on Computers, C-38(11), November 1989.
[7] Armando Fox, Steven D. Gribble, Yatin Chawathe, Eric A. Brewer, and Paul Gauthier. Cluster-based scalable network services. In Proceedings of the 16th ACM Symposium on Operating System Principles, pages 78– 91, Saint-Malo, France, 1997.
[8] Sanjay Ghemawat, Howard Gobioff, and Shun-Tak Leung. The Google file system. In 19th Symposium on Operating Systems Principles, pages 29–43, Lake George, New York, 2003. [9] S. Gorlatch. Systematic efficient parallelization of scan and other list homomorphisms. In L. Bouge, P. Fraigniaud, A. Mignotte, and Y. Robert, editors, Euro-Par’96. Parallel Processing, Lecture Notes in Computer Science 1124, pages 401–408. Springer-Verlag, 1996.
[10] Jim Gray. Sort benchmark home page. http://research.microsoft.com/barc/SortBenchmark/.
[11] William Gropp, Ewing Lusk, and Anthony Skjellum. Using MPI: Portable Parallel Programming with the Message-Passing Interface. MIT Press, Cambridge, MA, 1999.
[12] L. Huston, R. Sukthankar, R. Wickremesinghe, M. Satyanarayanan, G. R. Ganger, E. Riedel, and A. Ailamaki. Diamond: A storage architecture for early discard in interactive search. In Proceedings of the 2004 USENIX File and Storage Technologies FAST Conference, April 2004.
[13] Richard E. Ladner and Michael J. Fischer. Parallel prefix computation. Journal of the ACM, 27(4):831–838, 1980.
[14] Michael O. Rabin. Efficient dispersal of information for security, load balancing and fault tolerance. Journal of the ACM, 36(2):335–348, 1989.
[15] Erik Riedel, Christos Faloutsos, Garth A. Gibson, and David Nagle. Active disks for large-scale data processing. IEEE Computer, pages 68–74, June 2001.
[16] Douglas Thain, Todd Tannenbaum, and Miron Livny. Distributed computing in practice: The Condor experience. Concurrency and Computation: Practice and Experience, 2004.
[17] L. G. Valiant. A bridging model for parallel computation. Communications of the ACM, 33(8):103–111, 1997.
[18] Jim Wyllie. Spsort: How to sort a terabyte quickly. http://alme1.almaden.ibm.com/cs/spsort.pdf.

[1] 安德烈亚·C·阿帕奇 - 杜塞奥(Andrea C. Arpaci-Dusseau)、雷姆齐·H·阿帕奇 - 杜塞奥(Remzi H. Arpaci-Dusseau)、戴维·E·卡勒(David E. Culler)、约瑟夫·M·赫勒斯坦(Joseph M. Hellerstein)和戴维·A·帕特森(David A. Patterson)。在工作站网络上的高性能排序。在 1997 年美国计算机协会数据管理国际会议的会议记录中,亚利桑那州图森,1997 年 5 月。 [2] 雷姆齐·H·阿帕奇 - 杜塞奥、埃里克·安德森(Eric Anderson)、诺亚·特鲁哈夫特(Noah Treuhaft)、戴维·E·卡勒、约瑟夫·M·赫勒斯坦、戴维·帕特森和凯西·耶利克(Kathy Yelick)。使用 River 的集群 I/O:使快速情况常见。在第六届并行和分布式系统输入/输出研讨会(IOPADS '99)的会议记录中,第 10-22 页,佐治亚州亚特兰大,1999 年 5 月。 [3] 阿拉什·巴拉特卢(Arash Baratloo)、梅赫梅特·卡拉乌尔(Mehmet Karaul)、兹维·凯德姆(Zvi Kedem)和彼得·威科夫(Peter Wyckoff)。夏洛特:网络上的元计算。在第 9 届国际并行和分布式计算系统会议的会议记录中,1996 年。 [4] 路易斯·A·巴罗索(Luiz A. Barroso)、杰弗里·迪恩(Jeffrey Dean)和乌尔斯·霍尔兹勒(Urs Hölzle)。网络搜索一个星球:谷歌集群架构。《IEEE 微型》,23(2):22-28,2003 年 4 月。 [5] 约翰·本特(John Bent)、道格拉斯·塞恩(Douglas Thain)、安德烈亚·C·阿帕奇 - 杜塞奥、雷姆齐·H·阿帕奇 - 杜塞奥和米罗恩·利夫尼(Miron Livny)。在一个批处理感知分布式文件系统中的显式控制。在第一届 USENIX 网络系统设计与实现研讨会 NSDI 的会议记录中,2004 年 3 月。 [6] 盖伊·E·布莱洛克(Guy E. Blelloch)。扫描作为原始并行操作。《IEEE 计算机学报》,C-38(11),1989 年 11 月。 [7] 阿曼多·福克斯(Armando Fox)、史蒂文·D·格里布尔(Steven D. Gribble)、亚廷·查瓦特(Yatin Chawathe)、埃里克·A·布鲁尔(Eric A. Brewer)和保罗·高蒂尔(Paul Gauthier)。基于集群的可扩展网络服务。在第 16 届 ACM 操作系统原理研讨会的会议记录中,第 78-91 页,法国圣马洛,1997 年。 [8] 桑贾伊·格马瓦特(Sanjay Ghemawat)、霍华德·戈比奥夫(Howard Gobioff)和孙塔克·梁(Shun-Tak Leung)。谷歌文件系统。在第 19 届操作系统原理研讨会的会议记录中,第 29-43 页,纽约州乔治湖,2003 年。 [9] S. 戈尔拉奇(S. Gorlatch)。扫描和其他列表同态的系统高效并行化。在 L. 布热(L. Bouge)、P. 弗雷尼亚(P. Fraigniaud)、A. 米尼奥特(A. Mignotte)和 Y. 罗伯特(Y. Robert)编辑的《欧洲 -Par'96. 并行处理》中,《计算机科学讲义》1124 卷,第 401-408 页。施普林格出版社,1996 年。 [10] 吉姆·格雷(Jim Gray)。排序基准主页。http://research.microsoft.com/barc/SortBenchmark/。 [11] 威廉·格罗普(William Gropp)、尤因·拉斯克(Ewing Lusk)和安东尼·斯基尔姆(Anthony Skjellum)。使用 MPI:使用消息传递接口的可移植并行编程。麻省理工学院出版社,马萨诸塞州剑桥,1999 年。 [12] L. 休斯顿(L. Huston)、R. 苏克坦卡尔(R. Sukthankar)、R. 威克雷梅辛赫(R. Wickremesinghe)、M. 萨蒂亚纳拉扬(M. Satyanarayanan)、G. R. 甘杰(G. R. Ganger)、E. 里德尔(E. Riedel)和 A. 艾拉马基(A. Ailamaki)。钻石:交互式搜索中早期丢弃的存储架构。在 2004 年 USENIX 文件和存储技术快速会议的会议记录中,2004 年 4 月。 [13] 理查德·E·拉德纳(Richard E. Ladner)和迈克尔·J·菲舍尔(Michael J. Fischer)。并行前缀计算。《美国计算机协会杂志》,27(4):831-838,1980 年。 [14] 迈克尔·O·拉宾(Michael O. Rabin)。高效信息分散用于安全、负载均衡和容错。《美国计算机协会杂志》,36(2):335-348,1989 年。 [15] 埃里克·里德尔(Erik Riedel)、克里斯托斯·法鲁索斯(Christos Faloutsos)、加思·A·吉布森(Garth A. Gibson)和大卫·内格尔(David Nagle)。用于大规模数据处理的主动磁盘。《IEEE 计算机》,第 68-74 页,2001 年 6 月。 [16] 道格拉斯·塞恩(Douglas Thain)、托德·坦嫩鲍姆(Todd Tannenbaum)和米罗恩·利夫尼(Miron Livny)。实践中的分布式计算:康多经验。《并发与计算:实践与经验》,2004 年。 [17] L. G. 瓦利安特(L. G. Valiant)。一种并行计算的桥接模型。《美国计算机协会通讯》,33(8):103-111,1997 年。 [18] 吉姆·怀利(Jim Wyllie)。Spsort:如何快速排序 1 太字节。http://alme1.almaden.ibm.com/cs/spsort.pdf。

A Word Frequency

一个词频

This section contains a program that counts the number of occurrences of each unique word in a set of input files specified on the command line.

此部分包含一个程序,该程序对在命令行上指定的一组输入文件中每个独特单词的出现次数进行计数。

#include "mapreduce/mapreduce.h"

// 用户的映射函数
class WordCounter : public Mapper {
public:
    virtual void Map(const MapInput& input) {
        const string& text = input.value();
        const int n = text.size();
        
        for (int i = 0; i < n;) {
            // 跳过前导空白
            while (i < n && isspace(text[i])) {
                i++;
            }
            
            // 找到单词结尾
            int start = i;
            while (i < n && !isspace(text[i])) {
                i++;
            }
            
            if (start < i) {
                Emit(text.substr(start, i-start), "1");
            }
        }
    }
};

REGISTER_MAPPER(WordCounter);

// 用户的归约函数
class Adder : public Reducer {
    virtual void Reduce(ReduceInput* input) {
        // 遍历所有具有相同键的条目并加和值
        int64 value = 0;
        while (!input->done()) {
            value += StringToInt(input->value());
            input->NextValue();
        }
        
        // 为 input->key() 发出总和
        Emit(IntToString(value));
    }
};

REGISTER_REDUCER(Adder);

int main(int argc, char** argv) {
    ParseCommandLineFlags(argc, argv);
    MapReduceSpecification spec;
    
    // 将输入文件列表存储到 "spec" 中
    for (int i = 1; i < argc; i++) {
        MapReduceInput* input = spec.add_input();
        input->set_format("text");
        input->set_filepattern(argv[i]);
        input->set_mapper_class("WordCounter");
    }
    
    // 指定输出文件:
    // /gfs/test/freq-00000-of-00100
    // /gfs/test/freq-00001-of-00100
    MapReduceOutput* out = spec.output();
    out->set_filebase("/gfs/test/freq");
    out->set_num_tasks(100);
    out->set_format("text");
    out->set_reducer_class("Adder");
    
    // 可选:在映射任务内进行部分求和以节省网络带宽
    out->set_combiner_class("Adder");
    
    // 调优参数:最多使用 2000 台机器,每个任务使用 100MB 内存
    spec.set_machines(2000);
    spec.set_map_megabytes(100);
    spec.set_reduce_megabytes(100);
    
    // 现在运行它
    MapReduceResult result;
    if (!MapReduce(spec, &result)) abort();
    
    // 完成:'result' 结构包含有关计数器、
    // 所用时间、使用的机器数量等信息
    return 0;
}