java - 即使在命令行上告诉为 -D mapred.reduce.tasks=0 后,hadoop reduce 任务仍在运行

标签 java hadoop mapreduce

我有一个 MapReduce编程为

public static class MapClass extends MapReduceBase implements Mapper<Text, Text, IntWritable, IntWritable> {

        private final static IntWritable uno = new IntWritable(1);
        private IntWritable citationCount = new IntWritable();

        public void map(Text key, Text value, OutputCollector<IntWritable, IntWritable> output, Reporter reporter) throws IOException {
            citationCount.set(Integer.parseInt(value.toString()));
            output.collect(citationCount, uno);
        }
    }

    public static class Reduce extends MapReduceBase implements Reducer<IntWritable, IntWritable, IntWritable, IntWritable> {

        public void reduce(IntWritable key, Iterator<IntWritable> values, OutputCollector<IntWritable, IntWritable> output, Reporter reporter) throws IOException {
            int count = 0;
            while (values.hasNext()) {
                count += values.next().get();
            }

            output.collect(key, new IntWritable(count));
        }
    }

我想运行map任务,输出应为 <number, 1> 形式 当我从命令行运行它时,我说

$ hadoop jar Hadoop-programs.jar com/hadoop/patent/CitationHistogram input output -Dmapred.reduce.tasks=0

但这是我在命令行输出中看到的

12/07/30 06:13:14 INFO mapred.JobClient:  map 50% reduce 0%
12/07/30 06:13:23 INFO mapred.JobClient:  map 58% reduce 0%
12/07/30 06:13:26 INFO mapred.JobClient:  map 60% reduce 8%
12/07/30 06:13:29 INFO mapred.JobClient:  map 68% reduce 8%
12/07/30 06:13:32 INFO mapred.JobClient:  map 76% reduce 8%
12/07/30 06:13:35 INFO mapred.JobClient:  map 85% reduce 16%
12/07/30 06:13:38 INFO mapred.JobClient:  map 93% reduce 16%
12/07/30 06:13:41 INFO mapred.JobClient:  map 98% reduce 16%
12/07/30 06:13:44 INFO mapred.JobClient:  map 100% reduce 16%
12/07/30 06:13:55 INFO mapred.JobClient:  map 100% reduce 69%
12/07/30 06:13:58 INFO mapred.JobClient:  map 100% reduce 78%
12/07/30 06:14:01 INFO mapred.JobClient:  map 100% reduce 94%
12/07/30 06:14:08 INFO mapred.JobClient:  map 100% reduce 100%

当我看到作业的输出时,我看到类似

的条目
1       2
13      2
24      1
29      1
31      2
42      3
6796    7
6799    1
6806    1
6815    1
6824    2

这意味着数据正在聚合

我怎么能完全不运行 reducer?

最佳答案

只有当您实现 ToolRunner.run 方法并在您的 main 方法中传递参数时,它才会起作用。

ToolRunner.run(new Configuration(), new YourClasImplmentingToolRunner(), args);

如果你不想做尝试设置

job.setNumReduceTasks(0);

或者另一个选项是在 conf 中设置值并在作业中使用该配置。

Configuration conf = new Configuration();
conf.set("mapred.reduce.tasks", "0");
Job job = new Job(conf, "My job Name");

关于java - 即使在命令行上告诉为 -D mapred.reduce.tasks=0 后,hadoop reduce 任务仍在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11722424/

相关文章:

java - 无法解析服务器输入流

java - 在 Web 浏览器中无法看到 Java Maven Tomcat-plugin Web 应用程序

java - 使用循环java按每个元素中的位数从最大到最小对数组进行排序

hadoop - 如何通过NFS网关挂载特定的hadoop文件夹

MongoDB - 使用聚合框架或 mapreduce 匹配文档中的字符串数组(配置文件匹配)

hadoop - 重启后 HDFS block 损坏

java - 在 fragment 中使用对话框

azure - 在 Azure 上的 HDInsights 群集上使用 Data Lake 或 Blob

hadoop - 在 Flume 中,文件 channel 的 channel 容量到底意味着什么?

hadoop - 在使用 MapReduce 执行字数统计时,是否可以在 map 函数中将数据拆分为字词?