Skip to content
Permalink
Browse files
Support -f output to file
  • Loading branch information
zonghaishang committed Sep 17, 2018
1 parent c1e2921 commit 5aaf493e5453cd99f3d4af30b51f1f1cfb25257d
Showing 3 changed files with 39 additions and 19 deletions.
@@ -28,8 +28,8 @@ Clone this project onto your desktop, then
./benchmark.sh dubbo-kryo-client
```

## Specify hostname and port for service
## Specify hostname, port and output file for service

```bash
./benchmark.sh -s [hostname|ip address] -p port
./benchmark.sh -s [hostname|ip address] -p port -f output
```
@@ -1,7 +1,13 @@
#!/usr/bin/env bash

usage() {
echo "Usage: ${PROGRAM_NAME} -m {profiling|benchmark} -s hostname -p port dirname"
echo "Usage: ${PROGRAM_NAME} command dirname"
echo "command: [m|s|p|f]"
echo " -m [profiling|benchmark], specify benchmark mode"
echo " -s hostname, host name"
echo " -p port, port number"
echo " -f output file path"
echo "dirname: test module name"
}

build() {
@@ -18,10 +24,10 @@ java_options() {
JAVA_OPTIONS="-server -Xmx1g -Xms1g -XX:MaxDirectMemorySize=1g -XX:+UseG1GC"
if [ "x${MODE}" = "xprofiling" ]; then
JAVA_OPTIONS="${JAVA_OPTIONS} \
-XX:+UnlockCommercialFeatures \
-XX:+FlightRecorder \
-XX:StartFlightRecording=duration=30s,filename=${PROJECT_DIR}.jfr \
-XX:FlightRecorderOptions=stackdepth=256"
-XX:+UnlockCommercialFeatures \
-XX:+FlightRecorder \
-XX:StartFlightRecording=duration=30s,filename=${PROJECT_DIR}.jfr \
-XX:FlightRecorderOptions=stackdepth=256"
fi
}

@@ -30,7 +36,7 @@ run() {
JAR=`find ${PROJECT_DIR}/target/*.jar | head -n 1`
echo
echo "RUN ${PROJECT_DIR} IN ${MODE:-benchmark} MODE"
CMD="java ${JAVA_OPTIONS} -Dserver.host=${SERVER} -Dserver.port=${PORT} -jar ${JAR}"
CMD="java ${JAVA_OPTIONS} -Dserver.host=${SERVER} -Dserver.port=${PORT} -Dbenchmark.output=${OUTPUT} -jar ${JAR}"
echo "command is: ${CMD}"
echo
${CMD}
@@ -41,14 +47,11 @@ PROGRAM_NAME=$0
MODE="benchmark"
SERVER="localhost"
PORT="8080"
OUTPUT=""
OPTIND=1

while getopts "h?m:s:p:" opt; do
while getopts "m:s:p:f:" opt; do
case "$opt" in
h|\?)
usage
exit 0
;;
m)
MODE=${OPTARG}
;;
@@ -58,6 +61,13 @@ while getopts "h?m:s:p:" opt; do
p)
PORT=${OPTARG}
;;
f)
OUTPUT=${OPTARG}
;;
?)
usage
exit 0
;;
esac
done

@@ -1,6 +1,7 @@
package org.apache.dubbo.benchmark;

import com.alibaba.dubbo.config.ProtocolConfig;

import org.apache.dubbo.benchmark.bean.Page;
import org.apache.dubbo.benchmark.bean.User;
import org.apache.dubbo.benchmark.rpc.AbstractClient;
@@ -12,8 +13,8 @@
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;
@@ -42,8 +43,8 @@ protected UserService getUserService() {

@TearDown
public void close() throws IOException {
context.close();
ProtocolConfig.destroyAll();
context.close();
}

@Benchmark
@@ -79,17 +80,26 @@ public Page<User> listUser() throws Exception {
}

public static void main(String[] args) throws Exception {
Options opt = new OptionsBuilder()
Options opt;
ChainedOptionsBuilder optBuilder = new OptionsBuilder()
.include(Client.class.getSimpleName())
.warmupIterations(3)
.warmupTime(TimeValue.seconds(10))
.measurementIterations(3)
.measurementTime(TimeValue.seconds(10))
.threads(CONCURRENCY)
// .resultFormat(ResultFormatType.JSON)
.forks(1)
.build();
.forks(1);

opt = doOptions(optBuilder).build();

new Runner(opt).run();
}

private static ChainedOptionsBuilder doOptions(ChainedOptionsBuilder optBuilder) {
String output = System.getProperty("benchmark.output");
if (output != null && !output.trim().isEmpty()) {
optBuilder.output(output);
}
return optBuilder;
}
}

0 comments on commit 5aaf493

Please sign in to comment.