2016-06-09 27 views
0

我尝试使用开源代码,即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示例)。
为什么会发生这种情况,我该如何解决?

回答

0

我不确定问题的原因是什么,您可以尝试检查日志并在blazingcache.xxx记录器中查找“连接事件”和异常。

请注意,Cache.put必须最终通知其他客户端托管数据的副本,这是一个网络操作。在这样的MapReduce作业中,很多客户端可能会持有对同一个“单词”的引用。请记住关闭CacheManager,因为每个CacheManager都会创建一个CacheClient,因此它会保留资源并接收通知。

当底层CacheClient以断开模式工作时,它可能会变慢,因为如果没有连接到缓存服务器,它不能保证缓存的一致性,因此它试图连接很长时间。

我已复制你的情况下,你必须编辑这些行:

1),你必须“创造”缓存只有一次

try { 
    cache = cacheManager.createCache("example", cacheConfiguration); 
} catch (CacheException alreadyCreated) {     
} 
cache = cacheManager.getCache("example"); 

2)不要使用静态参考缓存 3)除去这使得高速缓存服务器的发现

properties.put("blazingcache.mode", "clustered"); 

随着示例代码运行得非常好这些变化的线。

如果你想以真正的集群模式运行,你必须启动一个zookkeeper集群和至少一个blazingcache服务器。 没有饲养员我得到这个错误循环:

16/07/08 13时26分14秒INFO zookeeper.ClientCnxn:打开套接字连接 到服务器的localhost.localdomain/127.0.0.1:1281。不会尝试 使用SASL进行身份验证(未知错误)16/07/08 13:26:14 WARN zookeeper.ClientCnxn:服务器null的会话0x0,意外错误, 关闭套接字连接并尝试重新连接 java.net.ConnectException :CONNESSIONE rifiutata在 sun.nio.ch.SocketChannelImpl.checkConnect(本机方法)在 sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) 在 org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO .java:361) at org.apache.zookeeper.ClientCnxn $ SendThread.run(ClientCnxn。java:1081) 16/07/08 13:26:15信息mapreduce.Job:Job job_local7226039_0001 以超级模式运行:false 16/07/08 13:26:15信息mapreduce.Job: map 0%reduce 0 %16/07/08 13:26:16信息zookeeper.ClientCnxn:打开 套接字连接到服务器localhost.localdomain/127.0.0.1:1281。将 不尝试使用SASL(未知错误)16/07/08 13点26分16秒WARN验证zookeeper.ClientCnxn:服务器空, 意外错误,关闭套接字连接,并试图会议为0x0重新

你应该在blazingcache支持邮件列表

+0

感谢您的回答! – nd07

0

求人如果你在一个你最好删除这些行,然后重试本地模式(单JVM)测试:

properties.put("blazingcache.mode","clustered");   
properties.put("blazingcache.zookeeper.connectstring","localhost:1281"); 
properties.put("blazingcache.zookeeper.sessiontimeout","40000");   
properties.put("blazingcache.zookeeper.path","/blazingcache");