某些时候map的数量太少,但是每个map的文件比较大,导致执行时间很长。为了充分利用hadoop的优势,我们把map的数据hash到更多的reduce节点去做处理。
使用随机数据都不是特别好,更好的方式是使用input line的hashCode。
public void map(LongWritable key, Text value,
OutputCollector<Text, Text> output, Reporter reporter)
throws IOException
{
try
{
String line = value.toString();
rand=line.hashCode();
x.set(rand.toString());
y.set(line);
output.collect(x,y);
} catch (Exception e)
{
reporter.incrCounter("map", "exp", 1);
}
}