From 28ab3551a337839bad3c434e219b61757b461fc5 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Tue, 26 Nov 2024 16:08:12 +0100 Subject: [PATCH] chore: avoid deprecated items, fix warnings (#66) --- Cargo.toml | 9 ++++-- src/runtime.rs | 74 ++++++++++++++++++++++++-------------------------- src/task.rs | 12 ++++---- 3 files changed, 48 insertions(+), 47 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b368b68..e3f1996 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "tokio-metrics" version = "0.3.1" edition = "2021" -rust-version = "1.56.0" +rust-version = "1.70.0" authors = ["Tokio Contributors "] license = "MIT" readme = "README.md" @@ -14,6 +14,9 @@ Runtime and task level metrics for Tokio applications. categories = ["asynchronous", "network-programming"] keywords = ["async", "futures", "metrics", "debugging"] +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)'] } + [features] default = ["rt"] rt = ["tokio"] @@ -22,7 +25,7 @@ rt = ["tokio"] tokio-stream = "0.1.11" futures-util = "0.3.19" pin-project-lite = "0.2.7" -tokio = { version = "1.31.0", features = ["rt", "time", "net"], optional = true } +tokio = { version = "1.41.0", features = ["rt", "time", "net"], optional = true } [dev-dependencies] axum = "0.6" @@ -31,7 +34,7 @@ futures = "0.3.21" num_cpus = "1.13.1" serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" -tokio = { version = "1.26.0", features = ["full", "rt", "time", "macros", "test-util"] } +tokio = { version = "1.41.0", features = ["full", "rt", "time", "macros", "test-util"] } [[example]] name = "runtime" diff --git a/src/runtime.rs b/src/runtime.rs index 677feb6..d71fec1 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -244,37 +244,35 @@ pub struct RuntimeMetrics { /// times. /// /// This metric must be explicitly enabled when creating the runtime with - /// [`enable_metrics_poll_count_histogram`][tokio::runtime::Builder::enable_metrics_poll_count_histogram]. + /// [`enable_metrics_poll_time_histogram`][tokio::runtime::Builder::enable_metrics_poll_time_histogram]. /// Bucket sizes are fixed and configured at the runtime level. See /// configuration options on - /// [`runtime::Builder`][tokio::runtime::Builder::enable_metrics_poll_count_histogram]. + /// [`runtime::Builder`][tokio::runtime::Builder::enable_metrics_poll_time_histogram]. /// /// ##### Examples /// ``` - /// use tokio::runtime::HistogramScale; + /// use tokio::runtime::HistogramConfiguration; /// use std::time::Duration; /// - /// fn main() { - /// let rt = tokio::runtime::Builder::new_multi_thread() - /// .enable_metrics_poll_count_histogram() - /// .metrics_poll_count_histogram_scale(HistogramScale::Linear) - /// .metrics_poll_count_histogram_resolution(Duration::from_micros(50)) - /// .metrics_poll_count_histogram_buckets(12) - /// .build() - /// .unwrap(); + /// let config = HistogramConfiguration::linear(Duration::from_micros(50), 12); /// - /// rt.block_on(async { - /// let handle = tokio::runtime::Handle::current(); - /// let monitor = tokio_metrics::RuntimeMonitor::new(&handle); - /// let mut intervals = monitor.intervals(); - /// let mut next_interval = || intervals.next().unwrap(); + /// let rt = tokio::runtime::Builder::new_multi_thread() + /// .enable_metrics_poll_time_histogram() + /// .metrics_poll_time_histogram_configuration(config) + /// .build() + /// .unwrap(); /// - /// let interval = next_interval(); - /// println!("poll count histogram {:?}", interval.poll_count_histogram); - /// }); - /// } + /// rt.block_on(async { + /// let handle = tokio::runtime::Handle::current(); + /// let monitor = tokio_metrics::RuntimeMonitor::new(&handle); + /// let mut intervals = monitor.intervals(); + /// let mut next_interval = || intervals.next().unwrap(); + /// + /// let interval = next_interval(); + /// println!("poll count histogram {:?}", interval.poll_time_histogram); + /// }); /// ``` - pub poll_count_histogram: Vec, + pub poll_time_histogram: Vec, /// The number of times worker threads unparked but performed no work before parking again. /// @@ -527,7 +525,7 @@ pub struct RuntimeMetrics { /// /// The remote schedule count increases by one each time a task is woken from **outside** of /// the runtime. This usually means that a task is spawned or notified from a non-runtime - /// thread and must be queued using the Runtime's injection queue, which tends to be slower. + /// thread and must be queued using the Runtime's global queue, which tends to be slower. /// /// ##### Definition /// This metric is derived from [`tokio::runtime::RuntimeMetrics::remote_schedule_count`]. @@ -683,7 +681,7 @@ pub struct RuntimeMetrics { /// /// The worker steal count increases by one each time the worker attempts to schedule a task /// locally, but its local queue is full. When this happens, half of the - /// local queue is moved to the injection queue. + /// local queue is moved to the global queue. /// /// This metric only applies to the **multi-threaded** scheduler. /// @@ -957,15 +955,15 @@ pub struct RuntimeMetrics { /// - [`RuntimeMetrics::max_busy_duration`] pub min_busy_duration: Duration, - /// The number of tasks currently scheduled in the runtime's injection queue. + /// The number of tasks currently scheduled in the runtime's global queue. /// /// Tasks that are spawned or notified from a non-runtime thread are scheduled using the - /// runtime's injection queue. This metric returns the **current** number of tasks pending in - /// the injection queue. As such, the returned value may increase or decrease as new tasks are + /// runtime's global queue. This metric returns the **current** number of tasks pending in + /// the global queue. As such, the returned value may increase or decrease as new tasks are /// scheduled and processed. /// /// ##### Definition - /// This metric is derived from [`tokio::runtime::RuntimeMetrics::injection_queue_depth`]. + /// This metric is derived from [`tokio::runtime::RuntimeMetrics::global_queue_depth`]. /// /// ##### Example /// ``` @@ -1003,7 +1001,7 @@ pub struct RuntimeMetrics { /// assert_eq!(interval.num_remote_schedules, 2); /// # } /// ``` - pub injection_queue_depth: usize, + pub global_queue_depth: usize, /// The total number of tasks currently scheduled in workers' local queues. /// @@ -1143,7 +1141,7 @@ struct Worker { total_overflow_count: u64, total_polls_count: u64, total_busy_duration: Duration, - poll_count_histogram: Vec, + poll_time_histogram: Vec, } /// Iterator returned by [`RuntimeMonitor::intervals`]. @@ -1172,7 +1170,7 @@ impl RuntimeIntervals { let mut metrics = RuntimeMetrics { workers_count: self.runtime.num_workers(), elapsed: now - self.started_at, - injection_queue_depth: self.runtime.injection_queue_depth(), + global_queue_depth: self.runtime.global_queue_depth(), num_remote_schedules: num_remote_schedules - self.num_remote_schedules, min_park_count: u64::MAX, min_noop_count: u64::MAX, @@ -1183,7 +1181,7 @@ impl RuntimeIntervals { min_busy_duration: Duration::from_secs(1000000000), min_local_queue_depth: usize::MAX, mean_poll_duration_worker_min: Duration::MAX, - poll_count_histogram: vec![0; self.runtime.poll_count_histogram_num_buckets()], + poll_time_histogram: vec![0; self.runtime.poll_time_histogram_num_buckets()], budget_forced_yield_count: budget_forced_yields - self.budget_forced_yield_count, io_driver_ready_count: io_driver_ready_events - self.io_driver_ready_count, ..Default::default() @@ -1292,8 +1290,8 @@ impl RuntimeMonitor { impl Worker { fn new(worker: usize, rt: &runtime::RuntimeMetrics) -> Worker { - let poll_count_histogram = if rt.poll_count_histogram_enabled() { - vec![0; rt.poll_count_histogram_num_buckets()] + let poll_time_histogram = if rt.poll_time_histogram_enabled() { + vec![0; rt.poll_time_histogram_num_buckets()] } else { vec![] }; @@ -1308,7 +1306,7 @@ impl Worker { total_overflow_count: rt.worker_overflow_count(worker), total_polls_count: rt.worker_poll_count(worker), total_busy_duration: rt.worker_total_busy_duration(worker), - poll_count_histogram, + poll_time_histogram, } } @@ -1411,10 +1409,10 @@ impl Worker { // Update the histogram counts if there were polls since last count if worker_polls_count > 0 { - for (bucket, cell) in metrics.poll_count_histogram.iter_mut().enumerate() { - let new = rt.poll_count_histogram_bucket_count(self.worker, bucket); - let delta = new - self.poll_count_histogram[bucket]; - self.poll_count_histogram[bucket] = new; + for (bucket, cell) in metrics.poll_time_histogram.iter_mut().enumerate() { + let new = rt.poll_time_histogram_bucket_count(self.worker, bucket); + let delta = new - self.poll_time_histogram[bucket]; + self.poll_time_histogram[bucket] = new; *cell += delta; } diff --git a/src/task.rs b/src/task.rs index fd9726e..6125d5a 100644 --- a/src/task.rs +++ b/src/task.rs @@ -237,13 +237,13 @@ use std::time::{Duration, Instant}; /// The culprit is likely some combination of: /// - **Your tasks are accidentally blocking.** Common culprits include: /// 1. Using the Rust standard library's [filesystem](https://doc.rust-lang.org/std/fs/) or -/// [networking](https://doc.rust-lang.org/std/net/) APIs. +/// [networking](https://doc.rust-lang.org/std/net/) APIs. /// These APIs are synchronous; use tokio's [filesystem](https://docs.rs/tokio/latest/tokio/fs/) /// and [networking](https://docs.rs/tokio/latest/tokio/net/) APIs, instead. /// 3. Calling [`block_on`](https://docs.rs/tokio/latest/tokio/runtime/struct.Handle.html#method.block_on). /// 4. Invoking `println!` or other synchronous logging routines. -/// Invocations of `println!` involve acquiring an exclusive lock on stdout, followed by a -/// synchronous write to stdout. +/// Invocations of `println!` involve acquiring an exclusive lock on stdout, followed by a +/// synchronous write to stdout. /// 2. **Your tasks are computationally expensive.** Common culprits include: /// 1. TLS/cryptographic routines /// 2. doing a lot of processing on bytes @@ -253,7 +253,7 @@ use std::time::{Duration, Instant}; /// You observed that [your tasks are spending more time waiting to be polled](#are-my-tasks-spending-more-time-waiting-to-be-polled) /// suggesting some combination of: /// - Your application is inflating the time elapsed between instrumentation and first poll. -/// - Your tasks are being scheduled into tokio's injection queue. +/// - Your tasks are being scheduled into tokio's global queue. /// - Other tasks are spending too long without yielding, thus backing up tokio's queues. /// /// Start by asking: [*Is time-to-first-poll unusually high?*](#is-time-to-first-poll-unusually-high) @@ -307,9 +307,9 @@ use std::time::{Duration, Instant}; /// ``` /// /// Otherwise, [`mean_first_poll_delay`][TaskMetrics::mean_first_poll_delay] might be unusually high -/// because [*your application is spawning key tasks into tokio's injection queue...*](#is-my-application-spawning-more-tasks-into-tokio’s-injection-queue) +/// because [*your application is spawning key tasks into tokio's global queue...*](#is-my-application-spawning-more-tasks-into-tokio’s-global-queue) /// -/// ##### Is my application spawning more tasks into tokio's injection queue? +/// ##### Is my application spawning more tasks into tokio's global queue? /// Tasks awoken from threads *not* managed by the tokio runtime are scheduled with a slower, /// global "injection" queue. ///