https://kotlinlang.org logo
#coroutines
Title
# coroutines
k

kevinherron

10/22/2019, 5:33 PM
I’m seeing some pretty disappointing CPU usage from a low throughput coroutines workload (sending ~40-50 network requests per second) that is all non-blocking I/O, barely any CPU work. Using the async profiler shows the DefaultDispatcher threads are spending the majority of their time in the coroutines scheduler (mostly in
Worker.doPark
or
WorkQueue.trySteal
. Is this… expected?
l

Luis Munoz

10/22/2019, 5:37 PM
I don't understand your question, you say you are disappointment in CPU usage and you say you you have tasks that do barely any CPU work. Seems like a contradiction to me. If the tasks are IO bound then I would expect all the threads to be parked doing nothing.
k

kevinherron

10/22/2019, 5:37 PM
My point is that the coroutine scheduler itself is using much more CPU than I would expect
m

marstran

10/22/2019, 6:18 PM
When your code is mainly waiting for IO, then the percentage of time spent in the scheduler will go up because nothing else are running.
k

kevinherron

10/22/2019, 6:40 PM
@elizarov @Vsevolod Tolstopyatov [JB] is it possible this branch will improve things? https://github.com/Kotlin/kotlinx.coroutines/tree/scheduler-changes
v

Vsevolod Tolstopyatov [JB]

10/22/2019, 6:41 PM
yes, that's its point :)
k

kevinherron

10/22/2019, 6:42 PM
👍
i’d test instead of ask a stupid question but I can’t seem to build it right now because I don’t have Xcode installed
this jprofiler call tree seems crazy to me. 12 million invocations of
findTaskWithCpuPermit
to only 20,000 actual calls into suspended code (
DispatchedTask.run
)
v

Vsevolod Tolstopyatov [JB]

10/22/2019, 6:45 PM
(sending from my phone, so can't give more detailed instructions) you can comment out all native targets from https://github.com/Kotlin/kotlinx.coroutines/blob/master/gradle/compile-native-multiplatform.gradle
k

kevinherron

10/22/2019, 6:45 PM
(image not uploading)
thanks for the link
message has been deleted
@Vsevolod Tolstopyatov [JB] that branch makes a significant difference in CPU usages. Nice work 👍
11 Views