mirror of
https://github.com/Syfaro/bkapi.git
synced 2024-11-05 14:44:29 +00:00
Record time to add to tree.
This commit is contained in:
parent
f144ba43b5
commit
196ea5a2e2
@ -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 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_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)]
|
#[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
|
// Avoid checking if each value is unique if we were told that the
|
||||||
// database query only returns unique values.
|
// database query only returns unique values.
|
||||||
|
let timer = TREE_ADD_DURATION.start_timer();
|
||||||
if config.database_is_unique || tree.find_exact(&node).is_none() {
|
if config.database_is_unique || tree.find_exact(&node).is_none() {
|
||||||
tree.add(node);
|
tree.add(node);
|
||||||
}
|
}
|
||||||
|
timer.stop_and_record();
|
||||||
|
|
||||||
count += 1;
|
count += 1;
|
||||||
if count % 250_000 == 0 {
|
if count % 250_000 == 0 {
|
||||||
@ -308,6 +311,8 @@ async fn listen_for_payloads(
|
|||||||
|
|
||||||
let node: Node = payload.hash.into();
|
let node: Node = payload.hash.into();
|
||||||
|
|
||||||
|
let _timer = TREE_ADD_DURATION.start_timer();
|
||||||
|
|
||||||
let tree = tree.upgradable_read().await;
|
let tree = tree.upgradable_read().await;
|
||||||
if tree.find_exact(&node).is_some() {
|
if tree.find_exact(&node).is_some() {
|
||||||
tracing::trace!("hash already existed in tree");
|
tracing::trace!("hash already existed in tree");
|
||||||
|
Loading…
Reference in New Issue
Block a user