Coroutine scheduler monitoring
See original GitHub issueAre there any monitoring tools available for how many coroutines are currently active and their state etc? It would be nice if it could be exposed so that something like Prometheus can scrape it and visualise it in grafana.
It will also help in debugging leaks - and errors that might occur if we see coroutines just rising linearly
If not can this be done by looking at the thread stats instead?
Go exposes it via runtime.NumGoroutines()
Related:? https://github.com/Kotlin/kotlinx.coroutines/issues/494
Issue Analytics
- State:
- Created 4 years ago
- Reactions:22
- Comments:20 (10 by maintainers)
Top Results From Across the Web
Monitoring with Coroutines @ heycar - Medium
Coroutines are a powerful alternative to several libraries for reactive programming on the JVM. We'll give a background on what they are and ......
Read more >The Beginner's Guide to Kotlin Coroutine Internals
We will discuss what coroutines are, get an overview of language, library and scheduling components of Kotlin coroutines, and then deep dive ...
Read more >Use Kotlin coroutines with lifecycle-aware components
A LifecycleScope is defined for each Lifecycle object. Any coroutine launched in this scope is canceled when the Lifecycle is destroyed. You can ......
Read more >Monitoring metrics for coroutines in production
Since coroutines has graduated to stable, we plan to adopt it in our code more heavily, goals being 1) saner async code than...
Read more >Coroutines and Tasks — cocotb 1.7.2 documentation
Testbenches built using cocotb use Python coroutines. Tasks are cocotb objects that wrap coroutines and are used to schedule concurrent execution of the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Interesting — is there a branch or design doc or something for the reworking? Curious how it’s changing.
My proposal is pretty simple. A few of the core objects involved with coroutine scheduling should be (a) publicly accessible and (b) expose a few properties that provide statistics about them. It’s fine if these are documented as “experiment, up for change, don’t rely on this” and as “fetching these properties may have a performance impact if done frequently” (eg,
ConcurrentLinkedQueue.size
is O(n)).Most specifically, I’d want to have access to
ExperimentalCoroutineDispatcher.coroutineScheduler
(which perhaps would return an interface declared to only contain the metrics below)LimitingDispatcher.queueSize: Int
CoroutineScheduler.corePoolSize: Int
CoroutineScheduler.maxPoolSize: Int
CoroutineScheduler.queueSizes: Map<WorkerState, List<Int>>
CoroutineScheduler.globalQueueSize: Int
CoroutineScheduler.schedulerName: String
(for tagging in the unlikely case of multiple schedulers) (ie, basically all the stuff in CoroutineScheduler.toString(); I think getting the control state isn’t super necessary.)I don’t need kotlinx.coroutines to provide any machinery for hooking this up to my metrics service: I’m happy to keep at application (or external library) level the code that takes the dispatchers I care about, polls them for metrics, and publishes to my metrics service of choice.
We aim to implement it in the next releases after 1.5.0