【发布时间】:2013-07-17 04:34:06
【问题描述】:
我们有一个在单个节点上运行的作业最多需要 40m 才能完成,而通过 M/R,我们希望将其缩短到 2m 以下,但我们不确定流程的哪些部分进入@ 987654321@和reduce()。
当前进程:
对于键列表,为每个键调用 Web 服务并获取 xml 响应;将 xml 转换为管道分隔的格式;最后输出一个文件...
def keys = 100..9999
def output = new StringBuffer()
keys.each(){ key ->
def xmlResponse = callRemoteService( key)
def transformed = convertToPipeDelimited( xmlResponse)
output.append( transformed)
}
file.write( output)
Map/Reduce 模型
这是我使用 map/reduce 对其进行建模的方法,只是想确保我走在正确的道路上......
映射器
钥匙从keys.txt中提取;我为每个密钥调用远程服务并存储密钥/xml 对...
public static class XMLMapper extends Mapper<Text, Text, Text, Text> {
private Text xml = new Text();
public void map(Text key, Text value, Context context){
String xmlResponse = callRemoteService( key)
xml.set( xmlResponse)
context.write(key, xml);
}
}
减速器
对于每个键/xml 对,我将 xml 转换为管道分隔格式,然后写出结果...
public static class XMLToPipeDelimitedReducer extends Reducer<Text,Text,Text,Text> {
private Text result = new Text();
public void reduce(Text key, Iterable<Text> values, Context context ) {
String xml = values.iterator().next();
String transformed = convertToPipeDelimited( xml);
result.set( transformed);
context.write( key, result);
}
}
问题
- 在进行
在
reduce()中转换;进行这两项操作的任何好处map()? - 我不检查
reduce()中的重复项,因为 keys.txt 不包含重复键;那安全吗? - 如何控制输出文件的格式?
TextOutputFormat看起来很有趣;我希望它看起来像这样......
100|foo bar|$456,098 101|bar foo|$20,980
【问题讨论】:
-
网络服务难道不是这里真正的限制因素吗?
-
假设只有一个,是的,但它位于代理后面,多个实例部署在多个节点上。
标签: java parallel-processing mapreduce