tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
25.44k stars 2.3k forks source link

metrics: Stabilize active_task_count #6619

Open rcoh opened 1 month ago

rcoh commented 1 month ago

Motivation

Stabilize num_active_tasks so it can be used outside of --cfg tokio_unstable

Solution

  1. stabilize num_active_tasks
  2. Rename internal fields to match num_active_tasks
  3. Split rt_metrics into rt_metrics and rt_unstable_metrics.

Refs: #6546

mox692 commented 4 weeks ago

Since https://github.com/tokio-rs/tokio/pull/6114 has been merged, we need to resolve conflict here. Also, perhaps we should stabilize num_active_tasks instead of active_tasks_count?

rcoh commented 3 weeks ago

Ah that comment was attempting to refer to spawned_task_count

On Sat, Jun 15, 2024, 3:06 PM Alice Ryhl @.***> wrote:

@.**** commented on this pull request.

In tokio/src/runtime/metrics/runtime.rs https://github.com/tokio-rs/tokio/pull/6619#discussion_r1641407903:

@@ -47,6 +47,29 @@ impl RuntimeMetrics { self.handle.inner.num_workers() }

  • /// Returns the current number of active tasks in the runtime.
  • ///
  • /// This value increases and decreases over time as tasks are spawned and as they are completed or cancelled.
  • ///
  • /// To see the total number of spawned tasks, see spawned_tasks_count. Note that this API currently requires using --cfg tokio_unstable.

If this is being stabilized, then the documentation should no longer say that it's unstable.

— Reply to this email directly, view it on GitHub https://github.com/tokio-rs/tokio/pull/6619#pullrequestreview-2120793789, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADYKZZO5E3NIQNX465VC7LZHSGEFAVCNFSM6AAAAABI5FHB4SVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCMRQG44TGNZYHE . You are receiving this because you authored the thread.Message ID: @.***>

Darksonn commented 3 weeks ago

Okay. It's a bit confusing like this. You don't need to say that it's unstable in the docs for other methods.

Darksonn commented 1 week ago

I'm sorry for responding slowly here.

I'm wondering whether the name should be something else. The word "active" is the opposite of "idle", but the count includes idle tasks that have not yet exited. How about a name like alive_tasks_count?

rcoh commented 1 week ago

runnable? That has some issues too. I wonder if this would be helped with a TaskMetrics struct that could give some docs to explain the different task states & group the metrics.

On Sun, Jun 30, 2024, 4:46 AM Alice Ryhl @.***> wrote:

I'm sorry for responding slowly here.

I'm wondering whether the name should be something else. The word "active" is the opposite of "idle", but the count includes idle tasks that have not yet exited. How about a name like alive_tasks_count?

— Reply to this email directly, view it on GitHub https://github.com/tokio-rs/tokio/pull/6619#issuecomment-2198515516, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADYKZ5ICVVOKM5II2OKRUTZJ7OXTAVCNFSM6AAAAABI5FHB4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJYGUYTKNJRGY . You are receiving this because you authored the thread.Message ID: @.***>

Darksonn commented 1 week ago

I ended up renaming it in #6667.

Darksonn commented 1 week ago

I don't think runnable works either. That also implies that idle tasks shouldn't be counted, but they are.