如标题所说。我在读书 另一个语言极客:延续的风格 我想知道MapReduce是否可以将其归类为一种延续风格的又称CPS的一种形式。

我还想知道CP如何利用一台计算机执行复杂的计算。也许CPS可以更轻松地使用 演员模型.

有帮助吗?

解决方案

我会说他们是对立的。 MapReduce显然将自己放在分布中,地图可以独立执行子任务。使用CPS,您可以编写一个递归功能,每个呼叫都在等待较小的情况下等待。

我认为CPS是盖伊·斯蒂尔(Guy Steele 并行的未来:程序员要做什么?

其他提示

我不会这么说。 MapReduce确实执行用户定义的功能,但这些功能更为称为“回调”。我认为CPS是一个非常抽象的概念,通常用于模拟诸如函数,Coroutines,回调和循环之类的知名概念的行为。通常不直接使用。

再说一次,我可能会使CPS本身混淆。我不是任何一个专家。

CPS和MAPREDUCE都利用了高阶功能。这意味着两者都涉及将函数作为参数的函数。

在CPS的情况下,您具有一个函数(称为延续),其参数说出如何处理结果。通常(但并非总是)延续一次。该函数指定其余的计算应如何继续。这也使其成为串行的事情。通常,您有一个执行线程,并且延续指定其将如何继续。

在MapReduce的情况下,您提供了多次使用的函数参数。这些参数函数并不能真正代表整个计算的其余部分,而只是一遍又一遍地使用的几个构建块。通常可以在多台机器上分发“一遍又一遍地”的位,从而使其成为一种平行的东西。

因此,您可以看到共同点。但是一个并不是另一个例子。

地图还原是实现。您可以使用该实现的编码界面可以使用连续性;这确实是如何抽象的框架和工作控制的问题。考虑Hadoop的声明性接口,例如Pig或SQL等声明语言;接口下方的机械可以通过多种方式实现。

例如,这是一个抽象的python map-reduce实现:

def mapper(input_tuples):
    "Return a generator of items with qualifying keys, keyed by item.key"
    # we are seeing a partition of input_tuples
    return (item.key, item) for (key, item) in input_items if key > 1)

def reducer(input_tuples):
    "Return a generator of items with qualifying keys"
    # we are seeing a partition of input_tuples
    return (item for (key, item) in input_items if key != 'foo')

def run_mapreduce(input_tuples):
    # partitioning is magically run across boxes
    mapper_inputs = partition(input_tuples)
    # each mapper is magically run on separate box
    mapper_outputs = (mapper(input) for input in mapper_inputs)
    # partitioning and sorting is magically run across boxes
    reducer_inputs = partition(
        sort(mapper_output for output in mapper_outputs))
    # each reducer is magically run on a separate box
    reducer_outputs = (reducer(input) for input in reducer_inputs)

这是使用Coroutines的相同实现,甚至隐藏了更神奇的抽象:

def mapper_reducer(input_tuples):
    # we are seeing a partition of input_tuples
    # yield mapper output to caller, get reducer input
    reducer_input = yield (
        item.key, item) for (key, item) in input_items if key > 1)
    # we are seeing a partition of reducer_input tuples again, but the
    # caller of this continuation has partitioned and sorted
    # yield reducer output to caller
    yield (item for (key, item) in input_items if key != 'foo')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top