gpt4 book ai didi

amazon-web-services - AWS Redis : JedisConnectionException: java.net.SocketException:打开的文件太多

转载 作者:行者123 更新时间:2023-12-03 06:37:39 26 4
gpt4 key购买 nike

我已经使用 AWS Elasticache 配置了 redis,并通过安装在 AWS EC2 上的 tomcat 连接了它。

以下是我的代码:

private JedisPool jedisPool = null;

@PostConstruct
private void initialiseJedisPools() {
try {
String redisHost = RESOURCES.getProperty("redis.master.host");
if(Objects.nonNull(redisHost)) {
Integer redisPort = Integer.valueOf(RESOURCES.getProperty("redis.master.port"));
jedisPool = new JedisPool(redisHost, redisPort);
}
} catch (NumberFormatException exception) {
logger.error("Exception occurred while initialising jedis pool.", exception);
}
}

public void addKey(String key, String value, Integer secondsToExpire) {
if (Objects.nonNull(jedisPool)) {
try (Jedis jedis = jedisPool.getResource()) {
jedis.set(key, value);
if (Objects.nonNull(secondsToExpire)) {
jedis.expire(key, secondsToExpire.intValue());
}
} catch (JedisException jedisException) {
logger.error("Exception thrown while adding key in cache.", jedisException);
}
}
}

经常出现以下错误,我必须重新启动 tomcat 才能使其正常工作。

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
.
.
.
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Too many open files
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:49)
... 10 more
Caused by: java.net.SocketException: Too many open files
at java.net.Socket.createImpl(Socket.java:460)
at java.net.Socket.getImpl(Socket.java:520)
at java.net.Socket.setReuseAddress(Socket.java:1449)
at redis.clients.jedis.Connection.connect(Connection.java:174)
... 17 more

我尝试增加打开文件的ulimit,为maxTotalmaxIdle配置JedisPoolConfigminIdle 等,但没有成功。

请提出建议。

最佳答案

我们过去也遇到过类似的问题,jedis 连接错误“java.net.SocketException:打开的文件太多”

发生这种情况是因为 jedis 连接没有关闭。

call jedisPool.returnResourse(jedis) or jedis.close()

关于amazon-web-services - AWS Redis : JedisConnectionException: java.net.SocketException:打开的文件太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51173256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com