1. 程式人生 > 其它 >MapReduce經典論文翻譯(中英對照)

MapReduce經典論文翻譯(中英對照)

MapReduce: Simplified Data Processing on Large Clusters(MapReduce: 簡化大型叢集下的資料處理)

轉:谷歌MapReduce經典論文翻譯(中英對照) - 小熊餐館 - 部落格園 (cnblogs.com)

作者:Jeffrey Dean and Sanjay Ghemawat

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是一個關於實施大型資料集處理和生成的程式設計模型。
使用者指定一個用於處理k/v對並生成中間態k/v對集合的對映(map)函式,以及一個用於合併所有具有相同中間態key的中間態value值的歸約(reduce)函式。
正如本篇論文所展示的那樣,很多現實世界中的任務都可以通過該模型(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.

 

以這種函式式風格編寫的程式可以在一個大型的商品級(譯者小熊餐館注:意思是很廉價、效能也很一般的意思,下同)機器叢集中自動、並行的執行。
該系統在執行時會關注如下細節:輸入資料的分割,在一系列機器間跨機器的排程程式的執行,機器故障的處理以及管理叢集內機器間的必要通訊。
這(使用MapReduce)使得沒有任何平行計算、分散式系統經驗的程式設計師們都可以輕鬆利用大型分散式系統中的資源。

 

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計算可以在數千臺機器上處理TB級別的資料。
程式設計師們發現系統很容易使用:已經有數以百計的MapReduce程式被實現,並且每天都有一千以上的MapReduce任務執行在谷歌的(計算機)叢集中。

1 Introduction(介紹)

 

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.

 

在過去的五年時間裡,包括作者在內的許多谷歌工作人員實現了數以百計的、用於特殊目的的計算程式來處理大量的原始資料,例如爬蟲獲取到的文件、網路請求日誌等等。
其目的是為了計算出各種型別的衍生資料,例如倒排索引、多種關於web文件的圖結構表示、被每個主機所爬取的頁面數摘要、給定的某天中被最頻繁查詢的集合等等。
大多數這樣的計算在概念上都很簡單,然而輸入的資料卻通常是巨大的。而且為了能在一個合理的時間範圍內完成,計算操作需要被分配到數百甚至數千臺機器上執行。
關於如何平行計算,如何分派資料以及如何處理故障等問題被混雜在了一起,使得原本簡單的計算邏輯被用於處理這些問題的大量複雜程式碼所模糊。

 

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 user specified 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原語。
我們意識到我們的絕大多數計算都涉及到為每一個輸入的邏輯記錄應用(applying)一個map對映操作,目的是對輸入集計算從而將其轉化為一箇中間態的k/v對集合;
然後為了恰當地合併衍生資料,再對所有擁有相同key值的k/v對中的value值應用一個reduce規約操作。
通過一個由使用者指定具體邏輯的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.

 

這項工作的主要貢獻在於提供了一個簡單且強大的介面,該介面能夠使大規模計算自動地並行化和分散式的執行。
結合該介面的實現,得以在大型的商品級PC叢集中獲得很高的效能。

 

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.

 

第二章介紹了基本的程式設計模型並給出了幾個示例。
第三章介紹了一個針對叢集計算環境的MapReduce介面實現。
第四章介紹了幾個我們發現的,關於該程式設計模型的有效改進。
第五章則是關於我們對各種任務所實施的效能測試。
第六章探討了MapReduce在谷歌內部的應用,其中包括了我們以MapReduce為基礎去重建索引生成系統的經驗。
第七章討論了一些相關的話題以及日後要做的工作。

2 Programming Model(程式設計模型)

 

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.

 

這一計算獲得並輸入一個k/v鍵值對集合,然後生成並輸出一個k/v鍵值對集合。
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 I
and passes them to the Reduce function.

 

Map函式是由使用者編寫的,其獲得一個輸入的k/v對並生成一箇中間態的k/v對。
MapReduce庫對所有的k/v對進行分組,使得所有有著相同中間態key值的k/v對的value值組合在一起,然後將它們傳遞給Reduce函式。

 

The Reduce function, also written by the user, accepts an intermediate key I 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函式也是由使用者編寫的,其接收一箇中間態的key值和與該鍵對應的一組value值的集合。
它會將這些value值進行統一的合併以形成一個可能更小的value值集合。
通常,每次reduce呼叫只會生成零個或一個輸出值。這個中間態的value集合通過一個迭代器提供給使用者的reduce函式。
這允許我們得以處理那些無法被完整放入記憶體的,過大的列表集合。

2.1 Example(示例)

 

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 specification object.
The user’s code is linked together with the MapReduce library (implemented in C++).
Appendix A contains the full program text for this example.

 

此外,使用者編寫程式碼以指定的輸入、輸出檔案的名字和可選的調優引數來填充一個規範的mapreduce物件。
使用者隨後呼叫MapReduce函式,傳遞這個符合規範的物件。使用者的程式碼與MapReduce庫(c++實現)進行連結。
附錄A包含了本示例的完整程式文字。

2.2 Types(型別)

 

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函式在型別上是有關聯的:

map (k1,v1) --> list(k2,v2)
reduce (k2,list(v2)) --> list (v2)
 

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.

 

舉個例子,輸入的key和value和輸出的key和value分屬不同的域。
此外,中間態的key和value和輸出的key和value則屬於相同的域。

 

Our 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++的實現中傳遞字串,以作為使用者自定義函式的輸入和輸出,並將字串(型別)與合適的型別間進行轉化的邏輯留給使用者程式碼實現。

2.3 More Examples(更多的例子)

 

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:
map函式如果匹配某個給定規則則輸出對應的那一行。
reduce函式是一個恆等函式,其只是將所輸入的中間資料原封不動的複製到輸出(譯者小熊餐館注:恆等函式:f(x) = x, 即輸入=輸出)。

 

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

 

URL訪問頻率計數:
map函式處理網頁請求的處理日誌,並且輸出<URL,1>的鍵值對。
reduce函式累加所有具有相同URL鍵值對的value值,並且輸出一個<URL,總訪問數>的鍵值對。

 

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))

 

反向web連結圖:
map函式從每一個源頁面(source)中找出每一個目標頁URL(target)的連結,輸出(target,source)格式的kv對。
reduce函式將所有具有相同target目標頁的所有源頁面(source)結合在一起組成一個列表,輸出這樣一個kv對(target,list(source))。

 

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,>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.

 

每臺主機的檢索詞向量:
彙總從一個或一系列文件中出現的最重要的單詞作為檢索詞向量(term-vector),生成以<word(單詞),frequency(出現頻次)>格式的kv對列表。
map函式針對每一個輸入的文件,輸出一個<hostname(主機名),term vector(檢索詞向量)>的kv對(主機名是從文件的URL中提取出來的)。
reduce函式接收一個給定host下基於每個文件的所有term-vectors(檢索詞向量)。
將這些檢索詞向量進行累加,拋棄掉一些出現頻率較低的檢索詞項然後返回最終的<hostname(主機名),term vector(檢索詞向量)>的kv對。

 

Inverted Index: The map function parses each document, and emits a sequence of <word,document ID>pairs.
The reduce function accepts all pairs for a given word, sorts the corresponding document IDs and emits a <word,list(document ID)> 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.

 

倒排索引:
map函式解析每一個文件,然後輸出一連串<word(單詞),documentID(文件ID)>格式的kv對。
reduce函式接收一個給定單詞對應的所有kv對,針對文件ID進行排序然後返回一個<word(單詞),_list_documentID(文件ID列表)>格式的kv對。
所有輸出的kv對集合構成了一個簡單的倒排索引。基於此,我們能簡單的增加記錄每一個單詞(在這些文件中)的位置的計算功能。

 

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.

 

分散式排序:
map函式提取每一個記錄中的key值,然後返回一個<key,record>格式的kv對。
reduce函式對所有的kv對不做修改直接返回。
該計算依賴於後續4.1章節中所述的分割槽機制和4.2章節中所述的有序性機制。

3 Implementation(實現)

 

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.
In our environment:
(1) Machines are typically dual-processor x86 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 over-all 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 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.

 

本章介紹的一個(MapReduce)實現是針對谷歌內部廣泛使用的計算環境的:通過交換式乙太網互相連線起來的大型商品級PC叢集。
在我們的環境中:
(1) 機器通常是有著x86架構的雙處理器的、執行linux作業系統的平臺,每臺機器有2-4GB的記憶體。
(2) 使用商品級的網路硬體 - 通常每臺機器的頻寬為100M/s或者1GB/s,但其平均(實際使用的)頻寬遠小於整個網路頻寬的一半。
(3) 整個叢集是由幾百或幾千臺機器所組成的,因此機器故障是頻繁出現的。
(4) 儲存是由直接連線到獨立機器上的IDE硬碟提供的。儲存在這些磁碟上的資料由一個內部自研的分散式檔案系統來管理。這一檔案系統採用複製機制,旨在不可靠的硬體之上實現可用性和可靠性。
(5) 使用者提交作業(job)給一個排程系統。每個作業都由一系列的任務(task)組成,任務被排程器對映到內部叢集中的一組可用機器上去執行。

3.1 Execution Overview(執行概述)

 

The Map invocations are distributed across multiple machines by automatically partitioning the input data into a set of M splits.
The input splits can be processed in parallel by different machines.
Reduce invocations are distributed by partitioning the intermediate key space into R pieces using a partitioning function (e.g., hash(key) mod R).
The number of partitions (R) and the partitioning function are specified by the user.

 

通過將輸入的資料自動分割為M份,map呼叫得以分佈在多個機器上呼叫執行。拆分後的輸入資料可以被不同的機器並行的處理。
通過一個分割槽函式將中間態的key值空間劃分為R份(例如: hash(key) mod R, 對key做hash後再對R求模),Reduce呼叫也得以分散式的執行。
分割槽的個數(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. The MapReduce library in the user program first splits the input files into M 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. One of the copies of the program is special – the master. The rest are workers that are assigned work by the master.
    There are M map tasks and R reduce tasks to assign. The master picks idle workers and assigns each one a map task or a reduce task.

  3. 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.

  4. Periodically, the buffered pairs are written to local disk, partitioned into R 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.

  5. 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.

  6. 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.

  7. 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.

 

圖1展示了我們所實現的MapReduce操作的總體流程。當用戶程式呼叫MapReduce函式時,會發生以下的一系列動作(圖1中的數字標號與以下列表中的數字是對應的):

  1. 內嵌於使用者程式中的MapReduce庫首先會將輸入的檔案拆分為M份,每份大小通常為16MB至64MB(具體的大小可以由使用者通過可選引數來控制)。
    然後便在叢集中的一組機器上啟動多個程式的副本。

  2. 其中一個程式的副本是特殊的-即master。剩下的程式副本都是worker, worker由master來分配任務。
    這裡有M個map任務和R個reduce任務需要分配。master選擇空閒的worker,並且為每一個被選中的worker分配一個map任務或一個reduce任務。

  3. 一個被分配了map任務的worker,讀取被拆分後的對應輸入內容。
    從輸入的資料中解析出key/value鍵值對,並將每一個kv對作為引數傳遞給使用者自定義的map函式。
    map函式產生的中間態key/value鍵值對會被快取在記憶體之中。

  4. 快取在記憶體中的kv對會被週期性地寫入通過分割槽函式所劃分出的R個磁碟區域內。
    這些在本地磁碟上被緩衝的kv對的位置將會被回傳給master,master負責將這些位置資訊轉發給後續執行reduce任務的worker。

  5. 當一個負責reduce任務的worker被master通知了這些位置資訊(map任務生成的中間態kv對資料所在的磁碟資訊),
    該worker通過遠過程呼叫(RPC)從負責map任務的worker機器的本地磁碟中讀取被快取的資料。
    當一個負責reduce任務的worker已經讀取了所有的中間態資料,將根據中間態kv對的key值進行排序,因此所有擁有相同key值的kv對將會被分組在一起。
    需要排序的原因是因為通常很多不同的key(的kv對集合)會被對映到同一個reduce任務中去。如果(需要排序的)中間態的資料量過大,無法完全裝進記憶體時,將會使用外排序。

  6. 負責reduce任務的worker迭代所有被排好序的中間態資料,並將所遇到的每一個唯一的key值和其對應的中間態value值集合傳遞給使用者自定義的reduce函式。
    reduce函式所產生的輸出將會追加在一個該reduce分割槽內的、最終的輸出檔案內。

  7. 當所有的map任務和reduce任務都完成後,master將喚醒使用者程式。此時,呼叫MapReduce的使用者程式(的執行流)將會返回到使用者程式碼中。

 

After successful completion, the output of the mapreduce execution is available in the R output files
(one per reduce task, with file names as specified by the user).
Typically, users do not need to combine these R 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執行的輸出結果將被存放在R個輸出檔案中(每一個reduce任務都對應一個輸出檔案,輸出檔案的名字由使用者指定)。
通常,使用者無需將這R個輸出檔案合併為一個檔案 - 他們通常傳遞這些檔案,將其作為另一個MapReduce呼叫的輸入,或者由另一個能處理多個被分割的輸入檔案的分散式應用所使用。

3.2 Master Data Structures(Master資料結構)

 

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).

 

master中維護了一些資料結構。對於每一個map和reduce任務,master儲存了對應的任務狀態(閒置的,執行中,或者已完成),以及worker機器的id(針對非空閒的任務)。

 

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 R 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是一個管道,將中間態檔案的位置資訊從map任務傳遞給reduce任務。
因此,對於每個已完成的map任務,master儲存了由map任務生成的R箇中間態檔案區域的位置和大小。
當map任務完成時,master將更新接受到的(中間態檔案區域)位置和大小資訊。
這些資訊的變更會以增量的方式推送給執行中的reduce任務。

3.3 Fault Tolerance(容錯)

 

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故障)
 

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.

 

master會週期性的ping每一個worker。
如果在一定的時間內沒有接收到來自某一worker的響應,master將會將worker標記為有故障(failed)。
所有由該worker完成的map任務將會被重置回初始狀態,因此這些map任務能被其它worker去排程執行。
類似的,任何在這個有故障的worker上處理中的map或reduce任務狀態也將被重置為初始化,並且(這些被重置的任務)能夠被重新排程執行。

 

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任務在故障時需要被重複執行的原因在於map任務的輸出是被儲存在故障機器的本地磁碟上的,因此無法被訪問到(宕機或者網路不通等情況)。
而已完成的reduce任務不需要重複執行的原因在於其輸出是被儲存在全域性的檔案系統中的。

 

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

 

當一個map任務在worker A上被首次執行,不久後又被worker B執行(因為worker A發生了故障),所有執行reduce任務的worker將會被通知需要重新執行。
所有還沒有從worker A處讀取(完整)資料的reduce任務將改為從worker B處讀取資料。

 

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能從大範圍的worker故障中迅速的恢復。
例如,在一個MapReduce操作執行期間內,一個正在執行的叢集上的一次網路維護導致了80臺機器在幾分鐘內無法訪問的。
MapReduce的master只需要將這些無法訪問的機器上的任務重新的執行,然後繼續向前推進,最終完成這個MapReduce操作。

Master Failure(Master故障)

 

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.

 

可以簡單的讓master週期性的將上述的master資料結構以檢查點的形式持久化。
如果master任務機器宕機了,一個新的master備份機器將會從最新的檢查點狀態處啟動。
然而,考慮到只有一臺master機器,是不太可能出現故障的;因此如果master故障了,我們當前的實現會中止MapReduce計算。
客戶端可以檢查master的這些狀態,並根據需要重試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 R 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 R 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 R files in a master data structure.

 

我們依賴map和reduce任務輸出結果的原子性提交機制來實現這一特性。
每一個處理中的任務將它們的輸出寫入其(任務)私有的臨時檔案中。
一個reduce任務產生一個這樣的檔案,同時一個map任務產生R個這樣的檔案(共R個檔案,R個reduce任務每個各對應一個檔案)。
當一個map任務完成後,對應worker會發送給master一個訊息,訊息內包含了這R個臨時檔名字的。
如果master接受到一個(已被標記為)已完成狀態任務的完成訊息時,其會忽略該訊息。
否則,將這R個檔案的名字記錄到master(維護)的資料結構中。

 

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.

 

當一個reduce任務完成了,執行reduce任務的worker會原子性的將臨時的輸出檔案重新命名為最終的輸出檔案。
如果在多臺機器上有相同的reduce任務被執行,在同一個最終輸出檔案上將會被執行多次重新命名呼叫。
我們依賴底層檔案系統所提供的原子性重新命名操作來保證最終檔案系統中恰好只儲存了一次reduce任務執行的資料。

 

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 non-deterministic, we provide weaker but still reasonable semantics.

In the presence of non-deterministic operators, the output of a particular reduce task R1 is equivalent to the output
for R1 produced by a sequential execution of the non-deterministic program.
However, the output for a different reduce task R2 may correspond to the output for R2 produced
by a different sequential execution of the non-deterministic program.

 

我們絕大多數的map和reduce運算元都是確定性的(即:輸出完全由輸入決定,同樣地輸入一定有著同樣地輸出),
在這種情況下我們(分散式架構下並行執行)的語義等價於(單機單執行緒)順序序列執行,這一事實使得程式設計師很容易理解他們程式的行為。
當map或reduce運算元是非確定性的,我們提供了一個稍弱但依然合理的語義。
存在非確定性運算元的情況下,一個特定reduce任務R1的輸出等同於R1在非確定性程式下(單機單執行緒)順序序列執行的輸出。
然而,另一個與R1不同的reduce任務R2的輸出將會對應於R2在一個不同的非確定程式中以順序序列執行的輸出。

 

Consider map task M and reduce tasks R1 and R2 .
Let e(Ri) be the execution of Ri that committed (there is exactly one such execution).
The weaker semantics arise because e(R1) may have read the output produced by one execution of M
and e(R2) may have read the output produced by a different execution of M.

 

考慮下目前有一個map任務M和兩個reduce任務R1和R2。
假設e(Ri)代表Ri任務已經被提交的一次執行(恰好只執行一次)。
由於e(R1)可能在一次執行中讀取M任務產生的輸出,同時e(R2)可能會在另一次執行中讀取M任務產生的輸出,此時將會出現弱語義。

 

針對MapReduce強語義、弱語義概念譯者自己的理解

3.4 Locality(區域性性)

 

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) is stored on the local disks of the machines that make up our cluster.
GFS divides each file into 64 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管理)被儲存在組成我們叢集的機器的本地磁碟上這一事實來節約網路頻寬。
GFS將每個檔案分割為64MB的塊,同時為每一個塊儲存幾個備份(通常是3個副本)在不同的機器上。
MapReduce的master排程map任務時將輸入檔案的位置資訊考慮在內,儘量在包含對應輸入資料副本的機器上排程執行一個map任務。
如果任務失敗了,排程map任務時會讓執行任務的機器儘量靠近任務所需輸入資料所在的機器(舉個例子,被選中的worker機器與包含資料的機器位於同一網路交換機下)。
當叢集中的相當一部分worker都在執行大型MapReduce操作時,絕大多數的輸入資料都在本地讀取從而不會消耗網路頻寬。

3.5 Task Granularity(任務粒度)

 

We subdivide the map phase into M pieces and the reduce phase into R pieces, as described above.
Ideally,M and R 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階段的任務拆分為M份,同時將reduce階段的任務拆分為R份。
理想情況下,M和R的值都應該遠大於worker機器的數量。
讓每一個worker執行很多不同的任務可以提高動態負載均衡的效率,
同時也能加快當一個worker故障時的恢復速度:(故障worker機器上)很多已經完成的map任務可以分散到所有其它的worker機器上去(重新執行)。

 

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

 

在我們的實現中,對M和R的實際大小做了限制,因為master必須O(M+R)的排程決定,同時要保持O(MR)個如上所處的記憶體狀態。
(然而這對於記憶體的總體使用率來說影響還是較小的:這O(M
R)份的狀態裡,構成每個map/reduce任務對的資料(只)佔大約1位元組。)

 

Furthermore, R 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 M so that each individual task is roughly 16 MB to 64 MB of input data
(so that the locality optimization described above is most effective),
and we make R a small multiple of the number of worker machines we expect to use.
We often perform MapReduce computations with M = 200,000 and R = 5,000, using 2,000 worker machines.

 

除此之外,使用者通常會限制R的大小,因為每一個reduce任務的輸出最後都會在一個被拆分的輸出檔案中。
實際上,我們傾向於設定M的大小使得每個獨立任務所需的輸入資料大約在16MB至64MB之間(使得上文所述的區域性性優化效果最好), 同時我們設定R的大小為我們預期使用worker機器數量的小几倍。
我們執行MapReduce計算時,通常使用2000臺worker機器,並設定M的值為200000,R的值為5000。

3.6 Backup Tasks(後備任務)

 

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/s to 1 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運算總耗時變長的一個常見的原因是存在“落伍者”:即一臺機器花費了異常長的時間去完成計算中最後的幾個map或reduce任務。
導致“落伍者”出現的原因多種多樣。
舉個例子,一臺有著壞磁碟的機器可能會在(讀取磁碟時)頻繁進行糾錯,使得磁碟的讀取效能從每秒30MB下降到每秒1MB。
叢集排程系統可能還將其它任務也排程到了這臺機器上,由於CPU、記憶體、本地磁碟或網路頻寬的競爭,使得MapReduce程式碼的執行變得更加的緩慢。
我們最近遇到的一個問題是由機器初始化程式碼中的一個bug導致的,其禁用了處理器的快取:受到影響的機器其計算速度(比正常情況下)慢了100倍以上。

 

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% longer to complete when the backup task mechanism is disabled.

 

我們有一個通用的機制來減輕“落伍者”問題帶來的影響。
當一個MapReduce運算接近完成時,master將會排程剩下的處理中的任務進行後備執行(backup executions)。
無論是主執行完成還是後備執行完成,這些任務都會被標記為已完成。
我們已對這個機制進行了優化,使得這一操作令所使用的計算資源增加通常不會超過幾個百分點。
我們發現這一操作明顯減少了大型MapReduce操作的完成時間。
例如,如果禁用後備任務這一機制,在5.3節中所述的排序程式將多花費44%的時間才能完成。

4 Refinements(改進)

 

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(分割槽函式)

 

The users of MapReduce specify the number of reduce tasks/output files that they desire (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) mod R”).
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)) mod R” as the partitioning function causes all URLs from the same host to end up in the same output file.

 

MapReduce使用者期望能指定reduce任務/輸出檔案的數量。
在這些任務中,使用一個基於中間態key的分割槽函式對資料進行分割槽。
(我們)提供了一個使用雜湊取模的預設分割槽函式(例如:“hash(key) mod R”)。
這往往會得到一個非常均衡的分割槽結果。
然而在有些情況下,使用其它的一些基於key的分割槽函式對資料進行分割槽是很有用的。
舉個例子,有時(map任務)輸出的key是URL,且我們希望同一個主機上的所有條目最後都寫入同一個輸出檔案中。
為了支援這種場景,MapReduce庫的使用者可以提供一個自定義的分割槽函式。
舉個例子,使用“hash(Hostname(urlkey)) mod R”作為分割槽函式,就可以使得來自同一個主機的所有URL(條目)最終都寫入同一個輸出檔案中。

4.2 Ordering Guarantees(有序性保證)

 

We guarantee that within a given partition, the intermediate key/value pairs are processed in increasing key order.
This ordering guarantee makes it easy to generate a sorted output file per partition,
which is useful when the output file format needs to support efficient random access lookups by key,
or users of the output find it convenient to have the data sorted.

 

我們保證在給定的分割槽內,中間態的k/v對是以中間態key值遞增的順序處理的。
這一有序性保證使得能簡單的為每個分割槽生成一個已排序的輸出檔案,
當輸出檔案的格式需要支援基於key來進行高效隨機查詢時(這一機制)會很有價值,或者使用者需要已經排好序的資料時會很方便。

4.3 Combiner Function(組合器函式)

 

In some cases, there is significant repetition in the intermediate keys produced by each map task,
and the user-specified 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, 1>.
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.

 

在一些情況下,每個map任務所生成的中間態key存在明顯的重複,同時使用者自定義的reduce函式具備可交換性和可結合性。
2.1章節中的單詞計數的示例程式就是一個很好的例子。
由於單詞出現的頻率遵循齊夫分佈(Zipf distribution),因此每一個map任務都將生成幾百或幾千的形如<the,1>的記錄。
所有的這些計數將通過網路傳送給一個單獨的reduce任務,然後再通過reduce函式累加它們而生成一個數字。
我們允許使用者指定一個可選的Combiner函式,在資料通過網路傳送前該函式將對資料進行不完全的合併。

 

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任務的機器上執行。
通常情況下,combiner函式和reduce函式的程式碼實現是相同的。
reduce函式和combiner函式間唯一的不同在於MapReduce是如何處理函式的輸出。
一個reduce函式的輸出會寫入最終的輸出檔案中。
而一個combiner函式的輸出會被寫入到一箇中間態的檔案中,並且將會發送給reduce任務。

 

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(輸入和輸出的型別)

 

The MapReduce library provides support for reading input data in several different formats.
For example, “text” 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.

 

MapReduce庫為多種不同格式輸入資料的讀取提供了支援。
例如,"文字"模式下將每一行的輸入視為一個kv鍵值對:key是該行在檔案中的偏移量,而value是該行的內容。
另一種所支援的常用格式則儲存基於key排序的一連串kv鍵值對。
每一個輸入型別的實現知道如何將輸入的資料劃分為有意義的區間,用以在一個獨立的map任務中處理。
(舉個例子,文字模式劃分區間時確保了只會在每一行的邊界上出現區間的劃分)
通過提供一個簡單的reader介面實現,使用者可以增加支援一種新的輸入型別,即使大多數使用者只會使用一個或少數幾個預定義的輸入型別。

 

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.

 

reader不一定只能通過讀取檔案來提供資料。
舉個例子,很容易定義一個reader去資料庫中讀取記錄,或者從被對映在記憶體中的資料結構中讀取資料。

 

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(副作用)

 

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的使用者發現從他們的map或reduce操作中生成輔助檔案作為額外的輸出可以為其帶來一些便利。
我們依賴應用程式的作者(自己在程式中保證)使得這些副作用具有原子性和冪等性。
通常,應用程式會(將額外的輸出)寫入一個臨時檔案,並且一旦完全生成該檔案後便原子性的重新命名這一檔案。

 

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(跳過錯誤的記錄)

 

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.

 

有時使用者的程式碼中存在一些bug,造成了Map或Reduce函式在處理某些資料時一定會崩潰。這些bug會阻止MapReduce操作的完成。
通常的做法是修復這個bug,但有時這是行不通的;可能這個bug位於三方庫中,且無法獲得其原始碼。
當然,有時忽略掉少量的資料是可接受的,比如對一個大型資料集上進行統計分析時。
我們提供了一個可選的執行模式,當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.

 

每個worker程序都安裝了一個訊號處理器,用於捕獲段異常(segmentation violations)和匯流排錯誤(bus errors)。
在呼叫使用者的Map或Reduce操作前,MapReduce庫會將引數的序列號儲存在一個全域性變數中。
如果使用者程式碼產生了一個訊號,則訊號處理器將會向MapReduce的master傳送一個包含了(該引數)序列號的"最後喘息(last gasp)"UDP包。
當master一個特定的記錄不止一次的導致故障時,master會指示對應的Map或Reduce任務在下一次重新執行時應該跳過該記錄。

4.7 Local Execution(本地執行)

 

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).

 

在實際計算髮生在分散式系統中時,除錯Map或Reduce函式會變得很棘手,通常由master動態的在幾千臺機器上決定工作的分配。
為了更利於除錯、分析和小規模的測試,我們開發了一個(執行在本地機器上的)MapReduce庫的可替代實現,該庫能讓所有的MapReduce工作在本地機器上順序執行。
控制權被交給了使用者,使得計算可以被限制在指定的Map任務中。
使用者通過一個特殊的標誌來呼叫他們的程式,然後可以輕鬆地使用任何他們覺得好用的除錯或者測試工具(例如:gdb)。

4.8 Status Information(狀態資訊)

 

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.

 

master機器運行了一個內建地Http伺服器,並提供了一系列地狀態資訊頁面供使用者訪問。
狀態資訊頁面會展示計算的進度,例如有多少任務已經完成,多少任務正在執行中,輸入資料的位元組數,中間資料的位元組數,輸出資料的位元組數,處理速度等等資訊。
頁面也包含了指向每個任務對應的標準誤差(standard error)和標準輸出檔案的連結。
使用者可以使用這些資料預測還要多長時間完成計算,以及是否需要為該計算投入更多資源。
這些頁面也可用於找出為什麼實際的計算比所預期的要慢的原因。

 

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.

 

此外,高階狀態頁面展示了哪些worker機器發生了故障,以及哪些map和reduce任務在執行時發生了故障。
在嘗試除錯使用者程式碼中的bug時這些資訊會很有用。

4.9 Counters(計數器)

 

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函式中以恰當的方式對計數器進行累加操作。
例如:

Count* uppercase;
uppercase = GetCounter("uppercase");

map(String name, String contents) :
    for each word w in contents:
        if(isCapitalized(w)):
            uppercase->Increment();
        EmitIntermediate(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.)

 

獨立worker機器中的counter值會週期性的傳遞給master(在ping響應包中附帶)
master將來自已經成功完成的map和reduce任務中的counter值聚合在一起,並在MapReduce任務完成時返回給使用者程式碼。
當前的counter值也會展示在master的狀態頁上,使得使用者可以看到實時的計算進度。
在聚合counter值時,master消除了同一個map或reduce任務多次執行的影響,避免了重複計數。
(多次執行出現的原因是我們的備份任務或任務故障時的重複執行導致的)

 

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.

 

有些counter值是由MapReduce自行維護的,例如已處理的輸入k/v對的數量和已生成的輸出k/v對的數量。

 

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操作中,使用者程式碼想要確保已生成的k/v對數量嚴格等於已處理的輸入k/v對數量,或者確保已處理的德語文件數量在已處理的全部文件中的佔比是否處於一個可接受的比例內。

5 Performance(效能)

 

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計算來測量MapReduce的效能。
其中一個計算是在大約1TB的資料中檢索特定的模式。
另一個計算是對大約1TB的資料進行排序。

 

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(叢集配置)

 

All of the programs were executed on a cluster that consisted of approximately 1800 machines.
Each machine had two 2GHz Intel Xeon processors with Hyper-Threading 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 band-width 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主頻的Intel至強處理器,4GB的記憶體,兩塊160GB容量的IDE硬碟,以及一條千兆的乙太網鏈路。
所有機器都被安置在一個雙層的樹形交換網路中,根節點處的總可用網路頻寬大概為100-200GB每秒。
所有的機器都位於同一個主機託管設施(hosting facility)內,因此任意一對機器間的(網路互動的)往返時間都低於1毫秒。

 

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(Globally search a Regular Expression and Print 基於正則表示式的全域性搜尋並列印)

 

The grep program scans through 10^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), and the entire output is placed in one file (R = 1).

 

grep程式掃描通過掃描10^10個100位元組大小的記錄,搜尋一個相對比較少見的3字元模式(這個模式只出現在92337條記錄中)。
輸入資料被分割為大約64MB大小的塊(M = 15000),並且完整的輸出被放在了一個檔案中(R = 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 30 GB/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.

 

圖二展示了隨時間推移的計算進度。
Y軸標識著掃描輸入資料的速率。
隨著越來越多的機器被分配給當前MapReduce計算,掃描輸入資料的速率也越來越快,並且當分配了1764個worker機器時其峰值達到了30GB每秒。
當map任務完成後,掃描輸入資料的速率開始下降並在計算執行到大約80秒的時候降至0。
整個計算從開始到結束大概耗時150秒。
這其中包括了一分鐘左右的啟動開銷。
這一開銷是由於需要將程式分發到所有的worker機器上,以及為了開啟1000個輸入檔案集合而與GFS互動並獲得區域性性優化資訊的延遲。

5.3 Sort(排序)

 

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

 

這個排序程式對10^10個100位元組大小的記錄進行排序(大約1TB的資料)。
這個程式是參照TeraSort基準測試程式而編寫的。

 

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位元組大小的、用於排序的key並且發出該key,並將原始的文字行作為value而生成中間態的k/v鍵值對。
我們使用內建的恆等函式(Identity function)作為Reduce運算元。
這個函式傳入中間態的k/v鍵值對,並且不做任何修改的將之作為輸出的k/v鍵值對。
最終完成排序的輸出被寫入了一個雙向複製的GFS檔案集合中(即程式總共寫入、輸出了2TB的資料)。

 

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

 

如上所述,輸入的資料被分給為64MB的塊(M = 15000)。
我們將排好序後的輸出資料分割為4000個檔案(R = 4000)。
分割槽函式基於key的初始位元組值將其分割為R份。

 

Our partitioning function for this benchmark has built-in 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 split-points for the final sorting pass.

 

我們的基準測試中內建的分割槽函式是瞭解key值具體分佈的。
在一個常規的排序程式中,我們會預先插入一個MapReduce操作,該操作將會收集key值的一個樣本並且基於key值樣本的分佈情況來計算最終排序時需要的分割點。

 

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/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部分展示了一個排序程式的正常執行過程。
左上角的圖表標識了輸入資料讀取的速率。
輸入資料速率的峰值為13GB每秒,由於所有的map任務都在200秒內完成了因此其非常快速地降到了零。
請注意輸入速率是小於上述地grep程式的。
這是因為排序的map任務有一半的耗時和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.

 

左邊排中間的圖表標識了map任務通過網路將資料傳送給reduce任務的速率。
這一轉換在第一個map任務完成不久後便開始了。
圖表中的第一個高峰對應著第一批的大約1700個reduce任務(整個MapReduce分配了1700臺機器,並且每一臺機器同一時間至多隻能執行一個reduce任務)
大概執行了300秒的計算時,第一批的一些reduce任務陸續完成並且剩餘的reduce任務繼續轉換資料。
所有的轉換大概在計算執行了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.

 

左下方的圖表標識了reduce任務將排序好的資料寫入最終的輸出檔案的速率。
在第一個轉換(shuffling)階段結束到開始寫入之間存在一點延遲,其原因是機器此時正忙於對中間態的資料進行排序。
寫入資料的以2-4GB每秒的速率持續了一段時間。所有的寫入大約在計算執行至850秒左右時完成。
包括啟動的開銷在內,整個計算過程共耗時891秒。
這與TeraSort基準測試目前已報告的最快記錄很相近。

 

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 rather than replication.

 

有幾點值得注意:

  • 輸入的速錄比轉換和輸出的速率要高很多,其原因在於我們進行了區域性性優化。大多數的資料是從本地的硬碟中讀取的,從而避免使用我們相對有限的網路頻寬。
  • 轉換速率比輸出速率要高很多,其原因在於輸出階段寫入了已排序資料的兩個備份(出於可靠性和可用性的考慮,我們構建了兩個輸出資料的備份)。
    我們寫入兩個備份的原因在於這是我們底層檔案系統所提供的可靠性和可用性的機制。
  • 如果底層檔案系統使用糾錯碼(Erasure Coding)來代替複製(來保證可靠性),則需要寫入資料時所需要的網路頻寬將減少很多。

5.4 Effect of Backup Tasks(後備任務的影響)

 

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% in elapsed time.

 

在圖3的b部分,我們展示了禁用後備任務時排序程式的執行狀況。
執行流與圖3的a部分很相似,除了最後面有一個非常長的尾部,且其幾乎沒有任何寫入發生(注意觀察代表done的那條豎線)。
在960s後,除了5個reduce任務外其它任務都已經完成。
然而最後幾個“落伍者”任務直到300秒後才相繼完成。整個計算過程共花費了1283秒,(相比正常執行的情況)增加了44%的耗時。

5.5 Machine Failures(機器故障)

 

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部分,我們展示了一個排序程式的執行流程,在其計算過程中我們故意在幾分鐘內殺死(killed)了1746臺worker機器中的200臺機器(的worker程序)。
底層的叢集排程器立即在這些機器上重新啟動新的worker程序(因為只是殺掉了worker程序,機器依然是正常工作的)。

 

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% over the normal execution time).

 

worker程序被殺死時展示一個負的輸入速率,因為之前已完成的任務失效了(因為對應的map worker被殺掉了)並且這些任務需要被重新執行。
map任務的重新執行相對來說是比較快的。
包括啟動開銷在內,整個計算過程共耗時933秒(相較於正常執行時的耗時,只增加了5%)

6 Experience(經驗)

 

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:

  • 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
  • large-scale graph computations.
 

我們於2003年2月編寫了第一版的MapReduce庫,並且在2003年的8月對其進行了重大改進,其中包括區域性性優化、跨worker機器間任務執行的動態負載均衡等等。
從那時起,我們驚喜的看到MapReduce庫被廣泛的應用於我們工作中所遇到的各種問題上。
MapReduce庫已在谷歌內的許多領域中被廣泛的使用,其中包括:

  • 大規模的機器學習問題
  • Google新聞和Froogle產品的聚類問題(clustering problems)
  • 基於常見查詢所產出的報告提取資料(例如,Google Zeitgeist (注:Google開發的一款網路查詢分析程式))
  • 基於新實驗和產品的網頁提取相關屬性(例如,從用於本地化搜尋的大型網頁語料庫中提取地理位置)
  • 大規模的圖計算
 
 
 

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.

 

圖4展示了登記在我們主要的原始碼管理系統中的獨立MapReduce程式數量隨著時間的推移有著顯著的增長,
從2003年年初的0個,再到2004年的9月有了接近900個獨立的MapReduce程式例項了。
MapReduce如此成功的原因在於其使得編寫一個簡單的程式,並在半小時內於上千臺機器上高效的執行成為了可能,這極大地加快了開發和原型設計的週期。
此外,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.

 

在每個job完成時,MapReduce庫會以日誌的形式記錄對應job所使用的計算資源的統計資訊。
在表1中,我們展示了谷歌在2004年8月所執行的MapReduce job的一個子集的(所使用計算資源的)一些統計資訊。

6.1 Large-Scale Indexing(大規模索引)

 

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最重要的一個應用就是完全重寫了索引生成系統,其生成的資料結構被用於Google web的搜尋服務。
索引系統將我們的爬蟲系統所檢索到的、被儲存為一系列GFS檔案的大量文件作為輸入。
這些文件的原始內容的資料大小超過了20TB。
整個索引處理過程由5到10個連續的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++ code
    to approximately 700 lines when expressed using MapReduce.
 
  • 索引相關的程式碼變得更簡單、(程式碼量)更少和更容易理解,因為處理容錯、分散式和並行化的程式碼被隱藏在了MapReduce庫內部。
    例如,某一計算階段的程式碼量在(改為)使用MapReduce表達後從(原來的)大約3800行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.
 
  • 處理索引變得更容易操作,因為大多數機器故障、機器執行緩慢和網路間歇性斷開(networking hiccups)等問題都由MapReduce庫自動處理了,而不需操作員介入。
    此外,通過向索引處理的叢集中新增新的機器可以輕鬆地提高索引處理的效能。
 

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 N element array in logN time
on N processors using parallel prefix computations.
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.

 

很多系統都提供了受限制的程式設計模型,並且使用這些約束來自動的將計算並行化。
舉個例子,使用並行字首計算時,一個結合函式可以在N個處理器上,以logN的時間計算出一個N元素陣列的所有字首。
MapReduce可以被認為是基於我們在現實世界中關於大型計算的經驗所總結出的一些模型的一個簡化和精煉。
更重要的是,我們提供了一個可拓展到幾千個處理器規模的容錯實現。
相比之下,大多數的並行處理系統的實現只能運用在更小的規模下,並且將處理機器故障的細節留給了程式設計師(去實現)。

 

Bulk Synchronous Programming and some MPI primitives 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.

 

整體同步程式(Bulk Synchronous Programming)和一些訊息傳遞介面(MPI Message-Passing Interface)原語提供了更高級別的抽象,使得程式設計師可以更加簡單的編寫並行程式。
這些系統與MapReduce最關鍵的不同在於MapReduce利用一個受限的程式設計模型令使用者程式自動的並行化並且了提供透明的(使用者無需感知的)容錯機制。

 

Our locality optimization draws its inspiration from techniques such as active disks, 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.

 

我們區域性性優化機制的靈感源自active disks等技術,推進計算並使得所要處理的元素是靠近本地磁碟的,以減少通過網路I/O子系統傳送的資料量。
我們的計算執行在直連少量磁碟的商用處理器上,而不是直接執行在有著磁碟控制器的處理器(disk controller processors)上,但大致的方法是類似的。

 

Our backup task mechanism is similar to the eager scheduling mechanism employed in the Charlotte System.
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.

 

我們的後備任務機制類似於Charlotte系統中所應用的緊急排程(eager scheduling)機制。
簡單的緊急排程機制的一個缺點就是如果一個給定的任務反覆失敗,則整個計算將無法完成。
我們通過跳過有問題記錄的機制,一定程度上的修復了這一問題。

 

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.

 

MapReduce的實現依賴於一個內部的叢集管理系統,該系統負責在大量的共享機器中分發和執行使用者的任務。
雖然這並不是本論文的重點,但該叢集管理系統從本質上來說和Condor系統非常相似。

 

The sorting facility that is a part of the MapReduce library is similar in operation to NOW-Sort.
Source machines (map workers) partition the data to be sorted and send it to one of R 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類似。
源機器(map workers)將待排序的資料進行分割槽,並將其傳送給R個reduce worker中的一個。
每一個reduce worker在本地對資料進行(儘可能的在記憶體中排序)。
當然,NOW-Sort不支援使得可使用者自定義的Map和Reduce函式,相比之下我們的MapReduce庫則有著更廣的適用範圍。

 

River 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 fine-grained 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提供了一個程式設計模型,該模型中程序間通過向分散式佇列中傳送資料來進行通訊。
和MapReduce一樣,即使由於異構的硬體或者系統擾動而導致了(計算資源的)不均衡,River系統也試圖在這種場景下提供足夠均衡的效能。
River通過仔細的對磁碟和網路傳輸進行排程,用以實現任務完成時間的平衡。
MapReduce則採用了不同的方法。
通過受限的程式設計模型,MapReduce框架能夠將一個問題分割為大量細粒度的任務。
這些任務會在可用的worker機器上動態的排程,因此執行速度更快的worker能夠處理更多的任務。
這一受限的程式設計模型也允許我們在job接近完成時進行冗餘任務的排程,這可以極大地減少在非均衡場景下的任務完成時間(比如存在緩慢或者卡住不動的worker)。

 

BAD-FS 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.
Both systems use redundant execution to recover from data loss caused by failures.
Both use locality-aware scheduling to reduce the amount of data sent across congested network links.

 

BAD-FS是一個與MapReduce非常不同的程式設計模型。與MapReduce不同,其致力於跨廣域網的執行job。
然而,這裡有兩個很相似的基本點。
兩個系統都使用冗餘的執行來恢復由故障導致的資料丟失。
兩者都使用距離敏感的排程策略,用以減少在擁擠的網路鏈路上所傳送資料的數量。

 

TACC 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是一個旨在簡化高效能網路服務構造的框架。
和MapReduce一樣,其也依賴重複執行機制來實現故障容錯。

8 Conclusions(總結)

 

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.
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是基於谷歌檔案系統GFS讀取輸入資料和寫出輸出資料的。
我們要感謝Mohit Aron、Howard Gobioff、Markus Gutschke、David Kramer、Shun Tak Leung和Josh Redstone為開發GFS所做的工作。
我們也要感謝Percy Liang和Olcan Sercinoglu為開發MapReduce叢集管理系統所做的工作。
Mike Burrows, Wilson Hsieh, Josh Levenberg, Sharon Perl, Rob Pike和Debby Wallach為這篇論文的前期草稿提供了很有幫助的建議。
匿名的OSDI評論員和我們的稽核者Eric Brewer就論文可以改進的方面提供了許多有用的建議。
最後,我們感謝谷歌工程部的所有MapReduce使用者,感謝他們提供的有價值的反饋、建議和bug報告。

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"
// User’s map function 
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; ) { 
            // Skip past leading whitespace 
            while ((i < n) && isspace(text[i])) 
               i++;
            // Find word end 
            int start = i; 
            while ((i < n) && !isspace(text[i]))
               i++;
            if (start < i) 
               Emit(text.substr(start,i-start),"1");
        }
    }
};   


REGISTER_MAPPER(WordCounter);
// User’s reduce function 
class Adder : public Reducer { 
    virtual void Reduce(ReduceInput* input) { 
        // Iterate over all entries with the 
        // same key and add the values 
        int64 value = 0; 
        while (!input->done()) { 
            value += StringToInt(input->value()); 
            input->NextValue();
        }
        // Emit sum for input->key() 
        Emit(IntToString(value));
    }
};

REGISTER_REDUCER(Adder);
int main(int argc, char** argv) { 
    ParseCommandLineFlags(argc, argv);
    MapReduceSpecification spec;
    // Store list of input files into "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");
    }
    // Specify the output files: 
    // /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");
    // Optional: do partial sums within map 
    // tasks to save network bandwidth 
    out->set_combiner_class("Adder");


    // Tuning parameters: use at most 2000 
    // machines and 100 MB of memory per task 

    spec.set_machines(2000); 
    spec.set_map_megabytes(100); 
    spec.set_reduce_megabytes(100);

    // Now run it 
    MapReduceResult result; 
    if (!MapReduce(spec, &result)) abort();

    // Done: ’result’ structure contains info
    // about counters, time taken, number of 
    // machines used, etc.
    return 0;
}
針對MapReduce強語義、弱語義概念譯者自己的理解

(譯者小熊餐館注:
上面這段內容比較晦澀,這裡根據我舉個簡單的例子來幫助大家理解。
假設有一段話:“Your name is Tom? My name is Tom, too.”,原始需求是想利用MapReduce計算統計分詞後每個單詞出現的次數(例子裡句子很短是為了描述,實際上可以是海量的文件)。
我們自定義的Map函式是確定性的函式運算元,輸入這個字串進行Map操作後總是會返回以下9個kv對(key是單詞,value是出現的次數): <Your,1>, <name,1>, <is,1>, <Tom,1>, <My,1>, <name,1>, <is,1>, <Tom,1>, <too,1>。
無論Map函式是單機單執行緒順序執行,還是在叢集中並行的執行,結果都是明確不變的,也就是上述的強語義的概念。
MapReduce庫會把Key相同的kv對進行分組,並將其傳遞給我們自定義的reduce函式,下面是分組後會傳給reduce函式運算元的引數:
<Tom,list(1,1)>, <name,list(1,1)>, <is,list(1,1)>, <Your,list(1)>, <My,list(1)>, <too,list(1)>。
在原始需求下,當map函式計算的結果不變時,無論reduce函式運算元何時執行,也無論出現故障重複執行了幾次,得到的結果一定和單機單執行緒順序執行相同,這也是強語義。
結果:<Tom,2>, <name,2>, <is,2>, <Your,1>, <My,1>, <too,1>。 (key為單詞,value為出現的次數)
而如果改變原始需求,除了累加單詞總共出現的次數還要返回reduce計算時的當前機器id。
那麼此時的reduce函式就屬於不確定的函式運算元了,因為即使輸入相同,但每一次的執行獲得的結果都不一定相等(排程到不同機器上執行,機器id不同,輸出的結果也就不同)。
假設有兩臺reduce任務worker,id分別為aaa和bbb。
id為aaa的worker機器上reduce任務的執行結果就是<Tom,2-aaa>, <name,2-aaa>, <is,2-aaa>, <Your,1-aaa>, <My,1-aaa>, <too,1-aaa>,是為結果result_aaa。
id為bbb的worker機器上reduce任務的執行結果則是<Tom,2-bbb>, <name,2-bbb>, <is,2-bbb>, <Your,1-bbb>, <My,1-bbb>, <too,1-bbb>,是為結果result_bbb。
上述的弱語義表示,無論出現了什麼機器故障,雖然無法準確的得知結果到底是哪一個,但最終結果不是result_aaa就是result_bbb,反正一定是某一個reduce任務生成的完整輸出資料,而絕不可能出現跨任務的資料重複、冗餘、缺失等問題。
)

翻譯過程中大量參考了以下大佬的文章,非常感謝
https://zhuanlan.zhihu.com/p/122571315
https://blog.csdn.net/gqv2009/article/details/74674061
https://www.cnblogs.com/hehe520/p/6147464.html