我尝试使用开源代码,即BlazingCache http://blazingcache.org/为我的应用程序实现协调器缓存理念。在Hadoop中使用BlazingCache开源会降低性能
所以我只是使用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示例)。
为什么会发生这种情况,我该如何解决?
感谢您的回答! – nd07