Skip to content

Commit

Permalink
Driver's auction preprocessing total metric fix (#3261)
Browse files Browse the repository at this point in the history
The auction preprocessing job runs only once for each auction, which is
achieved by using a mutex where other threads wait until the running job
is completed. The `total` metric was placed incorrectly outside the
lock, accumulating a lot of useless information where the preprocessing
is already done, and other threads just read the value. This PR fixes it
by only populating the metric when the async job is really executed.
  • Loading branch information
squadgazzz authored Jan 30, 2025
1 parent 25a9522 commit c060bb5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions crates/driver/src/domain/competition/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ impl AuctionProcessor {
/// unfillable orders. Fetches full app data for each order and returns an
/// auction with updated orders.
pub async fn prioritize(&self, auction: Auction, solver: &eth::H160) -> Auction {
let _timer = metrics::get()
.auction_preprocessing
.with_label_values(&["total"])
.start_timer();

Auction {
orders: self.prioritize_orders(&auction, solver).await,
..auction
Expand Down Expand Up @@ -199,9 +194,19 @@ impl AuctionProcessor {
// Use spawn_blocking() because a lot of CPU bound computations are happening
// and we don't want to block the runtime for too long.
let fut = tokio::task::spawn_blocking(move || {
let _timer = metrics::get()
.auction_preprocessing
.with_label_values(&["total"])
.start_timer();
let start = std::time::Instant::now();
orders.extend(rt.block_on(Self::cow_amm_orders(&eth, &tokens, &cow_amms, signature_validator.as_ref())));
sorting::sort_orders(&mut orders, &tokens, &solver, &order_comparators);
{
let _timer = metrics::get()
.auction_preprocessing
.with_label_values(&["cow_amm_orders_and_sorting"])
.start_timer();
orders.extend(rt.block_on(Self::cow_amm_orders(&eth, &tokens, &cow_amms, signature_validator.as_ref())));
sorting::sort_orders(&mut orders, &tokens, &solver, &order_comparators);
}
let (mut balances, mut app_data_by_hash) =
rt.block_on(async {
tokio::join!(
Expand Down

0 comments on commit c060bb5

Please sign in to comment.