Skip to content

Doc/deferred #3643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 98 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
845e322
Update Kotlin to 1.7.10 (#3324)
qwwdfsad Jul 14, 2022
19666ac
Use Platform.getAvailableProcessors for K/N Dispatchers.Default (#3366)
qwwdfsad Jul 14, 2022
3e7873f
Reduce unnecessary @PublishedApi surface of UnbiasedSelectBuilderImpl…
qwwdfsad Jul 25, 2022
007b5a5
Mark context in DiagnosticCoroutineContextException as transient (#3370)
qwwdfsad Jul 26, 2022
5c582ee
Get rid of the old Kotlin/Native memory model (#3376)
qwwdfsad Jul 27, 2022
3120530
Introduce Job.parent API (#3384)
qwwdfsad Jul 29, 2022
371e4f3
Introduce a rendezvous on CancellableContinuationImpl.parentHandle to…
qwwdfsad Aug 2, 2022
521ee78
Update Kover to 0.6.0-Beta (#3386)
qwwdfsad Aug 4, 2022
9e886f1
Update select-guide timings to be precise (#3387)
qwwdfsad Aug 4, 2022
feea6a5
New `select` and `Mutex` implementations (#3020)
ndkoval Aug 4, 2022
03176c7
Recover proper coverage filtering and add few more tests for legacy s…
qwwdfsad Aug 4, 2022
a78dd11
Introduce Java Object Layout to the codebase and write tests for core…
qwwdfsad Aug 4, 2022
7d8e275
Merge branch 'master' into develop
qwwdfsad Sep 5, 2022
73f780c
Fix cancelled delayed jobs not being disposed of in TestDispatcher (#…
dkhalanskyjb Sep 8, 2022
03e6a74
Properly cancel handles returned by setTimeout in JS dispatchers (#3440)
qwwdfsad Sep 8, 2022
9e1eb9e
Update wording in shared-mutable-state-and-concurrency.md
qwwdfsad Sep 8, 2022
4a44fef
Fix another potential memory leak in WorkerDispatcher (#3445)
dkhalanskyjb Sep 8, 2022
4e97c83
Get rid of workaround for KT-16222 that is long time fixed (#3446)
qwwdfsad Sep 9, 2022
1fc01e7
Replace hand-rolled ArrayQueue with ArrayDeque in standard library in…
qwwdfsad Sep 9, 2022
df9421a
Update delay and withTimeout* documentation (#3451)
qwwdfsad Sep 13, 2022
3327273
Update Dispatchers.Main documentation (#3450)
qwwdfsad Sep 13, 2022
5322c8d
Ensure awaitFrame() only awaits a single frame when used from the mai…
qwwdfsad Sep 16, 2022
7f557e9
Preparation for atomicfu JVM IR plugin application in 1.7.20 (#3455)
mvicsokolova Sep 20, 2022
61ba10d
Introduce non-nullable types in reactive integrations where appropria…
qwwdfsad Sep 20, 2022
bb16214
Remove Class-Path attribute from debug JAR (#3402)
qwwdfsad Sep 27, 2022
4a5892f
Properly use UndispatchedCoroutine context for context-specific eleme…
qwwdfsad Sep 27, 2022
dc58806
Allow customization of default scheduler name on JVM (#3465)
IgnatBeresnev Sep 28, 2022
85a2601
Add parametrized Flow#filterIsInstance extension (#3464)
IgnatBeresnev Sep 28, 2022
4f1d41f
Adjust Gradle configuration and introduce allWarningsAsErrors (#3466)
qwwdfsad Sep 28, 2022
935faf7
Use outputFileProperty instead of outputFile (#3460)
ilgonmic Oct 5, 2022
cefd9c0
Update Kover version to 0.6.1 (#3471)
qwwdfsad Oct 5, 2022
d2503c0
Add timeout operator to Flow as @FlowPreview (#3148)
pablobaxter Oct 5, 2022
f77f6dd
Make use of `CompletionStage#handle` instead of `whenComplete` (#3475)
He-Pin Oct 11, 2022
27396e7
Fix flakiness of TimeoutTest (#3477)
qwwdfsad Oct 11, 2022
150f185
Update Kotlin to 1.7.20 (#3478)
qwwdfsad Oct 12, 2022
298eb11
New implementation of K/N multi-threaded dispatchers (#3421)
qwwdfsad Oct 12, 2022
1656a0d
Get rid of real time in TimeoutTest
qwwdfsad Oct 12, 2022
f3527c9
Merge kotlinx-coroutines-core and kotlinx-coroutines-jdk8 modules (#3…
qwwdfsad Oct 12, 2022
92a2495
Make Mono.awaitSingleOrNull wait for onComplete() (#3489)
dkhalanskyjb Oct 19, 2022
8947818
Integration test step in Train (#3486)
mvicsokolova Oct 20, 2022
449b7a0
docs: fix link in immediate documentation (#3491)
francescotescari Oct 20, 2022
0bb8ee8
Display artificial stack frames as calls to functions instead of text…
dkhalanskyjb Oct 20, 2022
8724e63
Update binary compatibility validator to 0.12.0 (#3496)
qwwdfsad Oct 21, 2022
02bf356
Add overloads for runTest that accept a Duration (#3483)
hfhbd Oct 21, 2022
4a13d58
Apply "configure-compilation-conventions" script earlier (#3488)
mvicsokolova Oct 25, 2022
bfc6c0b
Deprecate SharedFlow.toList(dst) and toSet(dst) (#3500)
dkhalanskyjb Oct 25, 2022
06b3b3b
Publish empty kotlinx-coroutines-jdk8 artifact (#3510)
qwwdfsad Oct 31, 2022
6c9d358
Remove some broken tests (#3513)
dkhalanskyjb Oct 31, 2022
4e29357
Disable tests with real source of the time on Java's Windows to preve…
qwwdfsad Nov 3, 2022
30e905c
Update atomicfu to 0.18.5 (#3501)
mvicsokolova Nov 15, 2022
9ae476f
Stabilize isClosedForSend and isClosedForReceive (#3517)
qwwdfsad Nov 16, 2022
c87589d
Fix Java targetCompatibility was not configured in kotlinx-coroutines…
Tapchicoma Nov 21, 2022
287d038
Fix coroutines dump tests (#3524)
anti-social Nov 21, 2022
54cf4fc
Merge pull request #3535 from Kotlin/kotlin-1.8.0/fix-jvm-target
woainikk Nov 22, 2022
4e25853
Remove no longer relevant third-party license file that was added as …
qwwdfsad Nov 22, 2022
cb0b51e
Update Kotlin to 1.8.0-Beta (#3549)
qwwdfsad Dec 7, 2022
ccde0c7
Fix a suppressed warning
dkhalanskyjb Dec 13, 2022
184d395
Mention value-based conflation in MutableStateFlow (#3539)
qwwdfsad Dec 27, 2022
7205177
Update JMH (#3531)
qwwdfsad Dec 27, 2022
28d98e8
Chore(infra): Prepare coroutines for including to the community proje…
stasjas Dec 9, 2022
c194877
Make EventLoopImplBase properly synchronized on Kotlin/Native (#3550)
qwwdfsad Dec 27, 2022
8eb8e68
Merge pull request #3559 from Kotlin/kotlin-community/dev
stasjas Dec 28, 2022
f4c5725
Merge branch 'master' into develop
qwwdfsad Jan 2, 2023
b74e039
Eliminate unneeded `LimitedDispatcher` instances on `Dispatchers.Defa…
dovchinnikov Jan 2, 2023
0eb94dd
Update atomicfu to 0.19.0 (#3570)
mvicsokolova Jan 3, 2023
e6ddc81
Remove unused internal function (#3573)
qwwdfsad Jan 3, 2023
67e21b2
Fix flaky SharingReferenceTest the same way it was addressed in #2709…
qwwdfsad Jan 5, 2023
c3b7b20
Promote @FlowPreview API to stable/experimental (#3548)
qwwdfsad Jan 13, 2023
ebff885
Make scan and runningFold documentation example consistent with other…
qwwdfsad Jan 16, 2023
87d1af9
Introduce a separate slot for stealing tasks into in CoroutineSchedul…
qwwdfsad Jan 16, 2023
4102f90
Increment WorkQueue.blockingTasksInBuffer only after capacity check (…
qwwdfsad Jan 16, 2023
71125e3
Do not propagate exceptions to CoroutineExceptionHandler in 'future' …
qwwdfsad Jan 16, 2023
eb21974
Prevent `runBlocking` failure when the Worker it runs on terminates (…
dkhalanskyjb Jan 17, 2023
6a6e62d
Remove obsolete and misleading line from the documentation (#3590)
qwwdfsad Jan 19, 2023
79d885f
Remove ThreadLocal from ThreadLocalMap when finishing UndispatchedCor…
qwwdfsad Jan 24, 2023
eac0b07
KotlinxTrain: add mavenLocal repo (#3599)
woainikk Jan 25, 2023
cca82e7
Improve DebugProbes performance (#3534)
qwwdfsad Feb 1, 2023
33220fc
Remove docs about Dispatchers.kt that replicate the common code (#3614)
dkhalanskyjb Feb 2, 2023
32af157
Fix suspend-resume race in DebugProbes (#3514)
qwwdfsad Feb 2, 2023
e946cd7
Don't allocate threads on every dispatch in Native's thread pools (#3…
dkhalanskyjb Feb 13, 2023
e7cf632
Introduce fast and scalable channels (#3103)
ndkoval Feb 13, 2023
54c3108
NonConcurrentlyModifiable concurrency failures should identify both p…
mcumings Feb 13, 2023
f538af6
Workaround for debugger+compiler crash (#3625)
qwwdfsad Feb 14, 2023
b6e1839
Explain the test framework behavior in the withTimeout message (#3623)
dkhalanskyjb Feb 14, 2023
8c4ff51
Preserve mutex invariant: throw ISE when incorrect access with owner …
qwwdfsad Feb 14, 2023
fc6c811
Remove dead-code in the LockFreeLinkedList implementation after new c…
qwwdfsad Feb 14, 2023
36065e6
Restore TCO in BufferedChannel (#3627)
qwwdfsad Feb 14, 2023
dc19e1f
Update Kotlin to 1.8.10 (#3628)
qwwdfsad Feb 15, 2023
7f4b80c
Add explicit module-info.java for JPMS compatibility (#3629)
qwwdfsad Feb 21, 2023
3b22c27
Allow specifying the timeout for `runTest` (#3603)
dkhalanskyjb Feb 21, 2023
c5f73ba
Update atomicfu to 0.20.0
mvicsokolova Feb 21, 2023
7014961
Update the documentation for runTest (#3632)
dkhalanskyjb Feb 22, 2023
bf03c48
Remove some ExperimentalCoroutinesApi markers in the test module (#3622)
dkhalanskyjb Feb 22, 2023
1ed19c8
Introduce first version of Dispatchers.IO for K/N (#3576)
qwwdfsad Feb 22, 2023
747db9e
Change the contract of CoroutineContext.isActive to return 'true' for…
qwwdfsad Feb 23, 2023
1245d7e
Attempt to report uncaught exceptions in the test module (#3449)
dkhalanskyjb Feb 24, 2023
c176901
TestTimeSource: Expose comparable timemarks (#3617)
hfhbd Feb 3, 2023
69a9fcd
Remove duplicated 'be' from Deferred kdoc
tommus Feb 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ build
out
target
local.properties
benchmarks.jar
/kotlin-js-store
5 changes: 5 additions & 0 deletions .idea/dictionaries/shared.xml

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

18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
[![JetBrains official project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub)
[![GitHub license](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0)
[![Download](https://img.shields.io/maven-central/v/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.6.4)](https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core/1.6.4/pom)
[![Kotlin](https://img.shields.io/badge/kotlin-1.6.21-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/kotlin-1.8.10-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Slack channel](https://img.shields.io/badge/chat-slack-green.svg?logo=slack)](https://kotlinlang.slack.com/messages/coroutines/)

Library support for Kotlin coroutines with [multiplatform](#multiplatform) support.
This is a companion version for the Kotlin `1.6.21` release.
This is a companion version for the Kotlin `1.8.10` release.

```kotlin
suspend fun main() = coroutineScope {
Expand Down Expand Up @@ -37,6 +37,7 @@ suspend fun main() = coroutineScope {
* [core/jvm](kotlinx-coroutines-core/jvm/) — additional core features available on Kotlin/JVM:
* [Dispatchers.IO] dispatcher for blocking coroutines;
* [Executor.asCoroutineDispatcher][asCoroutineDispatcher] extension, custom thread pools, and more.
* Integrations with `CompletableFuture` and JVM-specific extensions.
* [core/js](kotlinx-coroutines-core/js/) — additional core features available on Kotlin/JS:
* Integration with `Promise` via [Promise.await] and [promise] builder;
* Integration with `Window` via [Window.asCoroutineDispatcher], etc.
Expand All @@ -56,7 +57,7 @@ suspend fun main() = coroutineScope {
* [ui](ui/README.md) — modules that provide coroutine dispatchers for various single-threaded UI libraries:
* Android, JavaFX, and Swing.
* [integration](integration/README.md) — modules that provide integration with various asynchronous callback- and future-based libraries:
* JDK8 [CompletionStage.await], Guava [ListenableFuture.await], and Google Play Services [Task.await];
* Guava [ListenableFuture.await], and Google Play Services [Task.await];
* SLF4J MDC integration via [MDCContext].

## Documentation
Expand Down Expand Up @@ -92,7 +93,7 @@ And make sure that you use the latest Kotlin version:

```xml
<properties>
<kotlin.version>1.6.21</kotlin.version>
<kotlin.version>1.8.10</kotlin.version>
</properties>
```

Expand All @@ -111,10 +112,10 @@ And make sure that you use the latest Kotlin version:
```kotlin
plugins {
// For build.gradle.kts (Kotlin DSL)
kotlin("jvm") version "1.6.21"
kotlin("jvm") version "1.8.10"

// For build.gradle (Groovy DSL)
id "org.jetbrains.kotlin.jvm" version "1.6.21"
id "org.jetbrains.kotlin.jvm" version "1.8.10"
}
```

Expand Down Expand Up @@ -211,7 +212,7 @@ See [Contributing Guidelines](CONTRIBUTING.md).
[MainScope()]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-main-scope.html
[SupervisorJob()]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-supervisor-job.html
[CoroutineExceptionHandler]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-exception-handler/index.html
[Dispatchers.IO]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-i-o.html
[Dispatchers.IO]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-i-o.html
[asCoroutineDispatcher]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/as-coroutine-dispatcher.html
[Promise.await]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/await.html
[promise]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/promise.html
Expand Down Expand Up @@ -259,9 +260,6 @@ See [Contributing Guidelines](CONTRIBUTING.md).

<!--- MODULE kotlinx-coroutines-jdk8 -->
<!--- INDEX kotlinx.coroutines.future -->

[CompletionStage.await]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/await.html

<!--- MODULE kotlinx-coroutines-guava -->
<!--- INDEX kotlinx.coroutines.guava -->

Expand Down
25 changes: 6 additions & 19 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

@file:Suppress("UnstableApiUsage")

import me.champeau.gradle.*
import me.champeau.jmh.*
import org.jetbrains.kotlin.gradle.tasks.*

plugins {
id("com.github.johnrengelman.shadow")
id("me.champeau.gradle.jmh") apply false
id("me.champeau.jmh")
}

repositories {
Expand All @@ -21,33 +21,19 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
}

apply(plugin="me.champeau.gradle.jmh")

tasks.named<KotlinCompile>("compileJmhKotlin") {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-Xjvm-default=enable"
}
}

// It is better to use the following to run benchmarks, otherwise you may get unexpected errors:
// ./gradlew --no-daemon cleanJmhJar jmh -Pjmh="MyBenchmark"
extensions.configure<JMHPluginExtension>("jmh") {
jmhVersion = "1.26"
duplicateClassesStrategy = DuplicatesStrategy.INCLUDE
failOnError = true
resultFormat = "CSV"
project.findProperty("jmh")?.also {
include = listOf(".*$it.*")
}
// includeTests = false
}

val jmhJarTask = tasks.named<Jar>("jmhJar") {
archiveBaseName by "benchmarks"
archiveClassifier by null
archiveVersion by null
destinationDirectory.file("$rootDir")
archiveVersion.convention(null as String?)
destinationDirectory.set(file("$rootDir"))
}

tasks {
Expand All @@ -63,13 +49,14 @@ tasks {
}

dependencies {
implementation("org.openjdk.jmh:jmh-core:1.26")
implementation("org.openjdk.jmh:jmh-core:1.35")
implementation("io.projectreactor:reactor-core:${version("reactor")}")
implementation("io.reactivex.rxjava2:rxjava:2.1.9")
implementation("com.github.akarnokd:rxjava2-extensions:0.20.8")

implementation("com.typesafe.akka:akka-actor_2.12:2.5.0")
implementation(project(":kotlinx-coroutines-core"))
implementation(project(":kotlinx-coroutines-debug"))
implementation(project(":kotlinx-coroutines-reactive"))

// add jmh dependency on main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

package benchmarks

import benchmarks.common.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.scheduling.*
import kotlinx.coroutines.selects.select
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole
import java.lang.Integer.max
import java.util.concurrent.ForkJoinPool
import java.util.concurrent.Phaser
import java.util.concurrent.ThreadLocalRandom
import java.util.concurrent.TimeUnit


Expand All @@ -26,14 +25,14 @@ import java.util.concurrent.TimeUnit
* Please, be patient, this benchmark takes quite a lot of time to complete.
*/
@Warmup(iterations = 3, time = 500, timeUnit = TimeUnit.MICROSECONDS)
@Measurement(iterations = 10, time = 500, timeUnit = TimeUnit.MICROSECONDS)
@Fork(value = 3)
@BenchmarkMode(Mode.AverageTime)
@Measurement(iterations = 20, time = 500, timeUnit = TimeUnit.MICROSECONDS)
@Fork(value = 1)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
open class ChannelProducerConsumerBenchmark {
@Param
private var _0_dispatcher: DispatcherCreator = DispatcherCreator.FORK_JOIN
private var _0_dispatcher: DispatcherCreator = DispatcherCreator.DEFAULT

@Param
private var _1_channel: ChannelCreator = ChannelCreator.RENDEZVOUS
Expand All @@ -44,12 +43,13 @@ open class ChannelProducerConsumerBenchmark {
@Param("false", "true")
private var _3_withSelect: Boolean = false

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

@Param("50")
private var _5_workSize: Int = 0

private lateinit var dispatcher: CoroutineDispatcher
private lateinit var channel: Channel<Int>

Expand All @@ -61,13 +61,21 @@ open class ChannelProducerConsumerBenchmark {
}

@Benchmark
fun spmc() {
fun mcsp() {
if (_2_coroutines != 0) return
val producers = max(1, _4_parallelism - 1)
val consumers = 1
run(producers, consumers)
}

@Benchmark
fun spmc() {
if (_2_coroutines != 0) return
val producers = 1
val consumers = max(1, _4_parallelism - 1)
run(producers, consumers)
}

@Benchmark
fun mpmc() {
val producers = if (_2_coroutines == 0) (_4_parallelism + 1) / 2 else _2_coroutines / 2
Expand All @@ -76,7 +84,7 @@ open class ChannelProducerConsumerBenchmark {
}

private fun run(producers: Int, consumers: Int) {
val n = APPROX_BATCH_SIZE / producers * producers
val n = (APPROX_BATCH_SIZE / producers * producers) / consumers * consumers
val phaser = Phaser(producers + consumers + 1)
// Run producers
repeat(producers) {
Expand Down Expand Up @@ -111,7 +119,7 @@ open class ChannelProducerConsumerBenchmark {
} else {
channel.send(element)
}
doWork()
doWork(_5_workSize)
}

private suspend fun consume(dummy: Channel<Int>?) {
Expand All @@ -123,28 +131,25 @@ open class ChannelProducerConsumerBenchmark {
} else {
channel.receive()
}
doWork()
doWork(_5_workSize)
}
}

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

enum class ChannelCreator(private val capacity: Int) {
RENDEZVOUS(Channel.RENDEZVOUS),
// BUFFERED_1(1),
BUFFERED_2(2),
// BUFFERED_4(4),
BUFFERED_32(32),
BUFFERED_128(128),
BUFFERED_16(16),
BUFFERED_64(64),
BUFFERED_UNLIMITED(Channel.UNLIMITED);

fun create(): Channel<Int> = Channel(capacity)
}

private fun doWork(): Unit = Blackhole.consumeCPU(ThreadLocalRandom.current().nextLong(WORK_MIN, WORK_MAX))
private fun doWork(workSize: Int): Unit = doGeomDistrWork(workSize)

private const val WORK_MIN = 50L
private const val WORK_MAX = 100L
private const val APPROX_BATCH_SIZE = 100000
private const val APPROX_BATCH_SIZE = 100_000
19 changes: 10 additions & 9 deletions benchmarks/src/jmh/kotlin/benchmarks/SemaphoreBenchmark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package benchmarks
import benchmarks.common.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.scheduling.*
import kotlinx.coroutines.sync.*
import org.openjdk.jmh.annotations.*
import java.util.concurrent.*
Expand All @@ -19,17 +20,16 @@ import java.util.concurrent.*
@State(Scope.Benchmark)
open class SemaphoreBenchmark {
@Param
private var _1_dispatcher: SemaphoreBenchDispatcherCreator = SemaphoreBenchDispatcherCreator.FORK_JOIN
private var _1_dispatcher: SemaphoreBenchDispatcherCreator = SemaphoreBenchDispatcherCreator.DEFAULT

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

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

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

private lateinit var dispatcher: CoroutineDispatcher
Expand Down Expand Up @@ -80,10 +80,11 @@ open class SemaphoreBenchmark {
}

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

private const val WORK_INSIDE = 80
private const val WORK_OUTSIDE = 40
private const val BATCH_SIZE = 1000000
private const val WORK_INSIDE = 50
private const val WORK_OUTSIDE = 50
private const val BATCH_SIZE = 100000
Loading