Skip to content

Commit

Permalink
Gradle: JMH runner task
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Mashkov committed Oct 23, 2017
1 parent 1fc4894 commit 395ee2f
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 49 deletions.
31 changes: 0 additions & 31 deletions .idea/runConfigurations/Rebuild_JMH.xml

This file was deleted.

21 changes: 21 additions & 0 deletions .idea/runConfigurations/Rebuild__JMH.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 53 additions & 9 deletions ktor-server/ktor-server-benchmarks/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,57 @@
plugins {
id "me.champeau.gradle.jmh" version "0.4.4"
id "org.jetbrains.kotlin.plugin.allopen" version "1.1.51"
}

allOpen {
annotation("org.openjdk.jmh.annotations.State")
}

sourceSets {
jmh {
kotlin {
srcDir "src-jmh"
}
}
}

description = ''
dependencies {
compile project(':ktor-server:ktor-server-core')
compile project(':ktor-server:ktor-server-test-host')
compile project(':ktor-server:ktor-server-netty')
compile project(':ktor-server:ktor-server-jetty')
compile group: 'org.openjdk.jmh', name: 'jmh-core', version:'1.19'
compile group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version:'1.19'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version:'4.5.2'
compile group: 'com.squareup.okhttp3', name: 'okhttp', version:'3.6.0'
compile group: 'ch.qos.logback', name: 'logback-classic', version:'1.2.1'
jmh project(':ktor-server:ktor-server-test-host')
jmh project(':ktor-server:ktor-server-netty')
jmh project(':ktor-server:ktor-server-jetty')

jmh group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.2'
jmh group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.6.0'
jmh group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.1'
}

jmh {
jmhVersion = '1.19'
include = [/io.ktor.tests.ValuesMapBenchmark/]
}

jmhJar.archiveName = 'benchmarks.jar'

task runBenchmark(type: JavaExec, dependsOn: 'jmhJar') {
def mainClassFqName = null

if (project.hasProperty('benchmarkClassFqName')) {
mainClassFqName = project.benchmarkClassFqName
} else if (project.hasProperty('benchmarkName')) {
mainClassFqName = "io.ktor.benchmarks.${project.benchmarkName}Kt"
}

classpath = sourceSets.jmh.runtimeClasspath + jmhJar.outputs.files
main = mainClassFqName
systemProperties['benchmarkClassFqName'] = mainClassFqName

doFirst {
if (mainClassFqName == null) {
throw new InvalidUserDataException("Neither benchmarkName nor benchmarkClassFqName property specified (use option -P to assign)")
}

new File(project.buildDir, 'reports/benchmarks').mkdirs()
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.ktor.server.benchmarks

import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.results.format.*
import org.openjdk.jmh.runner.*
import org.openjdk.jmh.runner.options.*
import java.lang.reflect.*
Expand All @@ -11,6 +12,7 @@ val numberOfOperations = 10000
val jmhOptions = OptionsBuilder()
.mode(Mode.Throughput)
.timeUnit(TimeUnit.MILLISECONDS)
.resultFormat(ResultFormatType.CSV)
.forks(1)

class BenchmarkSettings {
Expand Down Expand Up @@ -80,7 +82,7 @@ fun runProfiler(settings: BenchmarkSettings) {
benchmarks.forEach { it.invoke(instance) }

if (settings.threads == 1) {
println("Running ${numberOfOperations} iterations…")
println("Running $numberOfOperations iterations…")
instance.executeBenchmarks(benchmarks, numberOfOperations)
} else {
val iterationsPerThread = numberOfOperations / settings.threads
Expand Down Expand Up @@ -131,6 +133,11 @@ fun runJMH(settings: BenchmarkSettings) {
val regexp = clazz.name + (method?.let { ".$it" } ?: "")
include(regexp.replace(".", "\\."))
}

System.getProperty("benchmarkClassFqName")?.let { fqName ->
val name = fqName.substringAfterLast('.').removeSuffix("Kt")
result("build/reports/benchmarks/$name.csv")
}
}
Runner(options.build()).run()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.nio.channels.*
import java.nio.file.*

@State(Scope.Benchmark)
open class ChannelBenchmarks {
class ChannelBenchmarks {
val file = listOf(File("test/io/ktor/tests/nio/DeflaterReadChannelTest.kt"),
File("ktor-server/ktor-server-core-tests/test/io/ktor/tests/nio/DeflaterReadChannelTest.kt")).first(File::exists)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.openjdk.jmh.annotations.*
import java.net.*

@State(Scope.Benchmark)
open class CodecsBenchmark {
class CodecsBenchmark {
@Benchmark
fun decodeHex() = decodeURLPart("%2A~%21%40%23%24%25%5E%26%28%29+%7B%7D%22%5C%3B%3A%60%2C%2F%5B%5D")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.util.concurrent.*


@State(Scope.Benchmark)
open class FullBenchmark {
class FullBenchmark {
private val testHost: TestApplicationHost = TestApplicationHost(createTestEnvironment())
private val classSignature = listOf(0xca, 0xfe, 0xba, 0xbe).map(Int::toByte)
private val packageName = FullBenchmark::class.java.`package`.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ abstract class IntegrationBenchmark {
}
}

open class NettyIntegrationBenchmark : IntegrationBenchmark() {
class NettyIntegrationBenchmark : IntegrationBenchmark() {
override fun createServer(port: Int, main: Application.() -> Unit): ApplicationHost {
return embeddedServer(Netty, port, module = main)
}
}

open class JettyIntegrationBenchmark : IntegrationBenchmark() {
class JettyIntegrationBenchmark : IntegrationBenchmark() {
override fun createServer(port: Int, main: Application.() -> Unit): ApplicationHost {
return embeddedServer(Jetty, port, module = main)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.ktor.util.*
import org.openjdk.jmh.annotations.*

@State(Scope.Benchmark)
open class BaselinePipeline {
class BaselinePipeline {
val functions = listOf({ "1" }, { "2" }, { "3" })
val suspendFunctions = listOf<suspend () -> String>({ "1" }, { "2" }, { "3" })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.openjdk.jmh.annotations.*
import java.util.concurrent.*

@State(Scope.Benchmark)
open class RoutingBenchmark {
class RoutingBenchmark {
private val testHost: TestApplicationHost = TestApplicationHost(createTestEnvironment())

@Setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import io.ktor.util.*
import org.openjdk.jmh.annotations.*

@State(Scope.Benchmark)
open class ValuesMapBenchmark {
class ValuesMapBenchmark {
private val headers = valuesOf("A" to listOf("B"), "C" to listOf("D"))

@Benchmark
Expand Down

0 comments on commit 395ee2f

Please sign in to comment.