Skip to content

Commit

Permalink
dex: 🪦 record duration of dead-end path search
Browse files Browse the repository at this point in the history
  • Loading branch information
cratelyn committed Jun 6, 2024
1 parent 2825fb4 commit 1e71cda
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/core/component/dex/src/component/router/path_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ pub trait PathSearch: StateRead + Clone + 'static {

// Initialize some metrics for calculating time spent on path searching
// vs route filling. We use vecs so we can count across iterations of the loop.
let path_start = std::time::Instant::now();
tracing::debug!(?src, ?dst, ?max_hops, "searching for path");
let path_start = std::time::Instant::now();
let record_duration = || {
use crate::component::metrics::DEX_PATH_SEARCH_DURATION;
let elapsed = path_start.elapsed();
metrics::histogram!(DEX_PATH_SEARCH_DURATION).record(elapsed);
};

// Work in a new stack of state changes, which we can completely discard
// at the end of routing
Expand All @@ -49,14 +54,14 @@ pub trait PathSearch: StateRead + Clone + 'static {

let entry = cache.lock().0.remove(&dst);
let Some(PathEntry { path, spill, .. }) = entry else {
record_duration();
return Ok((None, None));
};

let nodes = path.nodes;
let spill_price = spill.map(|p| p.price);
tracing::debug!(price = %path.price, spill_price = %spill_price.unwrap_or_else(|| 0u64.into()), ?src, ?nodes, "found path");
metrics::histogram!(crate::component::metrics::DEX_PATH_SEARCH_DURATION)
.record(path_start.elapsed());
record_duration();

match price_limit {
// Note: previously, this branch was a load-bearing termination condition, primarily
Expand Down

0 comments on commit 1e71cda

Please sign in to comment.