Update the way the Redis host(s) can be configured for the tests.
There is now a single property : redis-hosts. This property must contain at least 2 host definitions of the form "host:port" (comma separated). Sharding tests need 2 hosts ... If this is not the case, the default value used is "localhost:6379,localhost:6380". Tests that required one host are using the first definition.
This commit is contained in:
@@ -5,13 +5,16 @@ import java.net.UnknownHostException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||
|
||||
public class GetSetBenchmark {
|
||||
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
||||
private static final int TOTAL_OPERATIONS = 100000;
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException,
|
||||
IOException {
|
||||
Jedis jedis = new Jedis("localhost");
|
||||
Jedis jedis = new Jedis(hnp.host, hnp.port);
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
|
||||
@@ -6,13 +6,16 @@ import java.util.Calendar;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPipeline;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||
|
||||
public class PipelinedGetSetBenchmark {
|
||||
private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
|
||||
private static final int TOTAL_OPERATIONS = 200000;
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException,
|
||||
IOException {
|
||||
Jedis jedis = new Jedis("localhost");
|
||||
Jedis jedis = new Jedis(hnp.host, hnp.port);
|
||||
jedis.connect();
|
||||
jedis.auth("foobared");
|
||||
jedis.flushAll();
|
||||
|
||||
@@ -5,16 +5,20 @@ import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil;
|
||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||
|
||||
public class PoolBenchmark {
|
||||
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("localhost");
|
||||
Jedis j = new Jedis(hnp.host, hnp.port);
|
||||
j.connect();
|
||||
j.auth("foobared");
|
||||
j.flushAll();
|
||||
@@ -24,7 +28,7 @@ public class PoolBenchmark {
|
||||
// withoutPool();
|
||||
withPool();
|
||||
long elapsed = System.currentTimeMillis() - t;
|
||||
System.out.println(((1000 * 3 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
||||
System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
|
||||
}
|
||||
|
||||
private static void withoutPool() throws InterruptedException {
|
||||
@@ -35,7 +39,7 @@ public class PoolBenchmark {
|
||||
Thread hj = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Jedis j = new Jedis("localhost");
|
||||
Jedis j = new Jedis(hnp.host, hnp.port);
|
||||
try {
|
||||
j.connect();
|
||||
j.auth("foobared");
|
||||
@@ -59,31 +63,37 @@ public class PoolBenchmark {
|
||||
}
|
||||
|
||||
private static void withPool() throws InterruptedException {
|
||||
final JedisPool pool = new JedisPool("localhost");
|
||||
pool.setResourcesNumber(1000);
|
||||
pool.setDefaultPoolWait(20);
|
||||
final JedisPool pool = new JedisPool(hnp.host, hnp.port,
|
||||
2000, "foobared");
|
||||
pool.setResourcesNumber(50);
|
||||
pool.setDefaultPoolWait(1000000);
|
||||
pool.init();
|
||||
List<Thread> tds = new ArrayList<Thread>();
|
||||
|
||||
for (int i = 0; i < TOTAL_OPERATIONS; i++) {
|
||||
final String key = "foo" + i;
|
||||
final AtomicInteger ind = new AtomicInteger();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
Thread hj = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Jedis j = pool.getResource();
|
||||
j.auth("foobared");
|
||||
j.set(key, key);
|
||||
j.get(key);
|
||||
pool.returnResource(j);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
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();
|
||||
|
||||
pool.destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user