question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coroutine scheduler monitoring

See original GitHub issue

Are 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:open
  • Created 4 years ago
  • Reactions:22
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

19reactions
glassercommented, Aug 14, 2019

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.

17reactions
qwwdfsadcommented, Apr 6, 2021

We aim to implement it in the next releases after 1.5.0

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found