#171 Redis的Benchmark测试用例, 微调
This commit is contained in:
+2
-2
@@ -25,7 +25,7 @@ public class RedisMassInsertionBenchmark extends ConcurrentBenchmark {
|
||||
private static final int PORT = Protocol.DEFAULT_PORT;
|
||||
private static final int TIMEOUT = 40000;
|
||||
|
||||
private String keyPrefix = "springside.key_";
|
||||
private String keyPrefix = "springside.map:";
|
||||
private JsonMapper jsonMapper = new JsonMapper();
|
||||
private JedisPool pool;
|
||||
|
||||
@@ -79,7 +79,7 @@ public class RedisMassInsertionBenchmark extends ConcurrentBenchmark {
|
||||
Pipeline pl = jedis.pipelined();
|
||||
|
||||
for (int i = 0; i < loopCount; i++) {
|
||||
String key = new StringBuilder().append(keyPrefix).append(threadIndex).append("_").append(i)
|
||||
String key = new StringBuilder().append(keyPrefix).append(threadIndex).append(":").append(i)
|
||||
.toString();
|
||||
Session session = new Session(key);
|
||||
session.setAttrbute("name", key);
|
||||
|
||||
+9
-4
@@ -1,5 +1,7 @@
|
||||
package org.springside.examples.showcase.demos.redis;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import org.springside.modules.mapper.JsonMapper;
|
||||
import org.springside.modules.test.benchmark.BenchmarkTask;
|
||||
import org.springside.modules.test.benchmark.ConcurrentBenchmark;
|
||||
@@ -23,7 +25,7 @@ public class RedisSessionBenchmark extends ConcurrentBenchmark {
|
||||
private static final int PORT = Protocol.DEFAULT_PORT;
|
||||
private static final int TIMEOUT = Protocol.DEFAULT_TIMEOUT;
|
||||
|
||||
private String keyPrefix = "springside.key_";
|
||||
private String keyPrefix = "springside.map:";
|
||||
private JsonMapper jsonMapper = new JsonMapper();
|
||||
private JedisPool pool;
|
||||
|
||||
@@ -63,6 +65,8 @@ public class RedisSessionBenchmark extends ConcurrentBenchmark {
|
||||
}
|
||||
|
||||
public class SessionTask extends BenchmarkTask {
|
||||
private SecureRandom random = new SecureRandom();
|
||||
|
||||
public SessionTask(int index, ConcurrentBenchmark parent, int printBetweenSeconds) {
|
||||
super(index, parent, printBetweenSeconds);
|
||||
}
|
||||
@@ -74,12 +78,13 @@ public class RedisSessionBenchmark extends ConcurrentBenchmark {
|
||||
|
||||
try {
|
||||
for (int i = 0; i < loopCount; i++) {
|
||||
//set session expired after 300 seconds
|
||||
String key = new StringBuilder().append(keyPrefix).append(threadIndex).append("_").append(i)
|
||||
.toString();
|
||||
int randomIndex = random.nextInt((int) loopCount);
|
||||
String key = new StringBuilder().append(keyPrefix).append(threadIndex).append(":")
|
||||
.append(randomIndex).toString();
|
||||
Session session = new Session(key);
|
||||
session.setAttrbute("name", key);
|
||||
session.setAttrbute("seq", i);
|
||||
//set session expired after 300 seconds
|
||||
jedis.setex(session.getId(), 300, jsonMapper.toJson(session));
|
||||
|
||||
//get it back
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.math.BigDecimal;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Beanchmark中任务线程的基类.
|
||||
* Benchmark中任务线程的基类.
|
||||
*
|
||||
* @see ConcurrentBenchmark
|
||||
*/
|
||||
|
||||
+4
-4
@@ -6,8 +6,8 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 多线程Benchmark测试框架.
|
||||
* 使用JDK Concurrency中的CountDownLatch精确控制多线程中的测试任务启动与停止及计时.
|
||||
* 多线程Benchmark测试框架. 提供多线程调度及定时的测试进度, tps/latency信息打印.
|
||||
* 为方便移植重用, 无任何第三方类库依赖.
|
||||
*
|
||||
* @author calvin
|
||||
*/
|
||||
@@ -79,13 +79,13 @@ public abstract class ConcurrentBenchmark {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to do some global data prepare job.
|
||||
* Override to do some resource connect and global data prepare job.
|
||||
*/
|
||||
protected void onStart() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to do some global data cleanup and verify job.
|
||||
* Override to do some resource cleanup, result verify and global data cleanup job.
|
||||
*/
|
||||
protected void onFinish() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user