Disabled logging in JedisPool benchmark

This commit is contained in:
Jonathan Leibiusky
2010-10-14 09:12:41 -03:00
parent 3f21dcd0eb
commit 99a50db3ea

View File

@@ -6,94 +6,69 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger; 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.Jedis;
import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPool;
import redis.clients.jedis.tests.HostAndPortUtil; import redis.clients.jedis.tests.HostAndPortUtil;
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort; import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
import redis.clients.util.FixedResourcePool;
public class PoolBenchmark { 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; private static final int TOTAL_OPERATIONS = 100000;
public static void main(String[] args) throws UnknownHostException, public static void main(String[] args) throws UnknownHostException,
IOException, TimeoutException, InterruptedException { IOException, TimeoutException, InterruptedException {
Jedis j = new Jedis(hnp.host, hnp.port); Logger logger = Logger.getLogger(FixedResourcePool.class.getName());
j.connect(); logger.setLevel(Level.OFF);
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 withoutPool() throws InterruptedException { Jedis j = new Jedis(hnp.host, hnp.port);
List<Thread> tds = new ArrayList<Thread>(); j.connect();
j.auth("foobared");
for (int i = 0; i < TOTAL_OPERATIONS; i++) { j.flushAll();
final String key = "foo" + i; j.quit();
Thread hj = new Thread(new Runnable() { j.disconnect();
@Override long t = System.currentTimeMillis();
public void run() { // withoutPool();
Jedis j = new Jedis(hnp.host, hnp.port); withPool();
try { long elapsed = System.currentTimeMillis() - t;
j.connect(); System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
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();
}
} }
private static void withPool() throws InterruptedException { private static void withPool() throws InterruptedException {
final JedisPool pool = new JedisPool(hnp.host, hnp.port, final JedisPool pool = new JedisPool(hnp.host, hnp.port, 2000,
2000, "foobared"); "foobared");
pool.setResourcesNumber(50); pool.setResourcesNumber(50);
pool.setDefaultPoolWait(1000000); pool.setDefaultPoolWait(1000000);
pool.init(); pool.init();
List<Thread> tds = new ArrayList<Thread>(); List<Thread> tds = new ArrayList<Thread>();
final AtomicInteger ind = new AtomicInteger(); final AtomicInteger ind = new AtomicInteger();
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
Thread hj = new Thread(new Runnable() { Thread hj = new Thread(new Runnable() {
public void run() { public void run() {
for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) { for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) {
try { try {
Jedis j = pool.getResource(); Jedis j = pool.getResource();
final String key = "foo" + i; final String key = "foo" + i;
j.set(key, key); j.set(key, key);
j.get(key); j.get(key);
pool.returnResource(j); pool.returnResource(j);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
}); });
tds.add(hj); tds.add(hj);
hj.start(); hj.start();
} }
for (Thread t : tds) for (Thread t : tds)
t.join(); t.join();
pool.destroy(); pool.destroy();
} }
} }