我的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