From d51a1b4b89a655c09c54493cb848553d6226903b Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 19 Sep 2023 18:34:43 +0200 Subject: [PATCH] WIP: per-task-kind page cache stats --- pageserver/src/metrics.rs | 75 ++++++++++++++++++++++-------------- pageserver/src/page_cache.rs | 11 +++++- pageserver/src/task_mgr.rs | 1 + 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/pageserver/src/metrics.rs b/pageserver/src/metrics.rs index 582aab0aa56bd..1aa168f3be93f 100644 --- a/pageserver/src/metrics.rs +++ b/pageserver/src/metrics.rs @@ -1,3 +1,4 @@ +use enum_map::EnumMap; use metrics::metric_vec_duration::DurationResultObserver; use metrics::{ register_counter_vec, register_gauge_vec, register_histogram, register_histogram_vec, @@ -127,7 +128,7 @@ pub(crate) static MATERIALIZED_PAGE_CACHE_HIT: Lazy = Lazy::new(|| { .expect("failed to define a metric") }); -pub struct PageCacheMetrics { +pub struct PageCacheMetricsForTaskKind { pub read_accesses_materialized_page: IntCounter, pub read_accesses_immutable: IntCounter, @@ -136,11 +137,15 @@ pub struct PageCacheMetrics { pub read_hits_materialized_page_older_lsn: IntCounter, } +pub struct PageCacheMetrics { + by_task_kind: EnumMap, +} + static PAGE_CACHE_READ_HITS: Lazy = Lazy::new(|| { register_int_counter_vec!( "pageserver_page_cache_read_hits_total", "Number of read accesses to the page cache that hit", - &["key_kind", "hit_kind"] + &["task_kind", "key_kind", "hit_kind"] ) .expect("failed to define a metric") }); @@ -149,43 +154,55 @@ static PAGE_CACHE_READ_ACCESSES: Lazy = Lazy::new(|| { register_int_counter_vec!( "pageserver_page_cache_read_accesses_total", "Number of read accesses to the page cache", - &["key_kind"] + &["task_kind", "key_kind"] ) .expect("failed to define a metric") }); pub static PAGE_CACHE: Lazy = Lazy::new(|| PageCacheMetrics { - read_accesses_materialized_page: { - PAGE_CACHE_READ_ACCESSES - .get_metric_with_label_values(&["materialized_page"]) - .unwrap() - }, + by_task_kind: EnumMap::from_array(std::array::from_fn(|task_kind| { + let task_kind = ::from_usize(task_kind); + let task_kind: &'static str = task_kind.into(); + PageCacheMetricsForTaskKind { + read_accesses_materialized_page: { + PAGE_CACHE_READ_ACCESSES + .get_metric_with_label_values(&[task_kind, "materialized_page"]) + .unwrap() + }, - read_accesses_immutable: { - PAGE_CACHE_READ_ACCESSES - .get_metric_with_label_values(&["immutable"]) - .unwrap() - }, + read_accesses_immutable: { + PAGE_CACHE_READ_ACCESSES + .get_metric_with_label_values(&[task_kind, "immutable"]) + .unwrap() + }, - read_hits_immutable: { - PAGE_CACHE_READ_HITS - .get_metric_with_label_values(&["immutable", "-"]) - .unwrap() - }, + read_hits_immutable: { + PAGE_CACHE_READ_HITS + .get_metric_with_label_values(&[task_kind, "immutable", "-"]) + .unwrap() + }, - read_hits_materialized_page_exact: { - PAGE_CACHE_READ_HITS - .get_metric_with_label_values(&["materialized_page", "exact"]) - .unwrap() - }, + read_hits_materialized_page_exact: { + PAGE_CACHE_READ_HITS + .get_metric_with_label_values(&[task_kind, "materialized_page", "exact"]) + .unwrap() + }, - read_hits_materialized_page_older_lsn: { - PAGE_CACHE_READ_HITS - .get_metric_with_label_values(&["materialized_page", "older_lsn"]) - .unwrap() - }, + read_hits_materialized_page_older_lsn: { + PAGE_CACHE_READ_HITS + .get_metric_with_label_values(&[task_kind, "materialized_page", "older_lsn"]) + .unwrap() + }, + } + })), }); +impl PageCacheMetrics { + pub(crate) fn for_task_kind(&self, task_kind: TaskKind) -> &PageCacheMetricsForTaskKind { + &self.by_task_kind[task_kind] + } +} + pub struct PageCacheSizeMetrics { pub max_bytes: UIntGauge, @@ -1266,6 +1283,8 @@ use std::sync::{Arc, Mutex}; use std::task::{Context, Poll}; use std::time::{Duration, Instant}; +use crate::task_mgr::TaskKind; + pub struct RemoteTimelineClientMetrics { tenant_id: String, timeline_id: String, diff --git a/pageserver/src/page_cache.rs b/pageserver/src/page_cache.rs index 9cc1bf35dc4fa..76f6b487dbcb7 100644 --- a/pageserver/src/page_cache.rs +++ b/pageserver/src/page_cache.rs @@ -348,6 +348,7 @@ impl PageCache { lsn: Lsn, ) -> Option<(Lsn, PageReadGuard)> { crate::metrics::PAGE_CACHE + .for_task_kind(todo!()) .read_accesses_materialized_page .inc(); @@ -368,10 +369,12 @@ impl PageCache { { if available_lsn == lsn { crate::metrics::PAGE_CACHE + .for_task_kind(todo!()) .read_hits_materialized_page_exact .inc(); } else { crate::metrics::PAGE_CACHE + .for_task_kind(todo!()) .read_hits_materialized_page_older_lsn .inc(); } @@ -503,8 +506,12 @@ impl PageCache { unreachable!("Materialized pages use lookup_materialized_page") } CacheKey::ImmutableFilePage { .. } => ( - &crate::metrics::PAGE_CACHE.read_accesses_immutable, - &crate::metrics::PAGE_CACHE.read_hits_immutable, + &crate::metrics::PAGE_CACHE + .for_task_kind(todo!()) + .read_accesses_immutable, + &crate::metrics::PAGE_CACHE + .for_task_kind(todo!()) + .read_hits_immutable, ), }; read_access.inc(); diff --git a/pageserver/src/task_mgr.rs b/pageserver/src/task_mgr.rs index 3c7a1115df507..650bc119b6244 100644 --- a/pageserver/src/task_mgr.rs +++ b/pageserver/src/task_mgr.rs @@ -187,6 +187,7 @@ task_local! { Debug, // NB: enumset::EnumSetType derives PartialEq, Eq, Clone, Copy enumset::EnumSetType, + enum_map::Enum, serde::Serialize, serde::Deserialize, strum_macros::IntoStaticStr,