Adding metrics to save block info

This commit is contained in:
godmodegalactus 2024-01-29 15:33:05 +01:00
parent a9aebba6b5
commit 797f638f44
No known key found for this signature in database
GPG Key ID: 22DA4A30887FDA3C
2 changed files with 17 additions and 10 deletions

View File

@ -359,9 +359,10 @@ async fn main() -> anyhow::Result<()> {
.collect_vec(); .collect_vec();
let mut block_senders = vec![]; let mut block_senders = vec![];
for i in 1..=4 for i in 1..=4 {
{ let s = postgres::Postgres::new_with_workmem(i)
let s = postgres::Postgres::new_with_workmem(i).await.spawn_block_saver(); .await
.spawn_block_saver();
block_senders.push(s); block_senders.push(s);
} }

View File

@ -58,16 +58,19 @@ lazy_static::lazy_static! {
static ref ACCOUNT_SAVE_TIME: IntGauge = static ref ACCOUNT_SAVE_TIME: IntGauge =
register_int_gauge!(opts!("banking_stage_sidecar_account_save_time", "Account save time")).unwrap(); register_int_gauge!(opts!("banking_stage_sidecar_account_save_time", "Account save time")).unwrap();
static ref BLOCK_INFO_SAVE_TIME: IntGauge =
register_int_gauge!(opts!("banking_stage_sidecar_block_info_save_time", "Block info save time")).unwrap();
} }
#[derive(Clone)] #[derive(Clone)]
pub struct TempTableTracker { pub struct TempTableTracker {
nb : usize, nb: usize,
count: Arc<AtomicU64>, count: Arc<AtomicU64>,
} }
impl TempTableTracker { impl TempTableTracker {
pub fn new(nb:usize) -> Self { pub fn new(nb: usize) -> Self {
Self { Self {
nb, nb,
count: Arc::new(AtomicU64::new(1)), count: Arc::new(AtomicU64::new(1)),
@ -87,11 +90,11 @@ impl TempTableTracker {
#[derive(Clone)] #[derive(Clone)]
pub struct PostgresSession { pub struct PostgresSession {
client: Arc<Client>, client: Arc<Client>,
temp_table_tracker : TempTableTracker, temp_table_tracker: TempTableTracker,
} }
impl PostgresSession { impl PostgresSession {
pub async fn new(nb : usize) -> anyhow::Result<Self> { pub async fn new(nb: usize) -> anyhow::Result<Self> {
let pg_config = std::env::var("PG_CONFIG").context("env PG_CONFIG not found")?; let pg_config = std::env::var("PG_CONFIG").context("env PG_CONFIG not found")?;
let pg_config = pg_config.parse::<tokio_postgres::Config>()?; let pg_config = pg_config.parse::<tokio_postgres::Config>()?;
@ -125,7 +128,7 @@ impl PostgresSession {
Ok(Self { Ok(Self {
client: Arc::new(client), client: Arc::new(client),
temp_table_tracker: TempTableTracker::new(nb) temp_table_tracker: TempTableTracker::new(nb),
}) })
} }
@ -883,6 +886,7 @@ impl PostgresSession {
self.create_accounts_for_transaction(accounts).await?; self.create_accounts_for_transaction(accounts).await?;
ACCOUNT_SAVE_TIME.set(ins_acc.elapsed().as_millis() as i64); ACCOUNT_SAVE_TIME.set(ins_acc.elapsed().as_millis() as i64);
let instant_acc_tx: Instant = Instant::now();
let txs_accounts = block_info let txs_accounts = block_info
.transactions .transactions
.iter() .iter()
@ -900,8 +904,6 @@ impl PostgresSession {
.collect(), .collect(),
}) })
.collect_vec(); .collect_vec();
let instant_acc_tx: Instant = Instant::now();
if let Err(e) = self.insert_accounts_for_transaction(txs_accounts).await { if let Err(e) = self.insert_accounts_for_transaction(txs_accounts).await {
error!("Error inserting accounts for transactions : {e:?}"); error!("Error inserting accounts for transactions : {e:?}");
} }
@ -917,7 +919,11 @@ impl PostgresSession {
let ins = Instant::now(); let ins = Instant::now();
self.save_account_usage_in_block(&block_info).await?; self.save_account_usage_in_block(&block_info).await?;
TIME_TO_SAVE_BLOCK_ACCOUNTS.set(ins.elapsed().as_millis() as i64); TIME_TO_SAVE_BLOCK_ACCOUNTS.set(ins.elapsed().as_millis() as i64);
let inst_block_info = Instant::now();
self.save_block_info(&block_info).await?; self.save_block_info(&block_info).await?;
BLOCK_INFO_SAVE_TIME.set(inst_block_info.elapsed().as_millis() as i64);
TIME_TO_SAVE_BLOCK.set(instant.elapsed().as_millis() as i64); TIME_TO_SAVE_BLOCK.set(instant.elapsed().as_millis() as i64);
Ok(()) Ok(())
} }