我的工作流程如下:
我正在处理大量数据。我有一个MapFile
需要缓存的。这个文件的大小现在是 1 GB,但我希望它最终会增长。
MapFile 的内容是这样的:
12345,45464 192.34.23.1
33214,45321 123.45.32.1
- 在 中
map-phase
,我处理来自输入文件的每条记录TextInputFormat
。我解析该行(由标记分割)并检索前两个标记,token1 和 token2。
如果 (token1,token2) 对不在缓存文件中,那么我调用 API,获取信息,保存在缓存中(如果可能)并继续处理。
private Parser parser = new customParser();
protected void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
parser.parse(value);
Pair pair = new Pair();
pair.setFirst(parser.getFirst());
pair.setSecond(parser.getSecond());
IP ip = null;
//here is the catch
//check if pair exists in cache
if cache.contains(pair){
ip=cache.get(pair);
}
else {
ip=getFromAPI(pair);//This does API call outside network.
cache.put(pair,ip);
}
context.write(pair,ip);
}
}
我在这里看到的主要问题是
如何在所有节点的缓存中获取大文件。DistributedCache 通过将文件复制到本地节点来工作。但由于这个文件更大,这里涉及到网络流量,对于我的日常工作,我不想继续分发它。
如何高效查找 MapFile(cache),整个 mapFile 不会在内存中。
如何写入作为我的缓存的 MapFile。
谢谢