Skip to content

Commit 56b1d2b

Browse files
committed
Update channel "producer-consumer" and semaphore micro-benchmarks
1 parent ccde0c7 commit 56b1d2b

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

benchmarks/src/jmh/kotlin/benchmarks/ChannelProducerConsumerBenchmark.kt

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package benchmarks
66

77
import kotlinx.coroutines.*
88
import kotlinx.coroutines.channels.Channel
9+
import kotlinx.coroutines.scheduling.*
910
import kotlinx.coroutines.selects.select
1011
import org.openjdk.jmh.annotations.*
1112
import org.openjdk.jmh.infra.Blackhole
@@ -33,7 +34,7 @@ import java.util.concurrent.TimeUnit
3334
@State(Scope.Benchmark)
3435
open class ChannelProducerConsumerBenchmark {
3536
@Param
36-
private var _0_dispatcher: DispatcherCreator = DispatcherCreator.FORK_JOIN
37+
private var _0_dispatcher: DispatcherCreator = DispatcherCreator.DEFAULT
3738

3839
@Param
3940
private var _1_channel: ChannelCreator = ChannelCreator.RENDEZVOUS
@@ -44,10 +45,8 @@ open class ChannelProducerConsumerBenchmark {
4445
@Param("false", "true")
4546
private var _3_withSelect: Boolean = false
4647

47-
@Param("1", "2", "4") // local machine
48-
// @Param("1", "2", "4", "8", "12") // local machine
49-
// @Param("1", "2", "4", "8", "16", "32", "64", "128", "144") // dasquad
50-
// @Param("1", "2", "4", "8", "16", "32", "64", "96") // Google Cloud
48+
@Param("1", "2", "4", "8", "16") // local machine
49+
// @Param("1", "2", "4", "8", "16", "32", "64", "128") // Server
5150
private var _4_parallelism: Int = 0
5251

5352
private lateinit var dispatcher: CoroutineDispatcher
@@ -128,14 +127,14 @@ open class ChannelProducerConsumerBenchmark {
128127
}
129128

130129
enum class DispatcherCreator(val create: (parallelism: Int) -> CoroutineDispatcher) {
131-
FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() })
130+
//FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() }),
131+
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
132+
DEFAULT({ parallelism -> ExperimentalCoroutineDispatcher(corePoolSize = parallelism, maxPoolSize = parallelism) })
132133
}
133134

134135
enum class ChannelCreator(private val capacity: Int) {
135136
RENDEZVOUS(Channel.RENDEZVOUS),
136-
// BUFFERED_1(1),
137-
BUFFERED_2(2),
138-
// BUFFERED_4(4),
137+
BUFFERED_4(4),
139138
BUFFERED_32(32),
140139
BUFFERED_128(128),
141140
BUFFERED_UNLIMITED(Channel.UNLIMITED);

benchmarks/src/jmh/kotlin/benchmarks/SemaphoreBenchmark.kt

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package benchmarks
77
import benchmarks.common.*
88
import kotlinx.coroutines.*
99
import kotlinx.coroutines.channels.*
10+
import kotlinx.coroutines.scheduling.*
1011
import kotlinx.coroutines.sync.*
1112
import org.openjdk.jmh.annotations.*
1213
import java.util.concurrent.*
@@ -19,17 +20,16 @@ import java.util.concurrent.*
1920
@State(Scope.Benchmark)
2021
open class SemaphoreBenchmark {
2122
@Param
22-
private var _1_dispatcher: SemaphoreBenchDispatcherCreator = SemaphoreBenchDispatcherCreator.FORK_JOIN
23+
private var _1_dispatcher: SemaphoreBenchDispatcherCreator = SemaphoreBenchDispatcherCreator.DEFAULT
2324

2425
@Param("0", "1000")
2526
private var _2_coroutines: Int = 0
2627

2728
@Param("1", "2", "4", "8", "32", "128", "100000")
2829
private var _3_maxPermits: Int = 0
2930

30-
@Param("1", "2", "4") // local machine
31-
// @Param("1", "2", "4", "8", "16", "32", "64", "128", "144") // dasquad
32-
// @Param("1", "2", "4", "8", "16", "32", "64", "96") // Google Cloud
31+
@Param("1", "2", "4", "8", "16") // local machine
32+
// @Param("1", "2", "4", "8", "16", "32", "64", "128") // Server
3333
private var _4_parallelism: Int = 0
3434

3535
private lateinit var dispatcher: CoroutineDispatcher
@@ -80,10 +80,11 @@ open class SemaphoreBenchmark {
8080
}
8181

8282
enum class SemaphoreBenchDispatcherCreator(val create: (parallelism: Int) -> CoroutineDispatcher) {
83-
FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() }),
84-
EXPERIMENTAL({ parallelism -> Dispatchers.Default }) // TODO doesn't take parallelism into account
83+
// FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() }),
84+
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
85+
DEFAULT({ parallelism -> ExperimentalCoroutineDispatcher(corePoolSize = parallelism, maxPoolSize = parallelism) })
8586
}
8687

87-
private const val WORK_INSIDE = 80
88-
private const val WORK_OUTSIDE = 40
89-
private const val BATCH_SIZE = 1000000
88+
private const val WORK_INSIDE = 50
89+
private const val WORK_OUTSIDE = 50
90+
private const val BATCH_SIZE = 100000

0 commit comments

Comments
 (0)