Skip to content

Commit

Permalink
1. Benchmark tests for JOhm beginning with save-get benchmark.
Browse files Browse the repository at this point in the history
2. Support for reuse of jedis connection for bulk remote operations.
  • Loading branch information
Jonathan Leibiusky committed Oct 12, 2010
1 parent 33f9211 commit 06126c1
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 68 deletions.
20 changes: 0 additions & 20 deletions src/main/java/redis/clients/johm/JOhm.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,26 +215,6 @@ public static void setPool(JedisPool jedisPool) {
Nest.setJedisPool(jedisPool);
}

/**
* If this is set to true, it results in JOhm performing remote operations
* using the same cached remote connection. This mode will likely result in
* significant speed-up for bulk-operations but users need to exercise
* caution while using this.
*
* A recommended usage pattern is:<br>
* setReuseConnectionMode(true);<br>
* ....do a bunch of operations<br>
* setReuseConnectionMode(false);
*
* @param reuseCachedConnection
*/
public static void setReuseConnectionMode(boolean reuseCachedConnection) {
Nest.setReuseConnectionMode(reuseCachedConnection);
}

public static boolean isReuseConnectionMode() {
return Nest.isReuseConnectionMode();
}

protected JOhm() {
nest = new Nest(this);
Expand Down
32 changes: 2 additions & 30 deletions src/main/java/redis/clients/johm/Nest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public class Nest {
private StringBuilder sb;
private String key;
private static JedisPool jedisPool;
private static volatile boolean reuseConnectionMode;
private static Jedis cachedConnection;

public static void setJedisPool(JedisPool jedisPool) {
Nest.jedisPool = jedisPool;
Expand All @@ -44,23 +42,6 @@ public Nest(JOhm jOhm) {
this.key = jOhm.getClass().getSimpleName();
}

public static boolean isReuseConnectionMode() {
return reuseConnectionMode;
}

public static synchronized void setReuseConnectionMode(
boolean reuseConnectionMode) {
Nest.reuseConnectionMode = reuseConnectionMode;
if (!reuseConnectionMode) {
if (cachedConnection != null) {
if (jedisPool != null) {
returnResource(cachedConnection);
}
cachedConnection = null;
}
}
}

public String key() {
prefix();
String generatedKey = sb.toString();
Expand Down Expand Up @@ -250,21 +231,12 @@ public List<String> lrange(int start, int end) {
}

private static void returnResource(final Jedis jedis) {
if (!reuseConnectionMode) {
jedisPool.returnResource(jedis);
}
jedisPool.returnResource(jedis);
}

private static Jedis getResource() {
Jedis jedis;
if (reuseConnectionMode) {
if (cachedConnection == null) {
cachedConnection = getJedisHandle();
}
jedis = cachedConnection;
} else {
jedis = getJedisHandle();
}
jedis = getJedisHandle();
return jedis;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected void printStats(String test, int totalOps, int opTypes,
stats.append(", opTypes=").append(opTypes);
stats.append(", thruput=")
.append((1000 * opTypes * totalOps) / elapsed).append(
" ops/sec");
" ops");
System.out.println(stats);
}
}
17 changes: 0 additions & 17 deletions src/test/java/redis/clients/johm/benchmark/SaveGetBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,4 @@ public void saveGetModel() {
timer.end();
printStats("saveGetModel", totalOps, 2, timer.elapsed());
}

@Test
public void saveGetModelReuseConnection() {
int totalOps = 5000;
JOhm.setReuseConnectionMode(true);
timer.begin();
for (int n = 0; n <= totalOps; n++) {
User user = new User();
user.setName("foo" + n);
user.setRoom("vroom" + n);
user.save();
JOhm.get(User.class, user.getId());
}
timer.end();
printStats("saveGetModelReuseConnection", totalOps, 2, timer.elapsed());
JOhm.setReuseConnectionMode(false);
}
}

0 comments on commit 06126c1

Please sign in to comment.