From 891408892ca09f994ad51b2a741f39305bd92ccb Mon Sep 17 00:00:00 2001 From: Cuong Nguyen Date: Tue, 31 Oct 2023 18:23:00 -0400 Subject: [PATCH] Add metric for commit lock wait time --- pageserver/src/metrics.rs | 11 +++++++++++ pageserver/src/pgdatadir_mapping.rs | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/pageserver/src/metrics.rs b/pageserver/src/metrics.rs index 4f18f4e622fc..8cdd6038ea8d 100644 --- a/pageserver/src/metrics.rs +++ b/pageserver/src/metrics.rs @@ -633,6 +633,8 @@ pub static LIVE_CONNECTIONS_COUNT: Lazy = Lazy::new(|| { .expect("failed to define a metric") }); +// Remotexact + pub static LAST_RECEIVED_LSN: Lazy = Lazy::new(|| { register_int_gauge_vec!( "pageserver_last_received_lsn", @@ -652,6 +654,15 @@ pub static LSN_RECEIVE_DELAY: Lazy = Lazy::new(|| { .expect("failed to define a metric") }); +pub static WAL_COMMIT_WRITER_LOCK_WAIT_TIME: Lazy = Lazy::new(|| { + register_histogram!( + "pageserver_wal_commit_writer_lock_wait_seconds", + "Time spent waiting for the commit writer lock", + CRITICAL_OP_BUCKETS.into(), + ) + .expect("failed to define a metric") +}); + // remote storage metrics /// NB: increment _after_ recording the current value into [`REMOTE_TIMELINE_CLIENT_CALLS_STARTED_HIST`]. diff --git a/pageserver/src/pgdatadir_mapping.rs b/pageserver/src/pgdatadir_mapping.rs index d43c919464f1..4b72ed5fba59 100644 --- a/pageserver/src/pgdatadir_mapping.rs +++ b/pageserver/src/pgdatadir_mapping.rs @@ -9,6 +9,7 @@ use super::tenant::{PageReconstructError, Timeline}; use crate::context::RequestContext; use crate::keyspace::{KeySpace, KeySpaceAccum}; +use crate::metrics::WAL_COMMIT_WRITER_LOCK_WAIT_TIME; use crate::repository::*; use crate::walrecord::NeonWalRecord; use anyhow::Context; @@ -1180,7 +1181,10 @@ impl<'a> DatadirModification<'a> { /// All the modifications in this atomic update are stamped by the specified LSN. /// pub async fn commit(&mut self) -> anyhow::Result<()> { + let timer = WAL_COMMIT_WRITER_LOCK_WAIT_TIME.start_timer(); let writer = self.tline.writer().await; + timer.stop_and_record(); + let lsn = self.lsn; let pending_nblocks = self.pending_nblocks; self.pending_nblocks = 0;