【发布时间】:2016-06-09 12:03:27
【问题描述】:
我尝试使用一个名为 BlazingCache http://blazingcache.org/ 的开源来为我的应用程序实现协调器缓存的想法。
所以我只是使用 WordCount 示例 https://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html#Example:_WordCount_v2.0 来测试这个缓存库。这是我的全部代码:
public class WordCount2 {
public static class TokenizerMapper
extends Mapper<Object, Text, Text, IntWritable>{
//...
private static Cache<String, String> cache;
@Override
public void setup(Context context) throws IOException,
InterruptedException {
//...
initCache();
}
private void initCache() {
CachingProvider provider = Caching.getCachingProvider();
Properties properties = new Properties();
properties.put("blazingcache.mode","clustered");
properties.put("blazingcache.zookeeper.connectstring","localhost:1281");
properties.put("blazingcache.zookeeper.sessiontimeout","40000");
properties.put("blazingcache.zookeeper.path","/blazingcache");
CacheManager cacheManager = provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader(), properties);
MutableConfiguration<String, String> cacheConfiguration = new MutableConfiguration<>();
cache = cacheManager.createCache("example", cacheConfiguration);
}
@Override
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
//...
cache.put(word.toString(), one.toString());
}
}
}
//...
}
问题出在一行:
cache.put(word.toString(), one.toString());
在地图功能中。
在代码中插入这一行时,整个作业的性能会突然下降。 (我使用 Eclipse 在本地模式下运行 WordCount 示例)。
为什么会发生这种情况,我该如何解决?
【问题讨论】:
标签: java performance hadoop