Move jmh benchmarks to their respective modules

The benchmarks should be close to the code they're benchmarking, like
we do with tests.

This includes a bugfix to SerializingExecutorBenchmark to let it run.

The io.grpc.benchmarks.netty benchmarks in benchmarks/ depend on
ByteBufOutputMarshaller from benchmarks's main, so they were not moved.
This commit is contained in:
Eric Anderson 2017-08-26 17:10:18 -07:00
parent 812e65a5ca
commit 6164b7b2ee
15 changed files with 38 additions and 28 deletions

View File

@ -1,20 +1,12 @@
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
} }
dependencies { dependencies {
classpath libraries.math
classpath libraries.protobuf_plugin classpath libraries.protobuf_plugin
} }
} }
plugins {
id "me.champeau.gradle.jmh" version "0.4.4"
}
apply plugin: 'application' apply plugin: 'application'
description = "grpc Benchmarks" description = "grpc Benchmarks"
@ -23,11 +15,10 @@ startScripts.enabled = false
run.enabled = false run.enabled = false
jmh { jmh {
jmhVersion = '1.19'
warmupIterations = 10
iterations = 10
fork = 1
jvmArgs = "-server -Xms2g -Xmx2g" jvmArgs = "-server -Xms2g -Xmx2g"
// Workaround
// https://github.com/melix/jmh-gradle-plugin/issues/97#issuecomment-316664026
includeTests = true
} }
dependencies { dependencies {
@ -50,10 +41,6 @@ compileJava {
options.compilerArgs += ["-Xep:JavaLangClash:OFF"] options.compilerArgs += ["-Xep:JavaLangClash:OFF"]
} }
compileJmhJava {
options.compilerArgs = compileJava.options.compilerArgs
}
configureProtoCompilation() configureProtoCompilation()
def vmArgs = [ def vmArgs = [

View File

@ -10,6 +10,7 @@ buildscript {
classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0' classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.4.0' classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.4.0'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.11' classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.11'
classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.4"
} }
} }
@ -21,6 +22,7 @@ subprojects {
apply plugin: "signing" apply plugin: "signing"
apply plugin: "jacoco" apply plugin: "jacoco"
apply plugin: "me.champeau.gradle.jmh"
apply plugin: "com.google.osdetector" apply plugin: "com.google.osdetector"
// The plugin only has an effect if a signature is specified // The plugin only has an effect if a signature is specified
apply plugin: "ru.vyarus.animalsniffer" apply plugin: "ru.vyarus.animalsniffer"
@ -57,7 +59,7 @@ subprojects {
mavenLocal() mavenLocal()
} }
[compileJava, compileTestJava].each() { [compileJava, compileTestJava, compileJmhJava].each() {
it.options.compilerArgs += ["-Xlint:all", "-Xlint:-options", "-Xlint:-path"] it.options.compilerArgs += ["-Xlint:all", "-Xlint:-options", "-Xlint:-path"]
it.options.encoding = "UTF-8" it.options.encoding = "UTF-8"
if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) { if (rootProject.hasProperty('failOnWarnings') && rootProject.failOnWarnings.toBoolean()) {
@ -165,7 +167,7 @@ subprojects {
} }
} }
[compileJava, compileTestJava].each() { [compileJava, compileTestJava, compileJmhJava].each() {
// Protobuf-generated code produces some warnings. // Protobuf-generated code produces some warnings.
// https://github.com/google/protobuf/issues/2718 // https://github.com/google/protobuf/issues/2718
it.options.compilerArgs += ["-Xlint:-cast", "-Xep:MissingOverride:OFF", it.options.compilerArgs += ["-Xlint:-cast", "-Xep:MissingOverride:OFF",
@ -227,6 +229,9 @@ subprojects {
// Configuration for modules that use Jetty ALPN agent // Configuration for modules that use Jetty ALPN agent
alpnagent libraries.jetty_alpn_agent alpnagent libraries.jetty_alpn_agent
jmh 'org.openjdk.jmh:jmh-core:1.19',
'org.openjdk.jmh:jmh-generator-bytecode:1.19'
} }
signing { signing {
@ -261,6 +266,16 @@ subprojects {
source = fileTree(dir: "src/test", include: "**/*.java") source = fileTree(dir: "src/test", include: "**/*.java")
} }
jmh {
warmupIterations = 10
iterations = 10
fork = 1
// None of our benchmarks need the tests, and we have pseudo-circular
// dependencies that break when including them. (context's testCompile
// depends on core; core's testCompile depends on testing)
includeTests = false
}
task javadocJar(type: Jar) { task javadocJar(type: Jar) {
classifier = 'javadoc' classifier = 'javadoc'
from javadoc from javadoc

View File

@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package io.grpc.context; package io.grpc;
import io.grpc.Context;
import io.grpc.Context.Key; import io.grpc.Context.Key;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Benchmark;

View File

@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package io.grpc.context; package io.grpc;
import io.grpc.Context;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

View File

@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package io.grpc.context; package io.grpc;
import io.grpc.Context;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.BenchmarkMode;

View File

@ -18,3 +18,8 @@ javadoc {
exclude 'io/grpc/Internal?*.java' exclude 'io/grpc/Internal?*.java'
exclude 'io/grpc/internal/**' exclude 'io/grpc/internal/**'
} }
animalsniffer {
// Don't check sourceSets.jmh
sourceSets = [sourceSets.main, sourceSets.test]
}

View File

@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
package io.grpc.benchmarks; package io.grpc;
import io.grpc.CallOptions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;

View File

@ -18,6 +18,7 @@ package io.grpc.internal;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Phaser; import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Benchmark;
@ -39,7 +40,7 @@ import org.openjdk.jmh.annotations.TearDown;
@State(Scope.Thread) @State(Scope.Thread)
public class SerializingExecutorBenchmark { public class SerializingExecutorBenchmark {
private ExecutorService executorService; private ExecutorService executorService = Executors.newSingleThreadExecutor();
private Executor executor = new SerializingExecutor(executorService); private Executor executor = new SerializingExecutor(executorService);
private static class IncrRunnable implements Runnable { private static class IncrRunnable implements Runnable {
@ -94,4 +95,4 @@ public class SerializingExecutorBenchmark {
throw new AssertionError(); throw new AssertionError();
} }
} }
} }

View File

@ -29,3 +29,9 @@ project.sourceSets {
} }
} }
jmh {
// Workaround
// https://github.com/melix/jmh-gradle-plugin/issues/97#issuecomment-316664026
includeTests = true
}