Skip to content

Commit 7becf36

Browse files
committed
Benchmark switches to Typesafe config
1 parent 146e347 commit 7becf36

File tree

7 files changed

+56
-50
lines changed

7 files changed

+56
-50
lines changed

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ project(':lightningrpc-netty') {
5858
project(':lightningrpc-benchmark') {
5959
dependencies {
6060
compile project(':lightningrpc-netty')
61+
compile 'com.typesafe:config:1.3.0'
6162
}
6263
}
6364

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
akka {
2-
loggers = ["akka.event.slf4j.Slf4jLogger"]
3-
loglevel = "INFO"
1+
server {
2+
host = 127.0.0.1
3+
port = 3059
4+
threads = 128
5+
response.size = 100
6+
}
7+
8+
client {
9+
connections = 1
10+
concurrency = 128
11+
timeout = 1
12+
request {
13+
type = 3 // kryo
14+
size = 100
15+
duration = 1000
16+
statistics = true
17+
}
418
}
519

620

lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkClient.java

+23-24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
import com.esotericsoftware.kryo.serializers.DefaultArraySerializers;
1616

17+
import com.typesafe.config.Config;
18+
import com.typesafe.config.ConfigFactory;
1719
import info.minzhou.lightning.rpc.Codecs;
1820
import info.minzhou.lightning.rpc.protocol.KryoUtils;
1921
import info.minzhou.lightning.rpc.protocol.PBDecoder;
@@ -72,24 +74,21 @@ public abstract class AbstractBenchmarkClient {
7274
private static long above1000sum;
7375

7476
public void run(String[] args) throws Exception {
75-
if (args == null || (args.length != 7 && args.length != 8)) {
76-
throw new IllegalArgumentException(
77-
"must give seven or eight args, serverIP serverPort concurrents timeout codectype requestSize runtime(seconds) clientNums");
78-
}
79-
80-
final String serverIP = args[0];
81-
final int serverPort = Integer.parseInt(args[1]);
82-
final int concurrents = Integer.parseInt(args[2]);
83-
final int timeout = Integer.parseInt(args[3]);
84-
final int codectype = Integer.parseInt(args[4]);
85-
final int requestSize = Integer.parseInt(args[5]);
86-
runtime = Integer.parseInt(args[6]);
77+
Config conf = ConfigFactory.load();
78+
// server config
79+
final String serverIP = conf.getString("server.host");
80+
final int serverPort = conf.getInt("server.port");
81+
// client config
82+
final int concurrents = conf.getInt("client.concurrency");
83+
final int clientNums = conf.getInt("client.connections");
84+
final int timeout = conf.getInt("client.timeout");
85+
86+
// reuqest config
87+
final int codectype = conf.getInt("client.request.type");
88+
final int requestSize = conf.getInt("client.request.size");
89+
runtime = conf.getInt("client.request.duration");
90+
boolean isWriteResult = conf.getBoolean("client.request.statistics");
8791
final long endtime = System.currentTimeMillis() + runtime * 1000;
88-
int tmpClientNums = 1;
89-
if (args.length == 8) {
90-
tmpClientNums = Integer.parseInt(args[7]);
91-
}
92-
final int clientNums = tmpClientNums;
9392

9493
// Print start info
9594
Date currentDate = new Date();
@@ -215,7 +214,7 @@ public void run(String[] args) throws Exception {
215214
}
216215
}
217216

218-
boolean isWriteResult = Boolean.parseBoolean(System.getProperty("write.statistics", "false"));
217+
219218
if (isWriteResult) {
220219
BufferedWriter writer = new BufferedWriter(new FileWriter(
221220
"benchmark.all.results"));
@@ -272,12 +271,12 @@ public abstract ClientRunnable getClientRunnable(String targetIP, int targetPort
272271
int clientNums, int rpcTimeout, int codecType, int requestSize,
273272
CyclicBarrier barrier, CountDownLatch latch, long endTime, long startTime);
274273

275-
protected void startRunnables(List<ClientRunnable> runnables) {
276-
for (int i = 0; i < runnables.size(); i++) {
277-
final ClientRunnable runnable = runnables.get(i);
278-
Thread thread = new Thread(runnable, "benchmarkclient-" + i);
279-
thread.start();
280-
}
274+
protected void startRunnables(List<ClientRunnable> runnables) {
275+
for (int i = 0; i < runnables.size(); i++) {
276+
final ClientRunnable runnable = runnables.get(i);
277+
Thread thread = new Thread(runnable, "benchmarkclient-" + i);
278+
thread.start();
281279
}
280+
}
282281

283282
}

lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkServer.java

+11-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package info.minzhou.lightning.rpc.benchmark;
22

3-
import java.text.SimpleDateFormat;
4-
import java.util.Date;
5-
import java.util.concurrent.ExecutorService;
6-
import java.util.concurrent.SynchronousQueue;
7-
import java.util.concurrent.ThreadFactory;
8-
import java.util.concurrent.ThreadPoolExecutor;
9-
import java.util.concurrent.TimeUnit;
10-
3+
import com.esotericsoftware.kryo.serializers.DefaultArraySerializers;
4+
import com.google.protobuf.ByteString;
5+
import com.typesafe.config.Config;
6+
import com.typesafe.config.ConfigFactory;
117
import info.minzhou.lightning.rpc.NamedThreadFactory;
128
import info.minzhou.lightning.rpc.protocol.KryoUtils;
139
import info.minzhou.lightning.rpc.protocol.PBDecoder;
@@ -16,8 +12,9 @@
1612
import info.minzhou.lightning.rpc.server.Server;
1713
import info.minzhou.lightning.rpc.server.ServerProcessor;
1814

19-
import com.esotericsoftware.kryo.serializers.DefaultArraySerializers;
20-
import com.google.protobuf.ByteString;
15+
import java.text.SimpleDateFormat;
16+
import java.util.Date;
17+
import java.util.concurrent.*;
2118

2219
/**
2320
* Abstract benchmark server
@@ -31,13 +28,10 @@ public abstract class AbstractBenchmarkServer {
3128
"yyyy-MM-dd HH:mm:ss");
3229

3330
public void run(String[] args) throws Exception {
34-
if (args == null || args.length != 3) {
35-
throw new IllegalArgumentException(
36-
"must give three args: listenPort | maxThreads | responseSize");
37-
}
38-
int listenPort = Integer.parseInt(args[0]);
39-
int maxThreads = Integer.parseInt(args[1]);
40-
final int responseSize = Integer.parseInt(args[2]);
31+
Config conf = ConfigFactory.load();
32+
int listenPort = conf.getInt("server.port");
33+
int maxThreads = conf.getInt("server.threads");
34+
final int responseSize = conf.getInt("server.response.size");
4135
System.out.println(dateFormat.format(new Date())
4236
+ " ready to start server,listenPort is: " + listenPort
4337
+ ",maxThreads is:" + maxThreads + ",responseSize is:"

lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/Codecs.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ public class Codecs {
1717

1818
public static final int JAVA_CODEC = 1;
1919

20-
public static final int HESSIAN_CODEC = 2;
20+
public static final int PB_CODEC = 2;
2121

22-
public static final int PB_CODEC = 3;
23-
24-
public static final int KRYO_CODEC = 4;
22+
public static final int KRYO_CODEC = 3;
2523

2624
private static Encoder[] encoders = new Encoder[5];
2725

lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/RequestWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class RequestWrapper {
3030

3131
private int protocolType;
3232

33-
private int codecType = Codecs.HESSIAN_CODEC;
33+
private final int codecType;
3434

3535
private int messageLen;
3636

lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/ResponseWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ResponseWrapper {
1515

1616
private Throwable exception = null;
1717

18-
private int codecType = Codecs.HESSIAN_CODEC;
18+
private final int codecType;
1919

2020
private int protocolType;
2121

0 commit comments

Comments
 (0)