我嘗試使用開源代碼,即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