Jedis永远阻止与亚马逊的连接

时间:2014-04-03 19:15:16

标签: java amazon-web-services redis jedis

您好我正在调试Jedis与Amazon Elasticache Redis 2.6.13进行交谈

我遇到了Jedis无法获得连接的问题。目前,我正在使用所有默认值,并且我发现当我尝试建立连接时它总是会永久阻塞。即这个电话阻止

            Jedis jedis = jedisPool.getResource();

但是,如果我暂时离开服务器一段时间,它似乎再次起作用。这表明Jedis正在使用某些东西,并最终通过较低级别进行清理。

我相信我的配置存在问题,但我的笔记本电脑上的Redis可以正常使用(2.6.10)

我在2011年发现了一个关于配置的博客,其中间有一个非常有趣的句子

http://biasedbit.com/redis-jedispool-configuration/

"The annoyance here is that in a JedisPool by default, connections will die of inactivity and no new ones will be spawned."

我还看到了一些问题,表明Jedis每次都会创建一个新连接,并且不会重用现有连接。例如

https://groups.google.com/forum/#!topic/jedis_redis/H3FhLtwkDo8

是否有人将Jedis与Amazon Elasticache一起使用?它对你有用吗?你的配置是什么?

此外,是否有人认识到上述问题。如何避免/修复它们?

谢谢 彼得

1 个答案:

答案 0 :(得分:3)

以下是更新:

JedisConfig具有maxTotal和maxIdle调整参数

    JedisPoolConfig poolConfig = new JedisPoolConfig(); 
    // default 8 : Maximum active connections to Redis instance
    poolConfig.setMaxTotal(maxTotal);  
    // default 8 : Maximum number of idle connections to Redis
    poolConfig.setMaxIdle(maxIdle);   

Jedis显然很贪婪,并且会创造许多联系,即使它不需要。

我将max设置为100并运行3台服务器。

不幸的是,Amazon Redis实例似乎只有大约128个可用连接,所以我的服务器相互挨饿。

使用Amazon Elasticache控制台,我能够看到服务器重启之前的连接数量增加