Skip to content

Commit fe2996e

Browse files
committed
chore: avoid deprecated items, fix warnings
1 parent 47fbe3b commit fe2996e

File tree

3 files changed

+44
-43
lines changed

3 files changed

+44
-43
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Runtime and task level metrics for Tokio applications.
1414
categories = ["asynchronous", "network-programming"]
1515
keywords = ["async", "futures", "metrics", "debugging"]
1616

17+
[lints.rust]
18+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)'] }
19+
1720
[features]
1821
default = ["rt"]
1922
rt = ["tokio"]

src/runtime.rs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -244,37 +244,35 @@ pub struct RuntimeMetrics {
244244
/// times.
245245
///
246246
/// This metric must be explicitly enabled when creating the runtime with
247-
/// [`enable_metrics_poll_count_histogram`][tokio::runtime::Builder::enable_metrics_poll_count_histogram].
247+
/// [`enable_metrics_poll_time_histogram`][tokio::runtime::Builder::enable_metrics_poll_time_histogram].
248248
/// Bucket sizes are fixed and configured at the runtime level. See
249249
/// configuration options on
250-
/// [`runtime::Builder`][tokio::runtime::Builder::enable_metrics_poll_count_histogram].
250+
/// [`runtime::Builder`][tokio::runtime::Builder::enable_metrics_poll_time_histogram].
251251
///
252252
/// ##### Examples
253253
/// ```
254254
/// use tokio::runtime::HistogramScale;
255255
/// use std::time::Duration;
256256
///
257-
/// fn main() {
258-
/// let rt = tokio::runtime::Builder::new_multi_thread()
259-
/// .enable_metrics_poll_count_histogram()
260-
/// .metrics_poll_count_histogram_scale(HistogramScale::Linear)
261-
/// .metrics_poll_count_histogram_resolution(Duration::from_micros(50))
262-
/// .metrics_poll_count_histogram_buckets(12)
263-
/// .build()
264-
/// .unwrap();
257+
/// let rt = tokio::runtime::Builder::new_multi_thread()
258+
/// .enable_metrics_poll_time_histogram()
259+
/// .metrics_poll_time_histogram_scale(HistogramScale::Linear)
260+
/// .metrics_poll_time_histogram_resolution(Duration::from_micros(50))
261+
/// .metrics_poll_time_histogram_buckets(12)
262+
/// .build()
263+
/// .unwrap();
265264
///
266-
/// rt.block_on(async {
267-
/// let handle = tokio::runtime::Handle::current();
268-
/// let monitor = tokio_metrics::RuntimeMonitor::new(&handle);
269-
/// let mut intervals = monitor.intervals();
270-
/// let mut next_interval = || intervals.next().unwrap();
265+
/// rt.block_on(async {
266+
/// let handle = tokio::runtime::Handle::current();
267+
/// let monitor = tokio_metrics::RuntimeMonitor::new(&handle);
268+
/// let mut intervals = monitor.intervals();
269+
/// let mut next_interval = || intervals.next().unwrap();
271270
///
272-
/// let interval = next_interval();
273-
/// println!("poll count histogram {:?}", interval.poll_count_histogram);
274-
/// });
275-
/// }
271+
/// let interval = next_interval();
272+
/// println!("poll count histogram {:?}", interval.poll_time_histogram);
273+
/// });
276274
/// ```
277-
pub poll_count_histogram: Vec<u64>,
275+
pub poll_time_histogram: Vec<u64>,
278276

279277
/// The number of times worker threads unparked but performed no work before parking again.
280278
///
@@ -527,7 +525,7 @@ pub struct RuntimeMetrics {
527525
///
528526
/// The remote schedule count increases by one each time a task is woken from **outside** of
529527
/// the runtime. This usually means that a task is spawned or notified from a non-runtime
530-
/// thread and must be queued using the Runtime's injection queue, which tends to be slower.
528+
/// thread and must be queued using the Runtime's global queue, which tends to be slower.
531529
///
532530
/// ##### Definition
533531
/// This metric is derived from [`tokio::runtime::RuntimeMetrics::remote_schedule_count`].
@@ -683,7 +681,7 @@ pub struct RuntimeMetrics {
683681
///
684682
/// The worker steal count increases by one each time the worker attempts to schedule a task
685683
/// locally, but its local queue is full. When this happens, half of the
686-
/// local queue is moved to the injection queue.
684+
/// local queue is moved to the global queue.
687685
///
688686
/// This metric only applies to the **multi-threaded** scheduler.
689687
///
@@ -957,15 +955,15 @@ pub struct RuntimeMetrics {
957955
/// - [`RuntimeMetrics::max_busy_duration`]
958956
pub min_busy_duration: Duration,
959957

960-
/// The number of tasks currently scheduled in the runtime's injection queue.
958+
/// The number of tasks currently scheduled in the runtime's global queue.
961959
///
962960
/// Tasks that are spawned or notified from a non-runtime thread are scheduled using the
963-
/// runtime's injection queue. This metric returns the **current** number of tasks pending in
964-
/// the injection queue. As such, the returned value may increase or decrease as new tasks are
961+
/// runtime's global queue. This metric returns the **current** number of tasks pending in
962+
/// the global queue. As such, the returned value may increase or decrease as new tasks are
965963
/// scheduled and processed.
966964
///
967965
/// ##### Definition
968-
/// This metric is derived from [`tokio::runtime::RuntimeMetrics::injection_queue_depth`].
966+
/// This metric is derived from [`tokio::runtime::RuntimeMetrics::global_queue_depth`].
969967
///
970968
/// ##### Example
971969
/// ```
@@ -1003,7 +1001,7 @@ pub struct RuntimeMetrics {
10031001
/// assert_eq!(interval.num_remote_schedules, 2);
10041002
/// # }
10051003
/// ```
1006-
pub injection_queue_depth: usize,
1004+
pub global_queue_depth: usize,
10071005

10081006
/// The total number of tasks currently scheduled in workers' local queues.
10091007
///
@@ -1143,7 +1141,7 @@ struct Worker {
11431141
total_overflow_count: u64,
11441142
total_polls_count: u64,
11451143
total_busy_duration: Duration,
1146-
poll_count_histogram: Vec<u64>,
1144+
poll_time_histogram: Vec<u64>,
11471145
}
11481146

11491147
/// Iterator returned by [`RuntimeMonitor::intervals`].
@@ -1172,7 +1170,7 @@ impl RuntimeIntervals {
11721170
let mut metrics = RuntimeMetrics {
11731171
workers_count: self.runtime.num_workers(),
11741172
elapsed: now - self.started_at,
1175-
injection_queue_depth: self.runtime.injection_queue_depth(),
1173+
global_queue_depth: self.runtime.global_queue_depth(),
11761174
num_remote_schedules: num_remote_schedules - self.num_remote_schedules,
11771175
min_park_count: u64::MAX,
11781176
min_noop_count: u64::MAX,
@@ -1183,7 +1181,7 @@ impl RuntimeIntervals {
11831181
min_busy_duration: Duration::from_secs(1000000000),
11841182
min_local_queue_depth: usize::MAX,
11851183
mean_poll_duration_worker_min: Duration::MAX,
1186-
poll_count_histogram: vec![0; self.runtime.poll_count_histogram_num_buckets()],
1184+
poll_time_histogram: vec![0; self.runtime.poll_time_histogram_num_buckets()],
11871185
budget_forced_yield_count: budget_forced_yields - self.budget_forced_yield_count,
11881186
io_driver_ready_count: io_driver_ready_events - self.io_driver_ready_count,
11891187
..Default::default()
@@ -1292,8 +1290,8 @@ impl RuntimeMonitor {
12921290

12931291
impl Worker {
12941292
fn new(worker: usize, rt: &runtime::RuntimeMetrics) -> Worker {
1295-
let poll_count_histogram = if rt.poll_count_histogram_enabled() {
1296-
vec![0; rt.poll_count_histogram_num_buckets()]
1293+
let poll_time_histogram = if rt.poll_time_histogram_enabled() {
1294+
vec![0; rt.poll_time_histogram_num_buckets()]
12971295
} else {
12981296
vec![]
12991297
};
@@ -1308,7 +1306,7 @@ impl Worker {
13081306
total_overflow_count: rt.worker_overflow_count(worker),
13091307
total_polls_count: rt.worker_poll_count(worker),
13101308
total_busy_duration: rt.worker_total_busy_duration(worker),
1311-
poll_count_histogram,
1309+
poll_time_histogram,
13121310
}
13131311
}
13141312

@@ -1411,10 +1409,10 @@ impl Worker {
14111409

14121410
// Update the histogram counts if there were polls since last count
14131411
if worker_polls_count > 0 {
1414-
for (bucket, cell) in metrics.poll_count_histogram.iter_mut().enumerate() {
1415-
let new = rt.poll_count_histogram_bucket_count(self.worker, bucket);
1416-
let delta = new - self.poll_count_histogram[bucket];
1417-
self.poll_count_histogram[bucket] = new;
1412+
for (bucket, cell) in metrics.poll_time_histogram.iter_mut().enumerate() {
1413+
let new = rt.poll_time_histogram_bucket_count(self.worker, bucket);
1414+
let delta = new - self.poll_time_histogram[bucket];
1415+
self.poll_time_histogram[bucket] = new;
14181416

14191417
*cell += delta;
14201418
}

src/task.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ use std::time::{Duration, Instant};
237237
/// The culprit is likely some combination of:
238238
/// - **Your tasks are accidentally blocking.** Common culprits include:
239239
/// 1. Using the Rust standard library's [filesystem](https://doc.rust-lang.org/std/fs/) or
240-
/// [networking](https://doc.rust-lang.org/std/net/) APIs.
240+
/// [networking](https://doc.rust-lang.org/std/net/) APIs.
241241
/// These APIs are synchronous; use tokio's [filesystem](https://docs.rs/tokio/latest/tokio/fs/)
242242
/// and [networking](https://docs.rs/tokio/latest/tokio/net/) APIs, instead.
243243
/// 3. Calling [`block_on`](https://docs.rs/tokio/latest/tokio/runtime/struct.Handle.html#method.block_on).
244244
/// 4. Invoking `println!` or other synchronous logging routines.
245-
/// Invocations of `println!` involve acquiring an exclusive lock on stdout, followed by a
246-
/// synchronous write to stdout.
245+
/// Invocations of `println!` involve acquiring an exclusive lock on stdout, followed by a
246+
/// synchronous write to stdout.
247247
/// 2. **Your tasks are computationally expensive.** Common culprits include:
248248
/// 1. TLS/cryptographic routines
249249
/// 2. doing a lot of processing on bytes
@@ -253,7 +253,7 @@ use std::time::{Duration, Instant};
253253
/// You observed that [your tasks are spending more time waiting to be polled](#are-my-tasks-spending-more-time-waiting-to-be-polled)
254254
/// suggesting some combination of:
255255
/// - Your application is inflating the time elapsed between instrumentation and first poll.
256-
/// - Your tasks are being scheduled into tokio's injection queue.
256+
/// - Your tasks are being scheduled into tokio's global queue.
257257
/// - Other tasks are spending too long without yielding, thus backing up tokio's queues.
258258
///
259259
/// 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};
307307
/// ```
308308
///
309309
/// Otherwise, [`mean_first_poll_delay`][TaskMetrics::mean_first_poll_delay] might be unusually high
310-
/// because [*your application is spawning key tasks into tokio's injection queue...*](#is-my-application-spawning-more-tasks-into-tokio’s-injection-queue)
310+
/// because [*your application is spawning key tasks into tokio's global queue...*](#is-my-application-spawning-more-tasks-into-tokio’s-global-queue)
311311
///
312-
/// ##### Is my application spawning more tasks into tokio's injection queue?
312+
/// ##### Is my application spawning more tasks into tokio's global queue?
313313
/// Tasks awoken from threads *not* managed by the tokio runtime are scheduled with a slower,
314314
/// global "injection" queue.
315315
///

0 commit comments

Comments
 (0)