【发布时间】:2014-03-18 10:40:59
【问题描述】:
我尝试使用 hadoop 分发计算。
我正在使用序列输入和输出文件,以及自定义可写文件。
输入是一个三角形列表,最大大小为 2Mb,但也可以更小 50kb 左右。 中间值和输出是自定义 Writable 中的 map(int,double)。 这是瓶颈吗?
问题是计算比没有hadoop的版本慢很多。 此外,将节点从 2 个增加到 10 个,并不会加快进程。
一种可能性是由于输入大小较小,我没有获得足够的映射器。
我进行了更改 mapreduce.input.fileinputformat.split.maxsize 的测试,但它变得更糟,而不是更好。
我在本地使用 hadoop 2.2.0,在 amazon elastic mapreduce 使用。
我是否忽略了什么?或者这只是应该在没有 hadoop 的情况下完成的任务? (这是我第一次使用 mapreduce)。
您想查看代码部分吗?
谢谢。
public void map(IntWritable triangleIndex, TriangleWritable triangle, Context context) throws IOException, InterruptedException {
StationWritable[] stations = kernel.newton(triangle.getPoints());
if (stations != null) {
for (StationWritable station : stations) {
context.write(new IntWritable(station.getId()), station);
}
}
}
class TriangleWritable implements Writable {
private final float[] points = new float[9];
@Override
public void write(DataOutput d) throws IOException {
for (int i = 0; i < 9; i++) {
d.writeFloat(points[i]);
}
}
@Override
public void readFields(DataInput di) throws IOException {
for (int i = 0; i < 9; i++) {
points[i] = di.readFloat();
}
}
}
public class StationWritable implements Writable {
private int id;
private final TIntDoubleHashMap values = new TIntDoubleHashMap();
StationWritable(int iz) {
this.id = iz;
}
@Override
public void write(DataOutput d) throws IOException {
d.writeInt(id);
d.writeInt(values.size());
TIntDoubleIterator iterator = values.iterator();
while (iterator.hasNext()) {
iterator.advance();
d.writeInt(iterator.key());
d.writeDouble(iterator.value());
}
}
@Override
public void readFields(DataInput di) throws IOException {
id = di.readInt();
int count = di.readInt();
for (int i = 0; i < count; i++) {
values.put(di.readInt(), di.readDouble());
}
}
}
【问题讨论】:
-
我们不会看到输入小到 2MB,甚至只有 100MB 或几 GB 的任何显着改进。与在没有 hadoop 的情况下运行相同任务相比,创建 map、reduce 任务和所有 diff 线程来运行 Job 的开销可能更多。除非我们拥有数 GB、TB 级别的数据并真正运行分布式作业,否则我们可能看不到 hadoop 的好处。
-
mapper的输出(键,值)对是什么?有什么代码可以帮助我们更好地理解?
标签: java hadoop mapreduce amazon writable