question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why My JedisPool is not so fast

See original GitHub issue

When I use a multi-threaded simple java jar to test the performance of the JedisPool, the avg response time can reach 0.068 per request. Code is as following:

public class TestJedisPool { private static JedisPool pool; static { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(250); config.setMaxIdle(1000 * 60 * 60 * 6); config.setMaxWait(1000); config.setTestOnBorrow(true);

    pool = new JedisPool(config, "anotherhost", 6379);
}
private int total = 20000;
public void setTotal(int total) {
    this.total = total;
}
private int c = 1;
class MyThread extends Thread {
    @Override
    public void run() {

        for (int i = 0; i < TestJedisPool.this.total; i++){
            Jedis jedis = TestJedisPool.pool.getResource();
            jedis.get(String.valueOf(i));
            TestJedisPool.pool.returnResource(jedis);
        }

    }
}
private void setConcurrent(int c) {
    this.c = c;
}
public void test() {
    initInsert();
    testThread();
}

private void initInsert() {
    System.out.println("INIT Insert");
    Jedis jedis = pool.getResource();
    for (int i = 0; i < (TestJedisPool.this.total); i++)
        jedis.set(String.valueOf(i), String.valueOf(i));
    pool.returnResource(jedis);
}

private void testThread() {
    long begin = System.currentTimeMillis();
    System.out.println("BEGIN Test");
    Thread thread[] = new Thread[this.c];
    for (int i = 0; i < thread.length; i++) {
        thread[i] = new MyThread();
        thread[i].start();
    }

    for (int i = 0; i < thread.length; i++) {
        try {
            thread[i].join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    long cost = System.currentTimeMillis() - begin;
    System.out.println("COST:" + cost + " ms");
    System.out.println("AVG:" + ((double)cost / (total*c)));
}

/**
 * @param args
 */
public static void main(String[] args) {
    TestJedisPool test = new TestJedisPool();
    test.setTotal(Integer.parseInt(args[0]));
    test.setConcurrent(Integer.parseInt(args[1]));
    test.test();

}

}

But, When I use loadrunner to test calling a servlet(/testjedis) which uses the jedisPool running in a resin, I found the performance become very low about 20ms per request. The usage of JedisPool is the same as above, and also the JedisPool’s config is the same. The servlet is like this: public class TestRedis extends HttpServlet { private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public TestRedis() {
    super();
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    jedis  = jedisPool.getResource();
        jedis.set(key, value);
        jedisPool.returnResource(jedis);

}

}

When I recorded the time in the code, I found the most time costs is jedisPool.getResource(), What makes getResource becomes slow? Why is there so much different between a resin and a common jar?

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
HeartSaVioRcommented, Jun 4, 2014

@ThomasLau Redis worker thread is single but it uses event driven so we can concurrent within round-trip.

0reactions
imran1609commented, Aug 19, 2016

I have this configuration.

jedisPoolConfig = new JedisPoolConfig()j jedisPoolConfig.setMaxTotal(100); jedispool = new JedisPool(jedisPoolConfig,REDIS_HOST,REDIS_PORT)); jedis = jedispool.getResource();

Performance wise it is not working good ,Can somebody help how do i improve the performance

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why My JedisPool is not so fast · Issue #210 · redis/jedis
When I use a multi-threaded simple java jar to test the performance of the JedisPool, the avg response time can reach 0.068 per...
Read more >
Jedis pool is initialised multiple times - java - Stack Overflow
Here I'm expecting my jedisPool to get initialised only once but it is getting initialised multiple times. Not sure where I'm going wrong....
Read more >
How to optimize Redis with JedisPool - Site24x7 Blog
If so, here's our story of how we fixed the Redis performance issues we were facing by optimizing JedisPool. We hope this will...
Read more >
Read/Connect timeouts to Jedis Cluster - Google Groups
This does not appear to happen, as the shortest time I can make it time-out is 5 seconds. I am using a Jedis...
Read more >
Redis Java Clients – Jedis - My Developer Journal
In previous article we looked at Lettuce as a Java client. In this section we will deep dive into using Jedis as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found