Skip to content

Commit

Permalink
添加了warmup;
Browse files Browse the repository at this point in the history
javassist测试完毕,性能略下降,弃用
  • Loading branch information
songxinjianqwe committed Aug 26, 2018
1 parent 8921a4f commit 7a7b042
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 1,214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,25 @@ public abstract class AbstractClient {
private ExecutorService executorService;
private UserService userService;
private int measurementIterations;
private int warmupIterations;

protected abstract UserService getUserService();

public void run(int threads, int requestsTotal, int measurementIterations) {

public void run(String ...strings){
int threads = Integer.parseInt(strings[0]);
int requestTotal = Integer.parseInt(strings[1]);
int warmupIterations = Integer.parseInt(strings[2]);
int measurementIterations = Integer.parseInt(strings[3]);
run(threads, requestTotal,warmupIterations,measurementIterations);
}

public void run(int threads, int requestsTotal, int warmupIterations, int measurementIterations) {
this.threads = threads;
this.requestsTotal = requestsTotal;
this.requestsPerThread = requestsTotal / threads;
this.userService = getUserService();
this.executorService = Executors.newFixedThreadPool(threads);
this.warmupIterations = warmupIterations;
this.measurementIterations = measurementIterations;
createUser();
existUser();
Expand All @@ -68,7 +78,7 @@ public class BenchmarkResult {
private String p999;
@CsvBindByName(column = "Type")
private String index;

private double _mills;
private double _qps;
private double _avgRt;
Expand All @@ -79,7 +89,7 @@ public class BenchmarkResult {
public BenchmarkResult() {
}

public BenchmarkResult(int index,long nanos, List<Long> rts) {
public BenchmarkResult(int index, long nanos, List<Long> rts) {
this.index = "NORMAL-" + index;
double mills = 1.0 * nanos / 1000000;
// 每毫秒的处理请求数
Expand Down Expand Up @@ -119,7 +129,7 @@ public BenchmarkResult avgBenchmarkResult(List<BenchmarkResult> benchmarkResults
return result;
}


private void createUser() {
try {
Path benchmark = Paths.get(System.getProperty("user.home"), "benchmark", "createUser.csv");
Expand All @@ -138,7 +148,7 @@ private void createUser() {
log.info("----------------------------------------------------------------------------");
log.info("createUser started");
List<BenchmarkResult> results = new ArrayList<>();
for (int i = 0; i < measurementIterations; i++) {
for (int i = 0; i < warmupIterations + measurementIterations; i++) {
CountDownLatch countDownLatch = new CountDownLatch(threads);

User user = new User();
Expand All @@ -164,7 +174,6 @@ private void createUser() {
for (int j = 0; j < requestsPerThread; j++) {
long begin = System.nanoTime();
try {
log.info("request:{},createUser",j);
userService.createUser(user);
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -181,7 +190,9 @@ private void createUser() {
long benchmarkStart = System.nanoTime();
countDownLatch.await();
long nanos = System.nanoTime() - benchmarkStart;
results.add(new BenchmarkResult(i,nanos, rts));
if (i >= warmupIterations) {
results.add(new BenchmarkResult(i - warmupIterations, nanos, rts));
}
}
results.add(avgBenchmarkResult(results));
beanToCsv.write(results);
Expand Down Expand Up @@ -218,14 +229,13 @@ private void existUser() {
log.info("----------------------------------------------------------------------------");
log.info("existUser started");
List<BenchmarkResult> results = new ArrayList<>();
for (int i = 0; i < measurementIterations; i++) {
for (int i = 0; i < warmupIterations + measurementIterations; i++) {
CountDownLatch countDownLatch = new CountDownLatch(threads);
List<Long> rts = new Vector<>(requestsTotal);
Runnable r = () -> {
for (int j = 0; j < requestsPerThread; j++) {
long begin = System.nanoTime();
try {
log.info("request:{},existUser",j);
userService.existUser(j + "@gmail.com");
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -240,7 +250,9 @@ private void existUser() {
long benchmarkStart = System.nanoTime();
countDownLatch.await();
long nanos = System.nanoTime() - benchmarkStart;
results.add(new BenchmarkResult(i,nanos, rts));
if (i >= warmupIterations) {
results.add(new BenchmarkResult(i - warmupIterations, nanos, rts));
}
}
results.add(avgBenchmarkResult(results));
beanToCsv.write(results);
Expand Down Expand Up @@ -276,14 +288,13 @@ private void getUser() {
log.info("----------------------------------------------------------------------------");
log.info("getUser started");
List<BenchmarkResult> results = new ArrayList<>();
for (int i = 0; i < measurementIterations; i++) {
for (int i = 0; i < warmupIterations + measurementIterations; i++) {
CountDownLatch countDownLatch = new CountDownLatch(threads);
List<Long> rts = new Vector<>(requestsTotal);
Runnable r = () -> {
for (int j = 0; j < requestsPerThread; j++) {
long begin = System.nanoTime();
try {
log.info("request:{},getUser",j);
userService.getUser(j);
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -299,7 +310,9 @@ private void getUser() {
long benchmarkStart = System.nanoTime();
countDownLatch.await();
long nanos = System.nanoTime() - benchmarkStart;
results.add(new BenchmarkResult(i,nanos, rts));
if (i >= warmupIterations) {
results.add(new BenchmarkResult(i - warmupIterations, nanos, rts));
}
}
results.add(avgBenchmarkResult(results));
beanToCsv.write(results);
Expand Down Expand Up @@ -335,14 +348,13 @@ private void listUser() {
log.info("----------------------------------------------------------------------------");
log.info("listUser started");
List<BenchmarkResult> results = new ArrayList<>();
for (int i = 0; i < measurementIterations; i++) {
for (int i = 0; i < warmupIterations + measurementIterations; i++) {
CountDownLatch countDownLatch = new CountDownLatch(threads);
List<Long> rts = new Vector<>(requestsTotal);
Runnable r = () -> {
for (int j = 0; j < requestsPerThread; j++) {
long begin = System.nanoTime();
try {
log.info("request:{},listUser",j);
userService.listUser(j);
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -358,7 +370,9 @@ private void listUser() {
long benchmarkStart = System.nanoTime();
countDownLatch.await();
long nanos = System.nanoTime() - benchmarkStart;
results.add(new BenchmarkResult(i,nanos, rts));
if (i >= warmupIterations) {
results.add(new BenchmarkResult(i - warmupIterations, nanos, rts));
}
}
results.add(avgBenchmarkResult(results));
beanToCsv.write(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static void main(String[] args) throws InterruptedException {

@Override
public void run(String... strings) throws Exception {
client.run(32, 32 * 3000,3);
client.run(strings);
// client.run(1,1,0,1);
System.exit(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ public static void main(String[] args) throws InterruptedException {

@Override
public void run(String... strings) throws Exception {
// int threads = Integer.parseInt(strings[0]);
// int requestTotal = Integer.parseInt(strings[1]);
// int measurementIterations = Integer.parseInt(strings[2]);
// client.run(threads, requestTotal,measurementIterations);
client.run(1,1,1);
client.run(strings);
// client.run(1,1,0,1);
System.exit(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rpc.application.proxy=javassist
rpc.protocol.type=toy
rpc.protocol.executor.server.type=threadpool
rpc.protocol.executor.client.type=threadpool
rpc.registry.address=127.0.0.1:2181
#rpc.registry.address=192.168.1.117:2181
#rpc.registry.address=127.0.0.1:2181
rpc.registry.address=192.168.1.117:2181
rpc.cluster.loadbalance=consistent_hash
rpc.cluster.faulttolerance=failover
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</appender>


<logger name="com.sinjinsong" level="INFO" additivity="false">
<logger name="com.sinjinsong.benchmark" level="INFO" additivity="false">
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileAppender"/>
</logger>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</appender>


<logger name="com.sinjinsong" level="INFO" additivity="false">
<logger name="com.sinjinsong.benchmark" level="INFO" additivity="false">
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileAppender"/>
</logger>
Expand Down
Loading

0 comments on commit 7a7b042

Please sign in to comment.