Skip to content
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

API for number of active tokio tasks? #5400

Closed
coder3101 opened this issue Jan 26, 2023 · 3 comments · Fixed by #5628
Closed

API for number of active tokio tasks? #5400

coder3101 opened this issue Jan 26, 2023 · 3 comments · Fixed by #5628
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-metrics Module: tokio/runtime/metrics

Comments

@coder3101
Copy link

coder3101 commented Jan 26, 2023

Is your feature request related to a problem? Please describe.
I would like to get the count of active running tokio tasks. In python, I can use len(asyncio.all_tasks()) which returns the unfinished tasks for the current running loop.

Describe the solution you'd like
A simple associated function such as tokio::active_tasks() which could return the number or as with asyncio.all_tasks() return a set of not yet finished Task objects run by the loop.

Describe alternatives you've considered
There are debugging tools such as tokio-rs/console or tracing which helps achieve the same but they are mainly suited for debugging purpose. Is there a way to get those information in production?

Additional context
Originally asked as question on stackoverflow

@coder3101 coder3101 added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Jan 26, 2023
@Darksonn Darksonn added the M-metrics Module: tokio/runtime/metrics label Jan 27, 2023
@Darksonn
Copy link
Contributor

Adding this to tokio::runtime::RuntimeMetrics sounds like a good idea.

matildasmeds added a commit to matildasmeds/tokio that referenced this issue Apr 16, 2023
Adds a new metric for the number of active tasks  for the Runtime. We count
the elements on the OwnedTasks LinkedList, and access that through RuntimeMetrics.

Closes: tokio-rs#5400
matildasmeds added a commit to matildasmeds/tokio that referenced this issue Apr 16, 2023
Adds a new metric for the number of active tasks  for the Runtime. We count
the elements on the OwnedTasks LinkedList, and access that through RuntimeMetrics.

Closes: tokio-rs#5400
@coder3101
Copy link
Author

When and which version of tokio will include this newly added metric?

@Darksonn
Copy link
Contributor

It will be available in 1.29, which will be released about one month from now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-metrics Module: tokio/runtime/metrics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants