Skip to content

Commit dd8dc55

Browse files
committed
Setup benchmarks with CI
1 parent b8d72d1 commit dd8dc55

25 files changed

+383
-356
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Benchmarks CI
2+
on:
3+
push:
4+
5+
jobs:
6+
benchmark:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
os: [ ubuntu-latest, macos-latest ]
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: ./.github/actions/setup-gradle
15+
- run: ./gradlew assembleBenchmarks
16+
17+
- run: >
18+
./gradlew
19+
FastCsvLocalRequestChannelBenchmark
20+
FastCsvLocalRequestResponseBenchmark
21+
FastCsvLocalRequestStreamBenchmark
22+
--dry-run
23+
24+
- run: >
25+
./gradlew
26+
FastCsvLocalRequestChannelBenchmark
27+
FastCsvLocalRequestResponseBenchmark
28+
FastCsvLocalRequestStreamBenchmark
29+
--no-parallel
30+
--max-workers=1
31+
32+
- if: always() && !cancelled()
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: benchmark-reports-${{ matrix.os }}
36+
path: "benchmarks/**/build/reports/benchmarks/**/*.csv"
37+
retention-days: 1

.github/workflows/ci-samples.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v4
2121
- uses: ./.github/actions/setup-gradle
22-
with:
23-
cache-read-only: true
2422
- run: ./gradlew build --continue
2523
working-directory: samples/${{ matrix.sample }}

benchmarks/rsocket-java/build.gradle.kts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
import kotlinx.benchmark.gradle.*
1718
import rsocketbuild.*
1819

1920
plugins {
20-
id("rsocketbuild.multiplatform-base")
21-
alias(libs.plugins.kotlin.plugin.allopen)
22-
alias(libs.plugins.kotlinx.benchmark)
21+
id("rsocketbuild.multiplatform-benchmarks")
2322
}
2423

2524
kotlin {
@@ -36,32 +35,13 @@ kotlin {
3635
}
3736
}
3837

39-
allOpen {
40-
annotation("org.openjdk.jmh.annotations.State")
41-
}
42-
4338
benchmark {
4439
targets {
4540
register("jvm") {
46-
this as kotlinx.benchmark.gradle.JvmBenchmarkTarget
41+
this as JvmBenchmarkTarget
4742
jmhVersion = libs.versions.jmh.get()
4843
}
4944
}
50-
configurations {
51-
configureEach {
52-
reportFormat = "text"
53-
}
54-
named("main") {
55-
// all params
56-
param("payloadSize", "0", "64", "1024", "131072", "1048576")
57-
}
58-
register("localPayloadSize") {
59-
include("LocalRSocketJavaBenchmark")
60-
param("payloadSize", "0")
61-
}
62-
register("tcpPayloadSize") {
63-
include("TcpRSocketJavaBenchmark")
64-
param("payloadSize", "0", "64", "4096")
65-
}
66-
}
45+
46+
registerBenchmarks("RSocketJava", listOf("local", "tcp", "ws"))
6747
}

benchmarks/rsocket-java/src/jvmMain/kotlin/LocalRSocketJavaBenchmark.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,8 @@ package io.rsocket.kotlin.benchmarks.java
1818

1919
import io.rsocket.transport.*
2020
import io.rsocket.transport.local.*
21-
import kotlinx.benchmark.*
22-
import kotlinx.coroutines.*
23-
import kotlinx.coroutines.channels.*
2421

25-
@BenchmarkMode(Mode.Throughput)
26-
@Warmup(iterations = 3, time = 1)
27-
@Measurement(iterations = 3, time = 1)
28-
@State(Scope.Benchmark)
2922
class LocalRSocketJavaBenchmark : RSocketJavaBenchmark() {
30-
@Param("0")
31-
override var payloadSize: Int = 0
32-
3323
override val serverTransport: ServerTransport<*> = LocalServerTransport.create("local")
3424
override val clientTransport: ClientTransport = LocalClientTransport.create("local")
3525
}

benchmarks/rsocket-java/src/jvmMain/kotlin/RSocketJavaBenchmark.kt

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ import org.reactivestreams.*
2929
import reactor.core.publisher.*
3030
import kotlin.random.*
3131

32+
@BenchmarkMode(Mode.Throughput)
33+
@Warmup(iterations = WARMUP, time = WARMUP_DURATION)
34+
@Measurement(iterations = ITERATION, time = ITERATION_DURATION)
35+
@State(Scope.Benchmark)
3236
abstract class RSocketJavaBenchmark : RSocketBenchmark<Payload, Blackhole>() {
3337
protected abstract val clientTransport: ClientTransport
3438
protected abstract val serverTransport: ServerTransport<*>
@@ -96,27 +100,33 @@ abstract class RSocketJavaBenchmark : RSocketBenchmark<Payload, Blackhole>() {
96100
server.dispose()
97101
}
98102

99-
// @Benchmark
100-
// override fun requestResponseBlocking(bh: Blackhole) = super.requestResponseBlocking(bh)
101-
//
102-
// @Benchmark
103-
// override fun requestResponseParallel(bh: Blackhole) = super.requestResponseParallel(bh)
104-
//
105-
// @Benchmark
106-
// override fun requestResponseConcurrent(bh: Blackhole) = super.requestResponseConcurrent(bh)
103+
@Param("0")
104+
override var payloadSize: Int = 0
107105

108106
@Benchmark
109-
override fun requestStreamBlocking(bh: Blackhole) {
110-
super.requestStreamBlocking(bh)
111-
}
107+
override fun requestResponseBlocking(bh: Blackhole) = super.requestResponseBlocking(bh)
112108

113109
@Benchmark
114-
override fun requestStreamParallel(bh: Blackhole) {
115-
super.requestStreamParallel(bh)
116-
}
110+
override fun requestResponseParallel(bh: Blackhole) = super.requestResponseParallel(bh)
117111

118112
@Benchmark
119-
override fun requestStreamConcurrent(bh: Blackhole) {
120-
super.requestStreamConcurrent(bh)
121-
}
113+
override fun requestResponseConcurrent(bh: Blackhole) = super.requestResponseConcurrent(bh)
114+
115+
@Benchmark
116+
override fun requestStreamBlocking(bh: Blackhole) = super.requestStreamBlocking(bh)
117+
118+
@Benchmark
119+
override fun requestStreamParallel(bh: Blackhole) = super.requestStreamParallel(bh)
120+
121+
@Benchmark
122+
override fun requestStreamConcurrent(bh: Blackhole) = super.requestStreamConcurrent(bh)
123+
124+
@Benchmark
125+
override fun requestChannelBlocking(bh: Blackhole) = super.requestChannelBlocking(bh)
126+
127+
@Benchmark
128+
override fun requestChannelParallel(bh: Blackhole) = super.requestChannelParallel(bh)
129+
130+
@Benchmark
131+
override fun requestChannelConcurrent(bh: Blackhole) = super.requestChannelConcurrent(bh)
122132
}

benchmarks/rsocket-java/src/jvmMain/kotlin/TcpRSocketJavaBenchmark.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,10 @@
1717
package io.rsocket.kotlin.benchmarks.java
1818

1919
import io.rsocket.transport.*
20-
import io.rsocket.transport.local.*
2120
import io.rsocket.transport.netty.client.*
2221
import io.rsocket.transport.netty.server.*
23-
import kotlinx.benchmark.*
24-
import kotlinx.coroutines.*
25-
import kotlinx.coroutines.channels.*
2622

27-
@BenchmarkMode(Mode.Throughput)
28-
@Warmup(iterations = 3, time = 1)
29-
@Measurement(iterations = 3, time = 1)
30-
@State(Scope.Benchmark)
3123
class TcpRSocketJavaBenchmark : RSocketJavaBenchmark() {
32-
@Param("0")
33-
override var payloadSize: Int = 0
34-
3524
override val serverTransport: ServerTransport<*> = TcpServerTransport.create(9000)
3625
override val clientTransport: ClientTransport = TcpClientTransport.create(9000)
3726
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2015-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.rsocket.kotlin.benchmarks.java
18+
19+
import io.rsocket.transport.*
20+
import io.rsocket.transport.netty.client.*
21+
import io.rsocket.transport.netty.server.*
22+
23+
class WsRSocketJavaBenchmark : RSocketJavaBenchmark() {
24+
override val serverTransport: ServerTransport<*> = WebsocketServerTransport.create(9000)
25+
override val clientTransport: ClientTransport = WebsocketClientTransport.create(9000)
26+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2015-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import kotlinx.benchmark.gradle.*
18+
import org.gradle.kotlin.dsl.benchmark
19+
import rsocketbuild.*
20+
21+
plugins {
22+
id("rsocketbuild.multiplatform-benchmarks")
23+
}
24+
25+
kotlin {
26+
jvmTarget()
27+
28+
// no mingw because of cio
29+
macosX64()
30+
macosArm64()
31+
linuxX64()
32+
33+
sourceSets {
34+
commonMain.dependencies {
35+
implementation(projects.benchmarksShared)
36+
implementation("io.rsocket.kotlin:rsocket-transport-local:0.16.0")
37+
implementation("io.rsocket.kotlin:rsocket-transport-ktor-tcp:0.16.0")
38+
}
39+
}
40+
}
41+
42+
benchmark {
43+
targets {
44+
register("jvm") {
45+
this as JvmBenchmarkTarget
46+
jmhVersion = libs.versions.jmh.get()
47+
}
48+
register("macosArm64")
49+
register("macosX64")
50+
register("linuxX64")
51+
}
52+
registerBenchmarks("RSocketKotlin_0_16_", listOf("local", "ktorTcp")) { transport ->
53+
if (transport == "local") {
54+
param("dispatcher", "DEFAULT", "UNCONFINED")
55+
}
56+
}
57+
}

benchmarks/rsocket-kotlin-old/src/commonMain/kotlin/KtorTcpRSocketKotlinBenchmark.kt renamed to benchmarks/rsocket-kotlin-0_16/src/commonMain/kotlin/KtorTcpRSocketKotlin_0_16_Benchmark.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
package io.rsocket.kotlin.benchmarks.kotlin
1818

1919
import io.ktor.network.sockets.*
20+
import io.rsocket.kotlin.benchmarks.*
2021
import io.rsocket.kotlin.transport.*
2122
import io.rsocket.kotlin.transport.ktor.tcp.*
2223
import kotlinx.benchmark.*
2324
import kotlinx.coroutines.*
2425
import kotlin.random.*
2526

2627
@BenchmarkMode(Mode.Throughput)
27-
@Warmup(iterations = 3, time = 1)
28-
@Measurement(iterations = 3, time = 1)
28+
@Warmup(iterations = WARMUP, time = WARMUP_DURATION)
29+
@Measurement(iterations = ITERATION, time = ITERATION_DURATION)
2930
@State(Scope.Benchmark)
30-
class KtorTcpRSocketKotlinOldBenchmark : RSocketKotlinOldBenchmark() {
31+
class KtorTcpRSocketKotlin_0_16_Benchmark : RSocketKotlin_0_16_Benchmark() {
3132
@Param("0")
3233
override var payloadSize: Int = 0
3334

benchmarks/rsocket-kotlin-old/src/commonMain/kotlin/LocalRSocketKotlinOldBenchmark.kt renamed to benchmarks/rsocket-kotlin-0_16/src/commonMain/kotlin/LocalRSocketKotlin_0_16_Benchmark.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@
1616

1717
package io.rsocket.kotlin.benchmarks.kotlin
1818

19+
import io.rsocket.kotlin.benchmarks.*
1920
import io.rsocket.kotlin.transport.*
2021
import io.rsocket.kotlin.transport.local.*
2122
import kotlinx.benchmark.*
2223
import kotlinx.coroutines.*
2324

2425
@BenchmarkMode(Mode.Throughput)
25-
@Warmup(iterations = 3, time = 1)
26-
@Measurement(iterations = 3, time = 1)
26+
@Warmup(iterations = WARMUP, time = WARMUP_DURATION)
27+
@Measurement(iterations = ITERATION, time = ITERATION_DURATION)
2728
@State(Scope.Benchmark)
28-
class LocalRSocketKotlinOldBenchmark : RSocketKotlinOldBenchmark() {
29-
@Param("0")
30-
override var payloadSize: Int = 0
31-
29+
class LocalRSocketKotlin_0_16_Benchmark : RSocketKotlin_0_16_Benchmark() {
3230
@Param("")
3331
var dispatcher: String = ""
3432

0 commit comments

Comments
 (0)