2

In Spring, I have a jedisConnFactory and a jedisPoolConfig bean like this

    <bean id="jedisConnFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="127.0.0.1" p:port="6379" p:poolConfig-ref="jedisPoolConfig" />

    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal" value="${redis.pool.maxTotal}" />
        <property name="maxIdle" value="${redis.pool.maxIdle}" />
        <property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}" />
    </bean>

Sending data to server is OK. But I do not know how to verify if the JedisPoll is working.

How can I check the number of Active, Idle connection?

2 Answers 2

2

we can get the metrics by Java reflection:

      Field poolField = JedisConnectionFactory.class.getDeclaredField("pool");
  poolField.setAccessible(true);
  Pool<Jedis> jedisPool = (Pool<Jedis>)poolField.get(connectionFactory);
  int activeNum = jedisPool.getNumActive();
  int idleNum = jedisPool.getNumIdle();
  int waitNum = jedisPool.getNumWaiters();
  long maxBorrowWaitMs = jedisPool.getMaxBorrowWaitTimeMillis();
  long meanBorrowWaitMs = jedisPool.getMeanBorrowWaitTimeMillis();

output:

pool monitor - activeNum=0,idleNum=1,waitNum=0, maxBorrowWaitMs=7, meanBorrowWaitMs=0
Sign up to request clarification or add additional context in comments.

Comments

0

Make sure, that JMX is enabled in your pool configuration. Note that GenericObjectPoolConfig can also be passed, which gives you full control on your object pool. Then, you can connect to your application through JMX with jconsole and you can track the actual state of your connection pool.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.