Skip to content

Commit

Permalink
Fix the description of steal_count
Browse files Browse the repository at this point in the history
`steal_count` falsely claimed to be the number of times tasks where
stolen, but was actually the number of tasks stolen.
The description is wrong for all versions of tokio since at least the
minimum tokio version tokio-metrics currently supports (v1.15).
See: https://github.com/tokio-rs/tokio/blob/f64673580dfc649954eb744eb2734f2f118baa47/tokio/src/runtime/queue.rs#L323
  • Loading branch information
jschwe committed Jan 4, 2023
1 parent 84cbb53 commit 7ababad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -177,11 +177,11 @@ tokio::spawn(do_work());
- **[`min_noop_count`]**
The minimum number of times any worker thread unparked but performed no work before parking again.
- **[`total_steal_count`]**
The number of times worker threads stole tasks from another worker thread.
The number of tasks worker threads stole from another worker thread.
- **[`max_steal_count`]**
The maximum number of times any worker thread stole tasks from another worker thread.
The maximum number of tasks any worker thread stole from another worker thread.
- **[`min_steal_count`]**
The minimum number of times any worker thread stole tasks from another worker thread.
The minimum number of tasks any worker thread stole from another worker thread.
- **[`num_remote_schedules`]**
The number of tasks scheduled from outside of the runtime.
- **[`total_local_schedule_count`]**
Expand Down
16 changes: 10 additions & 6 deletions src/runtime.rs
Expand Up @@ -254,10 +254,11 @@ pub struct RuntimeMetrics {
/// - [`RuntimeMetrics::max_noop_count`]
pub min_noop_count: u64,

/// The number of times worker threads stole tasks from another worker thread.
/// The number of tasks worker threads stole from another worker thread.
///
/// The worker steal count starts increases by one each time the worker has processed its
/// scheduled queue and successfully steals more pending tasks from another worker.
/// The worker steal count starts increases by the amount of stolen tasks each time the worker
/// has processed its scheduled queue and successfully steals more pending tasks from another
/// worker.
///
/// This metric only applies to the **multi-threaded** runtime and will always return `0` when
/// using the current thread runtime.
Expand Down Expand Up @@ -297,7 +298,7 @@ pub struct RuntimeMetrics {
/// // Spawn a task that bumps the previous task out of the "next
/// // scheduled" slot.
/// tokio::spawn(async {});
/// // Blocking receive on the channe.
/// // Blocking receive on the channel.
/// rx.recv().unwrap();
/// flush_metrics().await;
/// }).await.unwrap();
Expand All @@ -321,7 +322,7 @@ pub struct RuntimeMetrics {
/// ```
pub total_steal_count: u64,

/// The maximum number of times any worker thread stole tasks from another worker thread.
/// The maximum number of tasks any worker thread stole from another worker thread.
///
/// ##### Definition
/// This metric is derived from the maximum of [`tokio::runtime::RuntimeMetrics::worker_steal_count`]
Expand All @@ -332,7 +333,7 @@ pub struct RuntimeMetrics {
/// - [`RuntimeMetrics::min_steal_count`]
pub max_steal_count: u64,

/// The minimum number of times any worker thread stole tasks from another worker thread.
/// The minimum number of tasks any worker thread stole from another worker thread.
///
/// ##### Definition
/// This metric is derived from the minimum of [`tokio::runtime::RuntimeMetrics::worker_steal_count`]
Expand Down Expand Up @@ -951,6 +952,7 @@ struct Worker {
total_park_count: u64,
total_noop_count: u64,
total_steal_count: u64,
total_steal_operations: u64,
total_local_schedule_count: u64,
total_overflow_count: u64,
total_polls_count: u64,
Expand Down Expand Up @@ -1088,6 +1090,7 @@ impl Worker {
total_park_count: rt.worker_park_count(worker),
total_noop_count: rt.worker_noop_count(worker),
total_steal_count: rt.worker_steal_count(worker),
total_steal_operations: rt.worker_steal_operations(worker),
total_local_schedule_count: rt.worker_local_schedule_count(worker),
total_overflow_count: rt.worker_overflow_count(worker),
total_polls_count: rt.worker_poll_count(worker),
Expand Down Expand Up @@ -1117,6 +1120,7 @@ impl Worker {
metric!(total_park_count, max_park_count, min_park_count, worker_park_count);
metric!(total_noop_count, max_noop_count, min_noop_count, worker_noop_count);
metric!(total_steal_count, max_steal_count, min_steal_count, worker_steal_count);
metric!(total_steal_operations, max_steal_operations, min_steal_operations, worker_steal_operations);
metric!(total_local_schedule_count, max_local_schedule_count, min_local_schedule_count, worker_local_schedule_count);
metric!(total_overflow_count, max_overflow_count, min_overflow_count, worker_overflow_count);
metric!(total_polls_count, max_polls_count, min_polls_count, worker_poll_count);
Expand Down

0 comments on commit 7ababad

Please sign in to comment.