Skip to the content.

Thuật Toán MapReduce

Hi, các bạn! hôm nay chúng ta sẽ cùng tìm hiểu về thuật toán MapReduce trong xử lý dữ liệu lớn nhé.

Giới thiệu

Có thể bạn chưa biết ?

Đào sâu một chút

img4

img1

Ví dụ kinh điển

Nào chúng ta cùng đến với ví dụ kinh điển trong bài toán xử lý phân tán, song song đó là WordCount.

img6

function map(String input_key, String input_value):
    // input_key: document name
    // input_value: document contents
    for each word w in input_value:
      EmitIntermediate(w, "1");


function reduce(String output_key, Iterator intermediate_values):
    // output_key: a word
    // output_values: a list of counts
    int result = 0;
    for each v in intermediate_values:
      result += ParseInt(v);
    Emit(AsString(result));

image7

img3

Bạn có thể tham khảo Hadoop WordCount Example

Tài liệu tham khảo