Jedis connection settings for high performance and reliability

I am using a Jedis client to connect to my Redis server. The following are the settings I use to connect to Jedis (using a shared Apache pool):

JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setTestOnBorrow(true); poolConfig.setTestOnReturn(true); poolConfig.setMaxIdle(400); // Tests whether connections are dead during idle periods poolConfig.setTestWhileIdle(true); poolConfig.setMaxTotal(400); // configuring it for some good max value so that timeout don't occur poolConfig.setMaxWaitMillis(120000); 

So far, I have not encountered any problems with these settings in terms of reliability (I can always get a Jedis connection when I want), but I see some lag behind Jedis performance.

Can someone suggest me another optimization for high performance?

+7
apache-commons redis jedis
source share
1 answer

You have 3 tests configured:

  • TestOnBorrow - Sends a PING request when requesting a resource.
  • TestOnReturn - Sends PING, and you return the resource to the pool.
  • TestWhileIdle - Sends periodic PINGS from unallocated resources in the pool.

While it’s good to know that your connections are still alive, those onBorrow PING requests spend RTT before your request, and the other two tests waste valuable Redis resources. Theoretically, the connection may get worse even after the PING test, so you should catch the connection exception in your code and deal with it even if you send the PING. If your network is stable and you do not have too many drops, you should remove these tests and process this scenario only with your exceptions.

Also, by setting MaxIdle == MaxTotal, you will not evict resources from your pool (good / bad?, Depends on your use). And when your pool is exhausted, an attempt to get a resource will end in a timeout after 2 minutes of waiting for a free resource.

+13
source share

All Articles