add program options for tokio histogram settings

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-12-19 07:01:15 +00:00 committed by strawberry
parent af3d6a2e37
commit 674acc8657
2 changed files with 19 additions and 11 deletions

View file

@ -38,6 +38,18 @@ pub(crate) struct Args {
/// Override the tokio worker_thread count. /// Override the tokio worker_thread count.
#[arg(long, hide(true), env = "TOKIO_WORKER_THREADS", default_value = available_parallelism().to_string())] #[arg(long, hide(true), env = "TOKIO_WORKER_THREADS", default_value = available_parallelism().to_string())]
pub(crate) worker_threads: usize, 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 /// Parse commandline arguments into structured data

View file

@ -35,25 +35,21 @@ pub(super) fn new(args: &Args) -> Result<tokio::runtime::Runtime> {
.on_task_terminate(task_terminate); .on_task_terminate(task_terminate);
#[cfg(tokio_unstable)] #[cfg(tokio_unstable)]
enable_histogram(&mut builder); enable_histogram(&mut builder, args);
builder.build().map_err(Into::into) builder.build().map_err(Into::into)
} }
#[cfg(tokio_unstable)] #[cfg(tokio_unstable)]
fn enable_histogram(builder: &mut Builder) { fn enable_histogram(builder: &mut Builder, args: &Args) {
use tokio::runtime::{HistogramConfiguration, LogHistogram}; use tokio::runtime::HistogramConfiguration;
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");
let buckets = args.worker_histogram_buckets;
let interval = Duration::from_micros(args.worker_histogram_interval);
let linear = HistogramConfiguration::linear(interval, buckets);
builder builder
.enable_metrics_poll_time_histogram() .enable_metrics_poll_time_histogram()
.metrics_poll_time_histogram_configuration(HistogramConfiguration::log(config)); .metrics_poll_time_histogram_configuration(linear);
} }
#[tracing::instrument( #[tracing::instrument(