2017-09-04 84 views
1

我遇到了使用Redis和Jedis連接池的問題。Jedis連接未被釋放

我看到的行爲是在連接建立之後,它們不會被釋放回連接池。

我知道這一點,因爲使用redis-cli client list命令我可以看到連接仍然懸而未決。

有人可以查看我的jedis連接池,讓我知道如果這可能導致問題。

 <spring:bean id="ElasticachePoolConfig" name="ElasticachePoolConfig" class="redis.clients.jedis.JedisPoolConfig" > 

     <!-- Minimum number of idle connections to Redis - these can be seen as always open and ready to serve --> 
     <spring:property name="minIdle" value="${redis.minIdle}" /> 

     <!-- Number of connections to Redis that just sit there and do nothing --> 
     <spring:property name="maxIdle" value="${redis.maxIdle}" /> 

     <!-- Maximum number of active connections that can be allocated from this pool at the same time --> 
     <spring:property name="maxTotal" value="${redis.maxTotal}" /> 

     <!-- The minimum amount of time an object may sit idle in the pool before it is eligable for eviction by the idle object evictor.--> 
     <spring:property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}" /> 

     <!-- The minimum amount of time a connection may sit idle in the pool before it is eligible for eviction by the idle connection evictor --> 
     <spring:property name="softMinEvictableIdleTimeMillis" value="${redis.softMinEvictableIdleTimeMillis}" /> 

     <!-- The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception --> 
     <spring:property name="maxWaitMillis" value="${redis.maxWaitMillis}" /> 

     <!-- Maximum number of connections to test in each idle check --> 
     <spring:property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}" /> 

     <!-- Tests whether connection is dead when connection retrieval method is called --> 
     <spring:property name="testOnBorrow" value="${redis.testOnBorrow}" /> 

     <!-- Tests whether connection is dead when returning a connection to the pool --> 
     <spring:property name="testOnReturn" value="${redis.testOnReturn}" /> 

     <!-- Tests whether connections are dead during idle periods --> 
     <spring:property name="testWhileIdle" value="${redis.testWhileIdle}" /> 

     <!-- Idle connection checking period --> 
     <spring:property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}" /> 

     <spring:property name="blockWhenExhausted" value="${redis.blockWhenExhausted}" /> 

    </spring:bean> 

,其中屬性設置如下......

redis.port=6379 
redis.timeout=2000 
redis.ttl=600 
redis.host=localhost 
redis.repeater.maxRetries=3 
redis.repeater.millisBetweenRetries=2000 
redis.minIdle=5 
redis.maxIdle=10 
redis.maxTotal=8 
redis.minEvictableIdleTimeMillis=30000 
redis.softMinEvictableIdleTimeMillis=-1 
redis.maxWaitMillis=5000 
redis.numTestsPerEvictionRun=10 
redis.testOnBorrow=true 
redis.testOnReturn=true 
redis.testWhileIdle=false 
redis.timeBetweenEvictionRunsMillis=50000 
redis.blockWhenExhausted=true 
+0

「我看到的行爲是在建立連接後,它們不會被釋放回連接池中,我知道這是因爲使用redis-cli客戶端列表命令,我可以看到連接仍處於閒置狀態。」不合邏輯的推論。連接應該留在周圍。您將*打開*連接放回到連接池中,而不是關閉的:) – hobbs

+0

嗨@hobbs感謝您的回覆。你是對的。但是在驅逐運行時,連接不應該回落到我的最小空閒連接? – Richie

+0

它應該下降到不超過'maxIdle'。 – hobbs

回答

0

maxIdle設置比你maxTotal設定較大,所以沒有有效的連接將被閒置釋放。該池將保持maxIdle連接。

JedisPool在內部使用Apache Commons Pooling。有關maxIdlemaxTotal之間的差異,請參閱this answer