Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-RC6'
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegDokuka committed Feb 4, 2020
2 parents 0a4559e + 7f76f0a commit 83d97f7
Show file tree
Hide file tree
Showing 60 changed files with 5,151 additions and 678 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ matrix:
- jdk: openjdk8
- jdk: openjdk11
env: SKIP_RELEASE=true
- jdk: openjdk12
- jdk: openjdk13
env: SKIP_RELEASE=true

env:
Expand Down
47 changes: 47 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## Usage of JMH tasks

Only execute specific benchmark(s) (wildcards are added before and after):
```
../gradlew jmh --include="(BenchmarkPrimary|OtherBench)"
```
If you want to specify the wildcards yourself, you can pass the full regexp:
```
../gradlew jmh --fullInclude=.*MyBenchmark.*
```

Specify extra profilers:
```
../gradlew jmh --profilers="gc,stack"
```

Prominent profilers (for full list call `jmhProfilers` task):
- comp - JitCompilations, tune your iterations
- stack - which methods used most time
- gc - print garbage collection stats
- hs_thr - thread usage

Change report format from JSON to one of [CSV, JSON, NONE, SCSV, TEXT]:
```
./gradlew jmh --format=csv
```

Specify JVM arguments:
```
../gradlew jmh --jvmArgs="-Dtest.cluster=local"
```

Run in verification mode (execute benchmarks with minimum of fork/warmup-/benchmark-iterations):
```
../gradlew jmh --verify=true
```

## Comparing with the baseline
If you wish you run two sets of benchmarks, one for the current change and another one for the "baseline",
there is an additional task `jmhBaseline` that will use the latest release:
```
../gradlew jmh jmhBaseline --include=MyBenchmark
```

## Resources
- http://tutorials.jenkov.com/java-performance/jmh.html (Introduction)
- http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/ (Samples)
163 changes: 163 additions & 0 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
apply plugin: 'java'
apply plugin: 'idea'

configurations {
current
baseline {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}

dependencies {
// Use the baseline to avoid using new APIs in the benchmarks
compileOnly "io.rsocket:rsocket-core:${perfBaselineVersion}"
compileOnly "io.rsocket:rsocket-transport-local:${perfBaselineVersion}"

implementation "org.openjdk.jmh:jmh-core:1.21"
annotationProcessor "org.openjdk.jmh:jmh-generator-annprocess:1.21"

current project(':rsocket-core')
current project(':rsocket-transport-local')
baseline "io.rsocket:rsocket-core:${perfBaselineVersion}", {
changing = true
}
baseline "io.rsocket:rsocket-transport-local:${perfBaselineVersion}", {
changing = true
}
}

task jmhProfilers(type: JavaExec, description:'Lists the available profilers for the jmh task', group: 'Development') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.openjdk.jmh.Main'
args '-lprof'
}

task jmh(type: JmhExecTask, description: 'Executing JMH benchmarks') {
classpath = sourceSets.main.runtimeClasspath + configurations.current
}

task jmhBaseline(type: JmhExecTask, description: 'Executing JMH baseline benchmarks') {
classpath = sourceSets.main.runtimeClasspath + configurations.baseline
}

class JmhExecTask extends JavaExec {

private String include;
private String fullInclude;
private String exclude;
private String format = "json";
private String profilers;
private String jmhJvmArgs;
private String verify;

public JmhExecTask() {
super();
}

public String getInclude() {
return include;
}

@Option(option = "include", description="configure bench inclusion using substring")
public void setInclude(String include) {
this.include = include;
}

public String getFullInclude() {
return fullInclude;
}

@Option(option = "fullInclude", description = "explicitly configure bench inclusion using full JMH style regexp")
public void setFullInclude(String fullInclude) {
this.fullInclude = fullInclude;
}

public String getExclude() {
return exclude;
}

@Option(option = "exclude", description = "explicitly configure bench exclusion using full JMH style regexp")
public void setExclude(String exclude) {
this.exclude = exclude;
}

public String getFormat() {
return format;
}

@Option(option = "format", description = "configure report format")
public void setFormat(String format) {
this.format = format;
}

public String getProfilers() {
return profilers;
}

@Option(option = "profilers", description = "configure jmh profiler(s) to use, comma separated")
public void setProfilers(String profilers) {
this.profilers = profilers;
}

public String getJmhJvmArgs() {
return jmhJvmArgs;
}

@Option(option = "jvmArgs", description = "configure additional JMH JVM arguments, comma separated")
public void setJmhJvmArgs(String jvmArgs) {
this.jmhJvmArgs = jvmArgs;
}

public String getVerify() {
return verify;
}

@Option(option = "verify", description = "run in verify mode")
public void setVerify(String verify) {
this.verify = verify;
}

@TaskAction
public void exec() {
setMain("org.openjdk.jmh.Main");
File resultFile = getProject().file("build/reports/" + getName() + "/result." + format);

if (include != null) {
args(".*" + include + ".*");
}
else if (fullInclude != null) {
args(fullInclude);
}

if(exclude != null) {
args("-e", exclude);
}
if(verify != null) { // execute benchmarks with the minimum amount of execution (only to check if they are working)
System.out.println("Running in verify mode");
args("-f", 1);
args("-wi", 1);
args("-i", 1);
}
args("-foe", "true"); //fail-on-error
args("-v", "NORMAL"); //verbosity [SILENT, NORMAL, EXTRA]
if(profilers != null) {
for (String prof : profilers.split(",")) {
args("-prof", prof);
}
}
args("-jvmArgsPrepend", "-Xmx3072m");
args("-jvmArgsPrepend", "-Xms3072m");
if(jmhJvmArgs != null) {
for(String jvmArg : jmhJvmArgs.split(" ")) {
args("-jvmArgsPrepend", jvmArg);
}
}
args("-rf", format);
args("-rff", resultFile);

System.out.println("\nExecuting JMH with: " + getArgs() + "\n");
resultFile.getParentFile().mkdirs();

super.exec();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import org.reactivestreams.Subscription;
import reactor.core.CoreSubscriber;

public class MaxPerfSubscriber implements CoreSubscriber<Payload> {
public class MaxPerfSubscriber<T> extends CountDownLatch implements CoreSubscriber<T> {

final CountDownLatch latch = new CountDownLatch(1);
final Blackhole blackhole;

public MaxPerfSubscriber(Blackhole blackhole) {
super(1);
this.blackhole = blackhole;
}

Expand All @@ -20,19 +20,18 @@ public void onSubscribe(Subscription s) {
}

@Override
public void onNext(Payload payload) {
payload.release();
public void onNext(T payload) {
blackhole.consume(payload);
}

@Override
public void onError(Throwable t) {
blackhole.consume(t);
latch.countDown();
countDown();
}

@Override
public void onComplete() {
latch.countDown();
countDown();
}
}
16 changes: 16 additions & 0 deletions benchmarks/src/main/java/io/rsocket/PayloadsMaxPerfSubscriber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.rsocket;

import org.openjdk.jmh.infra.Blackhole;

public class PayloadsMaxPerfSubscriber extends MaxPerfSubscriber<Payload> {

public PayloadsMaxPerfSubscriber(Blackhole blackhole) {
super(blackhole);
}

@Override
public void onNext(Payload payload) {
payload.release();
super.onNext(payload);
}
}
16 changes: 16 additions & 0 deletions benchmarks/src/main/java/io/rsocket/PayloadsPerfSubscriber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.rsocket;

import org.openjdk.jmh.infra.Blackhole;

public class PayloadsPerfSubscriber extends PerfSubscriber<Payload> {

public PayloadsPerfSubscriber(Blackhole blackhole) {
super(blackhole);
}

@Override
public void onNext(Payload payload) {
payload.release();
super.onNext(payload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import org.reactivestreams.Subscription;
import reactor.core.CoreSubscriber;

public class PerfSubscriber implements CoreSubscriber<Payload> {
public class PerfSubscriber<T> extends CountDownLatch implements CoreSubscriber<T> {

final CountDownLatch latch = new CountDownLatch(1);
final Blackhole blackhole;

Subscription s;

public PerfSubscriber(Blackhole blackhole) {
super(1);
this.blackhole = blackhole;
}

Expand All @@ -23,20 +23,19 @@ public void onSubscribe(Subscription s) {
}

@Override
public void onNext(Payload payload) {
payload.release();
public void onNext(T payload) {
blackhole.consume(payload);
s.request(1);
}

@Override
public void onError(Throwable t) {
blackhole.consume(t);
latch.countDown();
countDown();
}

@Override
public void onComplete() {
latch.countDown();
countDown();
}
}
Loading

0 comments on commit 83d97f7

Please sign in to comment.