#221 加入对Jedis的封装,又一轮代码改进与注释,新增了JedisPoolConfig的设置函数

This commit is contained in:
Calvin
2013-07-14 00:34:59 +08:00
parent f8ef90f6b0
commit e70ff75ecd
12 changed files with 79 additions and 52 deletions
@@ -56,7 +56,7 @@ public abstract class BenchmarkTask implements Runnable {
} catch (InterruptedException e) {
e.printStackTrace();
}
nextPrintTime = System.currentTimeMillis() + parent.intervalInMills;
nextPrintTime = System.currentTimeMillis() + parent.intervalMillis;
}
@@ -78,25 +78,25 @@ public abstract class BenchmarkTask implements Runnable {
long currentTime = System.currentTimeMillis();
if (currentTime > nextPrintTime) {
long lastIntervalInMills = parent.intervalInMills + (currentTime - nextPrintTime);
nextPrintTime = currentTime + parent.intervalInMills;
long lastIntervalMillis = parent.intervalMillis + (currentTime - nextPrintTime);
nextPrintTime = currentTime + parent.intervalMillis;
long lastRequests = currentRequests - previousRequests;
long totalTimeInMills = currentTime - parent.startTime.getTime();
long totalTimeInSeconds = TimeUnit.MILLISECONDS.toSeconds(totalTimeInMills);
long totalTimeMillis = currentTime - parent.startTime.getTime();
long totalTimeSeconds = TimeUnit.MILLISECONDS.toSeconds(totalTimeMillis);
long totalTps = (currentRequests * 1000) / totalTimeInMills;
long lastTps = (lastRequests * 1000) / lastIntervalInMills;
long totalTps = (currentRequests * 1000) / totalTimeMillis;
long lastTps = (lastRequests * 1000) / lastIntervalMillis;
BigDecimal lastLatency = new BigDecimal(lastIntervalInMills).divide(new BigDecimal(lastRequests), 2,
BigDecimal lastLatency = new BigDecimal(lastIntervalMillis).divide(new BigDecimal(lastRequests), 2,
BigDecimal.ROUND_HALF_UP);
BigDecimal totalLatency = new BigDecimal(totalTimeInMills).divide(new BigDecimal(currentRequests), 2,
BigDecimal totalLatency = new BigDecimal(totalTimeMillis).divide(new BigDecimal(currentRequests), 2,
BigDecimal.ROUND_HALF_UP);
System.out
.printf("Thread %02d process %,d requests after %s seconds. Last tps/latency is %,d/%sms. Total tps/latency is %,d/%sms.\n",
taskSequence, currentRequests, totalTimeInSeconds, lastTps, lastLatency.toString(),
taskSequence, currentRequests, totalTimeSeconds, lastTps, lastLatency.toString(),
totalTps, totalLatency.toString());
previousRequests = currentRequests;
@@ -107,10 +107,10 @@ public abstract class BenchmarkTask implements Runnable {
* 打印线程结果信息.
*/
protected void printThreadFinishMessage() {
long totalTimeInMills = System.currentTimeMillis() - parent.startTime.getTime();
long totalTimeMillis = System.currentTimeMillis() - parent.startTime.getTime();
long totalRequest = parent.loopCount;
long totalTps = (totalRequest * 1000) / totalTimeInMills;
BigDecimal totalLatency = new BigDecimal(totalTimeInMills).divide(new BigDecimal(totalRequest), 2,
long totalTps = (totalRequest * 1000) / totalTimeMillis;
BigDecimal totalLatency = new BigDecimal(totalTimeMillis).divide(new BigDecimal(totalRequest), 2,
BigDecimal.ROUND_HALF_UP);
System.out.printf("Thread %02d finish.Total tps/latency is %,d/%sms\n", taskSequence, totalTps,
@@ -23,7 +23,7 @@ public abstract class ConcurrentBenchmark {
protected CountDownLatch finishLock;
protected Date startTime;
protected int intervalInMills = 10 * 1000;
protected int intervalMillis = 10 * 1000;
public ConcurrentBenchmark(int defaultThreadCount, long defaultLoopCount) {
// merge default setting and system properties
@@ -80,15 +80,15 @@ public abstract class ConcurrentBenchmark {
Date endTime = new Date();
String className = this.getClass().getSimpleName();
long invokeTimes = threadCount * loopCount;
long timeInMills = endTime.getTime() - startTime.getTime();
long tps = (invokeTimes * 1000) / timeInMills;
long totalTimeMillis = endTime.getTime() - startTime.getTime();
long tps = (invokeTimes * 1000) / totalTimeMillis;
System.out.printf("%s finished at %s.\n%d threads processed %,d requests after %,d ms, tps is %,d.\n",
className, endTime.toString(), threadCount, invokeTimes, timeInMills, tps);
className, endTime.toString(), threadCount, invokeTimes, totalTimeMillis, tps);
}
protected void setIntervalInSecondss(int intervalInSeconds) {
this.intervalInMills = intervalInSeconds * 1000;
protected void setIntervalSeconds(int intervalSeconds) {
this.intervalMillis = intervalSeconds * 1000;
}
/**