mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-01-24 23:16:48 +00:00
metrics: fix blocking_threads count (#6551)
This commit is contained in:
@@ -8,7 +8,10 @@ impl Handle {
|
||||
}
|
||||
|
||||
pub(crate) fn num_blocking_threads(&self) -> usize {
|
||||
self.blocking_spawner.num_threads()
|
||||
// workers are currently spawned using spawn_blocking
|
||||
self.blocking_spawner
|
||||
.num_threads()
|
||||
.saturating_sub(self.num_workers())
|
||||
}
|
||||
|
||||
pub(crate) fn num_idle_blocking_threads(&self) -> usize {
|
||||
|
||||
@@ -8,7 +8,10 @@ impl Handle {
|
||||
}
|
||||
|
||||
pub(crate) fn num_blocking_threads(&self) -> usize {
|
||||
self.blocking_spawner.num_threads()
|
||||
// workers are currently spawned using spawn_blocking
|
||||
self.blocking_spawner
|
||||
.num_threads()
|
||||
.saturating_sub(self.num_workers())
|
||||
}
|
||||
|
||||
pub(crate) fn num_idle_blocking_threads(&self) -> usize {
|
||||
|
||||
@@ -31,6 +31,11 @@ fn num_blocking_threads() {
|
||||
assert_eq!(0, rt.metrics().num_blocking_threads());
|
||||
let _ = rt.block_on(rt.spawn_blocking(move || {}));
|
||||
assert_eq!(1, rt.metrics().num_blocking_threads());
|
||||
|
||||
let rt = threaded();
|
||||
assert_eq!(0, rt.metrics().num_blocking_threads());
|
||||
let _ = rt.block_on(rt.spawn_blocking(move || {}));
|
||||
assert_eq!(1, rt.metrics().num_blocking_threads());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user