Es kann keine Jedis-Verbindung hergestellt werden. Es konnte keine Ressource aus dem Pool abgerufen werdenJava

Java-Forum
Anonymous
 Es kann keine Jedis-Verbindung hergestellt werden. Es konnte keine Ressource aus dem Pool abgerufen werden

Post by Anonymous »

Ich erstelle eine Webanwendung und verwende Redis zur Datenspeicherung.
Ich habe JedisPoolConfig (Redis Client-Jedis Version 2.9.0) verwendet.
Wenn ich also meine Anwendung mit Hilfe von Apache Jmeter mit folgenden Konfigurationen teste:

Code: Select all

Number of threads(Users): 30
Ramp-Up period(in seconds) : 0
Loop-Count : 1
und JedisPoolConfig mit folgenden Konfigurationen:

Code: Select all

redis.sentinel.enable=true
redis.sentinel.ip=localhost
redis.sentinel.port=6379
redis.instance.account.masterName=master
redis.pool.max-active = 20
redis.pool.max-idle = 10
mit diesem Code (der beim Start der Spring-Anwendung als Bean erstellt wird):

Code: Select all

JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setPort(port);
factory.setHostName(hostName);
factory.afterPropertiesSet();
factory.setUsePool(true);
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(redisPoolMaxActive);
jedisPoolConfig.setMaxIdle(redisPoolMaxIdle);
factory.setPoolConfig(jedisPoolConfig);
return factory;
mit diesem Code zum Abrufen einer neuen Verbindung jedes Mal, wenn eine Anfrage eingeht:

Code: Select all

@Autowired
private JedisConnectionFactory redisConnectionFactory;
private StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
private RedisTemplate getNewConnection(){
RedisTemplate redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(stringRedisSerializer);
redisTemplate.setHashKeySerializer(stringRedisSerializer);
redisTemplate.setValueSerializer(stringRedisSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
Bearbeiten: meine Verwendung für redisTemplate für multi/exec in Redis:

Code: Select all

redisTemplate.setEnableTransactionSupport(true);

redisTemplate.multi();

for (ArrayList
> pairs : keys){
for (Pair pair: pairs)
redisTemplate.opsForHash().get(makeMap(pair.getFirst(), version) , pair.getSecond());
}

return redisTemplate.exec();
Ich habe die Antwort für 20 Anfragen erfolgreich erhalten, konnte aber für die restlichen 10 Anfragen keine Antwort erhalten. Das Problem, mit dem ich konfrontiert bin, besteht darin, dass, nachdem 20 Verbindungen von den ersten 20 Anfragen verwendet wurden, die restlichen 10 Anfragen nicht in der Lage sind, die Jedis-Verbindung aus dem Pool zu erhalten, und daher erhalte ich die folgende Ausnahme:

Code: Select all

    2017-10-06 17:38:11.753 ERROR 3539 --- [io-8080-exec-12] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool] with root cause

java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:449) ~[commons-pool2-2.4.2.jar:2.4.2]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[commons-pool2-2.4.2.jar:2.4.2]
at redis.clients.util.Pool.getResource(Pool.java:49) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:16) ~[jedis-2.9.0.jar:na]
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:194) ~[spring-data-redis-1.8.6.RELEASE.jar:na]
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:348) ~[spring-data-redis-1.8.6.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:129) ~[spring-data-redis-1.8.6.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisConnectionUtils.bindConnection(RedisConnectionUtils.java:67) ~[spring-data-redis-1.8.6.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:192) ~[spring-data-redis-1.8.6.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169) ~[spring-data-redis-1.8.6.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisTemplate.multi(RedisTemplate.java:868) ~[spring-data-redis-1.8.6.RELEASE.jar:na]
at net.media.mml.redis.repository.RedisRepository.makeTransaction(RedisRepository.java:50) ~[max-data-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at net.media.mml.redis.repository.RedisRepository.getFromRedis(RedisRepository.java:66) ~[max-data-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at net.media.mml.service.DimensionGetter.getDimensions(DimensionGetter.java:64) ~[ml-api.jar:0.0.1-SNAPSHOT]
at net.media.mml.service.MLQueriesGetter.makeQueries(MLQueriesGetter.java:32) ~[ml-api.jar:0.0.1-SNAPSHOT]
at net.media.mml.controller.MaxQueryController.query(MaxQueryController.java:61) ~[ml-api.jar:0.0.1-SNAPSHOT]
at sun.reflect.GeneratedMethodAccessor270.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
Ich habe im Internet gesucht, konnte aber keine Lösung dafür finden. Kann mir jemand helfen?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post