diff --git a/src/main/clap.rs b/src/main/clap.rs index 7e70bd80..28577356 100644 --- a/src/main/clap.rs +++ b/src/main/clap.rs @@ -38,6 +38,18 @@ pub(crate) struct Args { /// Override the tokio worker_thread count. #[arg(long, hide(true), env = "TOKIO_WORKER_THREADS", default_value = available_parallelism().to_string())] pub(crate) worker_threads: usize, + + /// Set the histogram bucket size, in microseconds (tokio_unstable). Default + /// is 25 microseconds. If the values of the histogram don't approach zero + /// with the exception of the last bucket, try increasing this value to e.g. + /// 50 or 100. Inversely, decrease to 10 etc if the histogram lacks + /// resolution. + #[arg(long, hide(true), env = "CONDUWUIT_RUNTIME_HISTOGRAM_INTERVAL", default_value = "25")] + pub(crate) worker_histogram_interval: u64, + + /// Set the histogram bucket count (tokio_unstable). Default is 20. + #[arg(long, hide(true), env = "CONDUWUIT_RUNTIME_HISTOGRAM_BUCKETS", default_value = "20")] + pub(crate) worker_histogram_buckets: usize, } /// Parse commandline arguments into structured data diff --git a/src/main/runtime.rs b/src/main/runtime.rs index ad0c3cde..6fc405a7 100644 --- a/src/main/runtime.rs +++ b/src/main/runtime.rs @@ -35,25 +35,21 @@ pub(super) fn new(args: &Args) -> Result { .on_task_terminate(task_terminate); #[cfg(tokio_unstable)] - enable_histogram(&mut builder); + enable_histogram(&mut builder, args); builder.build().map_err(Into::into) } #[cfg(tokio_unstable)] -fn enable_histogram(builder: &mut Builder) { - use tokio::runtime::{HistogramConfiguration, LogHistogram}; - - let config = LogHistogram::builder() - .min_value(Duration::from_micros(10)) - .max_value(Duration::from_millis(1)) - .max_error(0.5) - .max_buckets(32) - .expect("erroneous histogram configuration"); +fn enable_histogram(builder: &mut Builder, args: &Args) { + use tokio::runtime::HistogramConfiguration; + let buckets = args.worker_histogram_buckets; + let interval = Duration::from_micros(args.worker_histogram_interval); + let linear = HistogramConfiguration::linear(interval, buckets); builder .enable_metrics_poll_time_histogram() - .metrics_poll_time_histogram_configuration(HistogramConfiguration::log(config)); + .metrics_poll_time_histogram_configuration(linear); } #[tracing::instrument(