diff --git a/src/main.rs b/src/main.rs index 2d2b84e..0f52225 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ lazy_static::lazy_static! { static ref HTTP_REQUEST_DURATION: prometheus::HistogramVec = prometheus::register_histogram_vec!("http_request_duration_seconds", "Duration of HTTP requests", &["http_route", "http_method", "http_status_code"]).unwrap(); static ref TREE_DURATION: prometheus::HistogramVec = prometheus::register_histogram_vec!("bkapi_tree_duration_seconds", "Duration of tree search time", &["distance"]).unwrap(); + static ref TREE_ADD_DURATION: prometheus::Histogram = prometheus::register_histogram!("bkapi_tree_add_duration_seconds", "Duration to add new item to tree").unwrap(); } #[derive(thiserror::Error, Debug)] @@ -250,9 +251,11 @@ async fn create_tree( // Avoid checking if each value is unique if we were told that the // database query only returns unique values. + let timer = TREE_ADD_DURATION.start_timer(); if config.database_is_unique || tree.find_exact(&node).is_none() { tree.add(node); } + timer.stop_and_record(); count += 1; if count % 250_000 == 0 { @@ -308,6 +311,8 @@ async fn listen_for_payloads( let node: Node = payload.hash.into(); + let _timer = TREE_ADD_DURATION.start_timer(); + let tree = tree.upgradable_read().await; if tree.find_exact(&node).is_some() { tracing::trace!("hash already existed in tree");