-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
5,151 additions
and
678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
benchmarks/src/main/java/io/rsocket/PayloadsMaxPerfSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
benchmarks/src/main/java/io/rsocket/PayloadsPerfSubscriber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.