From abef267bab1d63ae096fb4c534a6b7b2774e537e Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Fri, 7 Feb 2025 02:42:37 +0100 Subject: [PATCH] avoid one arc counter incing --- pageserver/src/metrics.rs | 54 +--------------------------------- pageserver/src/page_service.rs | 7 ----- 2 files changed, 1 insertion(+), 60 deletions(-) diff --git a/pageserver/src/metrics.rs b/pageserver/src/metrics.rs index 96ee157856..2384a1da09 100644 --- a/pageserver/src/metrics.rs +++ b/pageserver/src/metrics.rs @@ -1238,12 +1238,6 @@ pub(crate) struct SmgrOpTimerInner { op: SmgrQueryType, } -pub(crate) struct SmgrOpFlushInProgress { - base: Instant, - global_micros: IntCounter, - per_timeline_micros: IntCounter, -} - impl SmgrOpTimer { pub(crate) fn deduct_throttle(&mut self, throttle: &Option) { let Some(throttle) = throttle else { @@ -1253,20 +1247,10 @@ impl SmgrOpTimer { inner.throttled += *throttle; } - pub(crate) fn observe_smgr_op_completion_and_start_flushing(mut self) -> SmgrOpFlushInProgress { + pub(crate) fn observe_smgr_op_completion_and_start_flushing(mut self) { let (flush_start, inner) = self .smgr_op_end() .expect("this method consume self, and the only other caller is drop handler"); - let SmgrOpTimerInner { - global_flush_in_progress_micros, - per_timeline_flush_in_progress_micros, - .. - } = inner; - SmgrOpFlushInProgress { - base: flush_start, - global_micros: global_flush_in_progress_micros, - per_timeline_micros: per_timeline_flush_in_progress_micros, - } } /// Returns `None`` if this method has already been called, `Some` otherwise. @@ -1312,42 +1296,6 @@ impl Drop for SmgrOpTimer { } } -impl SmgrOpFlushInProgress { - pub(crate) async fn measure(mut self, mut fut: Fut) -> O - where - Fut: std::future::Future, - { - let mut fut = std::pin::pin!(fut); - - let now = Instant::now(); - // Whenever observe_guard gets called, or dropped, - // it adds the time elapsed since its last call to metrics. - // Last call is tracked in `now`. - let mut observe_guard = scopeguard::guard( - || { - let elapsed = now - self.base; - self.global_micros - .inc_by(u64::try_from(elapsed.as_micros()).unwrap()); - self.per_timeline_micros - .inc_by(u64::try_from(elapsed.as_micros()).unwrap()); - self.base = now; - }, - |mut observe| { - observe(); - }, - ); - - loop { - match tokio::time::timeout(Duration::from_secs(10), &mut fut).await { - Ok(v) => return v, - Err(_timeout) => { - (*observe_guard)(); - } - } - } - } -} - #[derive( Debug, Clone, diff --git a/pageserver/src/page_service.rs b/pageserver/src/page_service.rs index dc0bbb3afb..e577b4221d 100644 --- a/pageserver/src/page_service.rs +++ b/pageserver/src/page_service.rs @@ -1076,13 +1076,6 @@ impl PageServerHandler { // what we want to do let flush_fut = pgb_writer.flush(); - // metric for how long flushing takes - let flush_fut = match flushing_timer { - Some(flushing_timer) => { - futures::future::Either::Left(flushing_timer.measure(flush_fut)) - } - None => futures::future::Either::Right(flush_fut), - }; // do it while respecting cancellation let _: () = async move { tokio::select! {