From c060bb58915ad1bafbdb27a89510e0488b88e6d6 Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 30 Jan 2025 16:52:29 +0000 Subject: [PATCH] Driver's auction preprocessing `total` metric fix (#3261) 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. --- .../driver/src/domain/competition/auction.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/driver/src/domain/competition/auction.rs b/crates/driver/src/domain/competition/auction.rs index f57ad741ca..ee8a97f930 100644 --- a/crates/driver/src/domain/competition/auction.rs +++ b/crates/driver/src/domain/competition/auction.rs @@ -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: ð::H160) -> Auction { - let _timer = metrics::get() - .auction_preprocessing - .with_label_values(&["total"]) - .start_timer(); - Auction { orders: self.prioritize_orders(&auction, solver).await, ..auction @@ -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(ð, &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(ð, &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!(