【发布时间】:2013-06-24 03:32:47
【问题描述】:
我开始使用 mrjob python 包学习 MapReduce。 mrjob 文档列出了以下 sn-p 作为示例 MapReduce 脚本。
"""The classic MapReduce job: count the frequency of words.
"""
from mrjob.job import MRJob
import re
WORD_RE = re.compile(r"[\w']+")
class MRWordFreqCount(MRJob):
def mapper(self, _, line):
for word in WORD_RE.findall(line):
yield (word.lower(), 1)
def combiner(self, word, counts):
yield (word, sum(counts))
def reducer(self, word, counts):
yield (word, sum(counts))
if __name__ == '__main__':
MRWordFreqCount.run()
我了解此算法的一般工作原理、组合器(不需要运行)的作用,以及化简器如何对来自映射器和组合器的打乱和排序值运行。
但是,我不明白减速器是如何得出单个值的。集群的不同节点上没有运行不同的reduce进程吗?如果分区器仅将某些经过混洗的键值对发送到某些 reducer,这些 reduce 函数如何得出一个单一的答案?
我想我对如何将各种 reducer 的输出组合成一个答案感到困惑。
【问题讨论】: