java - 为什么组合器输出记录 = 0?

标签 java hadoop mapreduce combiners bigdata

我有多个输入,所以我有两个映射器。我也有一个组合器:

class JoinCombiner extends MapReduceBase implements
        Reducer<TextPair, Text, TextPair, Text> {

    @Override
    public void reduce(TextPair key, Iterator<Text> values,
            OutputCollector<TextPair, Text> output, Reporter reporter)
            throws IOException {

        Text nodeId = new Text(values.next());
        while (values.hasNext()) {
            Text node = values.next();
            TextPair outValue = new TextPair(nodeId.toString(), "0");
            output.collect(outValue , node);
        }
    }
}

当我使用这个类作为 Reducer 时——所有的话都很好。但如果我将它用作组合器 - 我在日志中有以下信息:
Combine input records=6
Combine output records=0
Reduce input groups=0
Reduce shuffle bytes=30
Reduce input records=0
Reduce output records=0

因此,combiner 没有输出 -> reduce 没有输入。我不明白为什么。如果您有想法,请做一些解释))
谢谢

最佳答案

只有当你有一个 reducer 时才会执行一个组合器。尝试将 combiner 和 reducer 设置为同一个类(如果可能的话),并考虑设置 reduce 任务的数量。

更新:您正在尝试更改组合器中的键。组合器的目的是将相同键的值在本地组合在一起以减少流量。

来自 Hadoop Tutorial on YDN

Instances of the Combiner class are run on every node that has run map tasks. The Combiner will receive as input all data emitted by the Mapper instances on a given node. The output from the Combiner is then sent to the Reducers, instead of the output from the Mappers.



根据我的经验,这并不完全正确。 Hadoop 仅将映射器发出的键发送到化简器 - 这意味着如果您之间有一个组合器,它应该发出与映射器相同的键,从而减少与键关联的值的数量。 IMO,更改组合器中的键会导致意外行为。为了让您了解码合器的简单用例,请考虑使用单词计数器。

Mapper1 发出:
hi 1
hello 1
hi 1
hi 1
hello 1

Mapper2 发出:
hello 1
hi 1

您有七个输出记录。现在,如果您想在本地减少键的数量(意味着在运行映射器的同一台机器上),那么拥有一个组合器将为您提供如下内容:

Combiner1 发出:
hi 3
hello 2

Combiner2 发出:
hello 1
hi 1

请注意,combiner 没有更改 key .现在,在 reducer 中,您将获得如下值:

reducer 1:key: hi, values: <3, 1>你发出 hi 4
因为您只有一个 reducer ,所以这次将通过给它一个不同的键来再次调用同一个 reducer 。

reducer 1:key: hello, values: <2, 1>你发出 hello 3
最终输出如下
hello 3
hi 4

输出根据映射器发出的键进行排序。 您可以选择更改 reducer 发出的 key 但是您的输出不会按 reducer 发出的键排序(默认情况下)。希望有帮助。

关于java - 为什么组合器输出记录 = 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36671006/

相关文章:

apache-spark - 查找事件的 Hadoop 镜像

java - Hadoop MapReduce 不处理/输出错误?

hadoop - 在 Hive 中启动 MapReduce 作业的标准

java - Hadoop,mapreduce java.io.IOException : Type mismatch in value from map: expected org. apache.hadoop.io.Text,收到 org.apache.hadoop.io.IntWritable

java - 多项 Activity 和表面 View 是正确的方法吗?

java - Netbeans Maven :Java Application when run several times creates multiple instances (once for each time run), 导致端口冲突

hadoop - Hadoop Map-Reduce作业的吞吐量

java - java中的Httpclient,不使用任何第三方库

java - @ControllerAdvice 异常处理程序方法未被调用

hadoop - 是否有适用于 Hadoop/HBase 的 Amazon 社区 AMI?