From 99a50db3ea2915ec5d3e942d1b030a2409c55c72 Mon Sep 17 00:00:00 2001 From: Jonathan Leibiusky Date: Thu, 14 Oct 2010 09:12:41 -0300 Subject: [PATCH] Disabled logging in JedisPool benchmark --- .../jedis/tests/benchmark/PoolBenchmark.java | 119 +++++++----------- 1 file changed, 47 insertions(+), 72 deletions(-) diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/PoolBenchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/PoolBenchmark.java index 1a892c8..e02742f 100644 --- a/src/test/java/redis/clients/jedis/tests/benchmark/PoolBenchmark.java +++ b/src/test/java/redis/clients/jedis/tests/benchmark/PoolBenchmark.java @@ -6,94 +6,69 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Level; +import java.util.logging.Logger; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.tests.HostAndPortUtil; import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort; +import redis.clients.util.FixedResourcePool; public class PoolBenchmark { - private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0); + private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0); private static final int TOTAL_OPERATIONS = 100000; public static void main(String[] args) throws UnknownHostException, - IOException, TimeoutException, InterruptedException { - Jedis j = new Jedis(hnp.host, hnp.port); - j.connect(); - j.auth("foobared"); - j.flushAll(); - j.quit(); - j.disconnect(); - long t = System.currentTimeMillis(); - // withoutPool(); - withPool(); - long elapsed = System.currentTimeMillis() - t; - System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); - } + IOException, TimeoutException, InterruptedException { + Logger logger = Logger.getLogger(FixedResourcePool.class.getName()); + logger.setLevel(Level.OFF); - private static void withoutPool() throws InterruptedException { - List tds = new ArrayList(); - - for (int i = 0; i < TOTAL_OPERATIONS; i++) { - final String key = "foo" + i; - Thread hj = new Thread(new Runnable() { - @Override - public void run() { - Jedis j = new Jedis(hnp.host, hnp.port); - try { - j.connect(); - j.auth("foobared"); - j.set(key, key); - j.get(key); - j.quit(); - j.disconnect(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - tds.add(hj); - hj.start(); - } - for (Thread thread : tds) { - thread.join(); - } + Jedis j = new Jedis(hnp.host, hnp.port); + j.connect(); + j.auth("foobared"); + j.flushAll(); + j.quit(); + j.disconnect(); + long t = System.currentTimeMillis(); + // withoutPool(); + withPool(); + long elapsed = System.currentTimeMillis() - t; + System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops"); } private static void withPool() throws InterruptedException { - final JedisPool pool = new JedisPool(hnp.host, hnp.port, - 2000, "foobared"); - pool.setResourcesNumber(50); - pool.setDefaultPoolWait(1000000); - pool.init(); - List tds = new ArrayList(); + final JedisPool pool = new JedisPool(hnp.host, hnp.port, 2000, + "foobared"); + pool.setResourcesNumber(50); + pool.setDefaultPoolWait(1000000); + pool.init(); + List tds = new ArrayList(); - final AtomicInteger ind = new AtomicInteger(); - for (int i = 0; i < 50; i++) { - Thread hj = new Thread(new Runnable() { - public void run() { - for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) { - try { - Jedis j = pool.getResource(); - final String key = "foo" + i; - j.set(key, key); - j.get(key); - pool.returnResource(j); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - }); - tds.add(hj); - hj.start(); - } + final AtomicInteger ind = new AtomicInteger(); + for (int i = 0; i < 50; i++) { + Thread hj = new Thread(new Runnable() { + public void run() { + for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) { + try { + Jedis j = pool.getResource(); + final String key = "foo" + i; + j.set(key, key); + j.get(key); + pool.returnResource(j); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + }); + tds.add(hj); + hj.start(); + } - for (Thread t : tds) - t.join(); + for (Thread t : tds) + t.join(); - pool.destroy(); + pool.destroy(); } } \ No newline at end of file