-
Mar 22nd, 2013, 05:53 PM
#1
web application with PostgreSQL DB and JEDIS (REDIS)
Hi, I used in my web application (Spring, JSP, Tomcat) TWO connections:
- connection to REDIS by JEDIS connector (jedis-2.1.0.jar)
- connection to PostgreSQL DB (JDBC driver: postgresql-9.1-901.jdbc4.jar).
REDIS server version: 2.4 (windows version)
JEDIS version: 2.1.0
connection pool: apache commons pool version 1.6
tomcat version: 7.0.29
integration REDIS with spring: spring-data-redis-1.0.3.RELEASE.jar
everythink is OK, but after a few minutes application freezes. I debug my application, and I think problem is in connection pool in class: org.apache.commons.pool.impl.GenericObjectPool, in function
public T borrowObject() throws Exception {
...
if (latch.getPair() == null && !latch.mayCreate()) {
if(maxWait <= 0) {
latch.wait();
because, latch.getPair() = null, maxWait is -1 and latch.mayCreate() == false, so latch.wait is executed, and application freezes.
I think problem is, there is only one connection pool for JDCB connection to PostgreSQL and for JEDIS.
please, how can I define two independent connection pools, or there is another problem?
thanks for you advice
examples of usage o JEDIS from my application:
1.
RedisTemplate<String, String> redisTemplate = (RedisTemplate<String, String>) BeanUtil.getBean("redisTemplate");
return redisTemplate.boundZSetOps(set).incrementScore(key , value);
2.
RedisTemplate<String, String> redisTemplate = (RedisTemplate<String, String>) BeanUtil.getBean("redisTemplate");
Set<Tuple> mostViewed = redisTemplate.execute(new RedisCallback<Set<Tuple>>() {
@Override
public Set<Tuple> doInRedis(RedisConnection con)
throws DataAccessException {
Set<Tuple> zRangeByScoreWithScore = con.zRangeByScoreWithScores(ARTICLE_VIEWS_SET.getB ytes(), 1, 10);
return zRangeByScoreWithScore;
}
});
---
jedisConnectionFactory definition:
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.j edis.JedisConnectionFactory">
<property name="hostName" value="${redis.host}"/>
<property name="port" value="${redis.port}"/>
<property name="timeout" value="2000"/>
</bean>
Ivan
Last edited by termix; Mar 22nd, 2013 at 06:06 PM.
-
Mar 26th, 2013, 11:30 AM
#2
I don't think your Postgres and Jedis connections are sharing a pool, as the JedisConnectionFactory creates a new pool instance. It seems you are using RedisTemplate in a fairly standard way, so connections should be getting returned to the pool, though you can set a breakpoint in JedisConnection.close() or JedisPool.returnResource() to verify. You may also want to check JedisPool.returnBrokenResource(), perhaps the connections are all getting invalidated somehow?
If the pause is temporary and you do have a lot of concurrent active connections to Redis, you may need to adjust the poolConfig attribute of JedisConnectionFactory to increase your pool size, maxWait, etc.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules