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

runtime metrics blocking threads miscount #6550

Open
conradludgate opened this issue May 10, 2024 · 0 comments · May be fixed by #6551
Open

runtime metrics blocking threads miscount #6550

conradludgate opened this issue May 10, 2024 · 0 comments · May be fixed by #6551
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-metrics Module: tokio/runtime/metrics

Comments

@conradludgate
Copy link
Contributor

Version

cargo tree | grep tokio

measured-tokio v0.0.21 (/Users/conrad/Documents/code/better-metrics/tokio)
└── tokio v1.37.0
└── tokio v1.37.0 (*)

Platform

Darwin Conrads-MacBook-Pro.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020 arm64

Description
RuntimeMetrics::num_blocking_threads() double counts the worker_threads().

I tried this code:

let rt = tokio::runtime::Builder::new_multi_thread()
    .worker_threads(4)
    .build()
    .unwrap();
let metrics = rt.metrics();
let workers = metrics.num_workers();
let blocking = metrics.num_blocking_threads();
println!("{workers} - {blocking}");

I expected to see this happen: "4 - 0"

Instead, this happened: "4 - 4"

Tokio worker threads are spawned inside of blocking threads as an implementation detail, so the blocking thread count is artificially inflated.

@conradludgate conradludgate added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels May 10, 2024
@conradludgate conradludgate linked a pull request May 10, 2024 that will close this issue
@mox692 mox692 added the M-metrics Module: tokio/runtime/metrics label May 11, 2024
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-bug Category: This is a bug. M-metrics Module: tokio/runtime/metrics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants