Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jedis connection settings for high performance and reliablity

I am using Jedis client for connecting to my Redis server. The following are the settings I'm using for connecting with Jedis (using apache common 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 with these setting I'm not facing any issues in terms of reliability (I can always get the Jedis connection whenever I want), but I am seeing a certain lag with Jedis performance.

Can any one suggest me some more optimization for achieving high performance?

like image 928
pjain Avatar asked Mar 27 '15 16:03

pjain


1 Answers

You have 3 tests configured:

  • TestOnBorrow - Sends a PING request when you ask for the resource.
  • TestOnReturn - Sends a PING whe you return a resource to the pool.
  • TestWhileIdle - Sends periodic PINGS from idle resources in the pool.

While it is nice to know your connections are still alive, those onBorrow PING requests are wasting an RTT before your request, and the other two tests are wasting valuable Redis resources. In theory, a connection can go bad even after the PING test so you should catch a connection exception in your code and deal with it even if you send a PING. If your network is stable, and you do not have too many drops, you should remove those tests and handle this scenario in your exception catches only.

Also, by setting MaxIdle == MaxTotal, there will be no eviction of resources from your pool (good/bad?, depends on your usage). And when your pool is exhausted, an attempt to get a resource will endup in timeout after 2 minutes of waiting for a free resource.

like image 126
Ofir Luzon Avatar answered Sep 19 '22 19:09

Ofir Luzon