我的Reduce操作产生的输出文件很大(Gzipping后1 GB)。我希望它产生中断输出到200 MB的较小文件。是否有一个属性/ Java类来按大小分割减少输出?线条? 我无法增加还原器的数量,因为这会对hadoop作业的性能产生负面影响。Hadoop中的分裂Reducer输出
2
A
回答
2
我很好奇,为什么你不能只是使用更多的减速,但我会相信你的话。
你可以做的一个选择是使用MultipleOutputs并从一个reducer写入多个文件。例如,假设每个reducer的输出文件都是1GB,而您想要256MB文件。这意味着您需要为每个Reducer写入4个文件,而不是一个文件。
在你的工作的驱动程序,这样做:
JobConf conf = ...;
// You should probably pass this in as parameter rather than hardcoding 4.
conf.setInt("outputs.per.reducer", 4);
// This sets up the infrastructure to write multiple files per reducer.
MultipleOutputs.addMultiNamedOutput(conf, "multi", YourOutputFormat.class, YourKey.class, YourValue.class);
在你减速,这样做:
@Override
public void configure(JobConf conf) {
numFiles = conf.getInt("outputs.per.reducer", 1);
multipleOutputs = new MultipleOutputs(conf);
// other init stuff
...
}
@Override
public void reduce(YourKey key
Iterator<YourValue> valuesIter,
OutputCollector<OutKey, OutVal> ignoreThis,
Reporter reporter) {
// Do your business logic just as you're doing currently.
OutKey outputKey = ...;
OutVal outputVal = ...;
// Now this is where it gets interesting. Hash the value to find
// which output file the data should be written to. Don't use the
// key since all the data will be written to one file if the number
// of reducers is a multiple of numFiles.
int fileIndex = (outputVal.hashCode() & Integer.MAX_VALUE) % numFiles;
// Now use multiple outputs to actually write the data.
// This will create output files named: multi_0-r-00000, multi_1-r-00000,
// multi_2-r-00000, multi_3-r-00000 for reducer 0. For reducer 1, the files
// will be multi_0-r-00001, multi_1-r-00001, multi_2-r-00001, multi_3-r-00001.
multipleOutputs.getCollector("multi", Integer.toString(fileIndex), reporter)
.collect(outputKey, outputValue);
}
@Overrider
public void close() {
// You must do this!!!!
multipleOutputs.close();
}
这个伪代码在头脑里的旧的MapReduce API编写的。尽管使用mapreduce api存在等价的apis,但无论如何,您应该全部设置好。
0
没有财产做到这一点。您需要编写自己的输出格式&录音笔。
相关问题
- 1. Hadoop map-reducer不写任何输出
- 2. 将Reducer的输出添加到Hadoop中的列表中
- 3. Hadoop读取输入分裂多次
- 4. 有没有办法从hadoop中收集reducer的输出?
- 5. Hadoop Reducer内存中的值?
- 6. Hadoop中的Mapper和Reducer
- 7. 如何在Hadoop中设置reducer输出名称?
- 8. Hadoop - 使用Java将reducer输出合并到单个文件中
- 9. 多个reducer如何在Hadoop中只输出一个部分文件?
- 10. Hadoop返回映射器的输出而不是reducer
- 11. hadoop-mapreduce reducer-组合器输入
- 12. Hadoop - 在Reducer中排序
- 13. 将reducer输出目录路径保存到Hadoop中的变量中
- 14. 混乱的hadoop如何分裂工作
- 15. 使用FileAlreadyExistsException的Reducer中的Hadoop MultipleOutputs
- 16. 指定reducer时的中间输出
- 17. 为什么hadoop 1.0.3中的reducer很慢
- 18. 在hadoop中运行不带reducer的WordCount
- 19. 控制不会去hadoop中的reducer
- 20. Hadoop中reducer的好处是什么?
- 21. Hadoop mapreduce - reducer未运行
- 22. hadoop mapreduce common friends reducer spillage
- 23. 使用多个reducer时,Hadoop中的键/值对如何分布?
- 24. Hadoop作业使用相同的reducer输出到相同的文件
- 25. 如何在自定义分区程序Hadoop中设置每个reducer的输出文件号
- 26. 什么在Hadoop Reducer中结束?
- 27. hadoop NaturalKeyGroupingComparator - Reducer中发生了什么?
- 28. 如何在Hadoop 1.0.4中链接mapper/reducer?
- 29. 的Java分裂输入
- 30. Hadoop WordCount输出
我无法增加reducer的数量,因为它会让作业变慢,因为需要完成更多的shuffling数据。我已经在理论和实践中证实了这一点。不过我提议你的解决方案。我会试一试。 – hznut