AWS Redis: JedisConnectionException: java.net.SocketException: слишком много открытых файлов - PullRequest
0 голосов
/ 04 июля 2018

Я настроил redis с помощью AWS Elasticache и подключил его через tomcat, установленный на AWS EC2.

Ниже мой код:

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 для открытых файлов, настроить JedisPoolConfig для maxTotal, maxIdle, minIdle и т. Д., Но безуспешно.

Пожалуйста, предложите.

...