Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
[Metrics] Matched order classification counts (#1243)
Browse files Browse the repository at this point in the history
* add new batch metrics for matched order classification counts

* remove all metrics involved cancelled orders

Co-authored-by: Nicholas Rodrigues Lordello <nlordell@gmail.com>
  • Loading branch information
bh2smith and nlordell authored Oct 14, 2021
1 parent eb688f7 commit e021831
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
38 changes: 30 additions & 8 deletions solver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use shared::{
token_list::TokenList,
Web3,
};
use std::str::FromStr;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
Expand Down Expand Up @@ -288,23 +289,43 @@ impl Driver {
}
}

// Record metric with the amount of orders that were matched but not settled in this runloop (effectively queued for the next one)
// Should help us to identify how much we can save by parallelizing execution.
fn report_matched_but_unsettled_orders(
/// Record metrics on the matched orders from a single batch. Specifically we report on
/// the number of orders that were;
/// - matched but not settled in this runloop (effectively queued for the next one)
/// - matched but coming from known liquidity providers.
/// Should help us to identify how much we can save by parallelizing execution.
fn report_matched_orders(
&self,
submitted: &Settlement,
all: impl Iterator<Item = RatedSettlement>,
orders: Vec<LimitOrder>,
) {
let submitted: HashSet<_> = submitted
.trades()
.iter()
.map(|trade| trade.order.order_meta_data.uid)
.collect();
let all_matched: HashSet<_> = all
let all_matched_orders: HashSet<_> = all
.flat_map(|solution| solution.settlement.trades().to_vec())
.map(|trade| trade.order.order_meta_data.uid)
.map(|trade| trade.order)
.collect();
let all_matched_ids: HashSet<_> = all_matched_orders
.iter()
.map(|order| order.order_meta_data.uid)
.collect();
let matched_but_not_settled = all_matched_ids.difference(&submitted).copied().collect();
let liquidity_order_ids: HashSet<_> = orders
.into_iter()
.filter_map(|order| match order.is_liquidity_order {
true => OrderUid::from_str(&order.id).ok(),
false => None,
})
.collect();
let matched_but_not_settled: HashSet<_> = all_matched.difference(&submitted).collect();
let matched_but_unsettled_liquidity_ids: HashSet<_> = liquidity_order_ids
.intersection(&matched_but_not_settled)
.collect();
self.metrics
.orders_matched_but_liquidity(matched_but_unsettled_liquidity_ids.len());
self.metrics
.orders_matched_but_not_settled(matched_but_not_settled.len())
}
Expand Down Expand Up @@ -403,7 +424,7 @@ impl Driver {

let auction = Auction {
id: self.next_auction_id(),
orders,
orders: orders.clone(),
liquidity,
gas_price: gas_price.effective_gas_price(),
deadline: Instant::now() + self.solver_time_limit,
Expand Down Expand Up @@ -493,9 +514,10 @@ impl Driver {
.collect::<HashSet<OrderUid>>();
}

self.report_matched_but_unsettled_orders(
self.report_matched_orders(
&settlement.settlement,
rated_settlements.into_iter().map(|(_, solution)| solution),
orders,
);
}

Expand Down
14 changes: 14 additions & 0 deletions solver/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub trait SolverMetrics {
fn settlement_simulation_failed_on_latest(&self, solver: &'static str);
fn settlement_simulation_failed(&self, solver: &'static str);
fn settlement_submitted(&self, successful: bool, solver: &'static str);
fn orders_matched_but_liquidity(&self, count: usize);
fn orders_matched_but_not_settled(&self, count: usize);
fn runloop_completed(&self);
}
Expand All @@ -41,6 +42,7 @@ pub struct Metrics {
liquidity: IntGaugeVec,
settlement_simulations: IntCounterVec,
settlement_submissions: IntCounterVec,
matched_but_liquidity: IntCounter,
matched_but_unsettled_orders: IntCounter,
transport_requests: HistogramVec,
pool_cache_hits: IntCounter,
Expand Down Expand Up @@ -94,6 +96,12 @@ impl Metrics {
)?;
registry.register(Box::new(settlement_submissions.clone()))?;

let matched_but_liquidity = IntCounter::new(
"orders_matched_liquidity",
"Counter for the number of orders for which at least one solver computed an execution which was from a known liquidity provider",
)?;
registry.register(Box::new(matched_but_liquidity.clone()))?;

let matched_but_unsettled_orders = IntCounter::new(
"orders_matched_not_settled",
"Counter for the number of orders for which at least one solver computed an execution which was not chosen in this run-loop",
Expand Down Expand Up @@ -126,6 +134,7 @@ impl Metrics {
liquidity,
settlement_simulations,
settlement_submissions,
matched_but_liquidity,
matched_but_unsettled_orders,
transport_requests,
pool_cache_hits,
Expand Down Expand Up @@ -202,6 +211,10 @@ impl SolverMetrics for Metrics {
.inc()
}

fn orders_matched_but_liquidity(&self, count: usize) {
self.matched_but_liquidity.inc_by(count as u64);
}

fn orders_matched_but_not_settled(&self, count: usize) {
self.matched_but_unsettled_orders.inc_by(count as u64);
}
Expand Down Expand Up @@ -262,6 +275,7 @@ impl SolverMetrics for NoopMetrics {
fn settlement_simulation_failed_on_latest(&self, _: &'static str) {}
fn settlement_simulation_failed(&self, _: &'static str) {}
fn settlement_submitted(&self, _: bool, _: &'static str) {}
fn orders_matched_but_liquidity(&self, _: usize) {}
fn orders_matched_but_not_settled(&self, _: usize) {}
fn runloop_completed(&self) {}
}
Expand Down

0 comments on commit e021831

Please sign in to comment.