Skip to content

Commit

Permalink
WIP: per-task-kind page cache stats
Browse files Browse the repository at this point in the history
  • Loading branch information
problame committed Sep 19, 2023
1 parent a864083 commit d51a1b4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 30 deletions.
75 changes: 47 additions & 28 deletions pageserver/src/metrics.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -127,7 +128,7 @@ pub(crate) static MATERIALIZED_PAGE_CACHE_HIT: Lazy<IntCounter> = 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,

Expand All @@ -136,11 +137,15 @@ pub struct PageCacheMetrics {
pub read_hits_materialized_page_older_lsn: IntCounter,
}

pub struct PageCacheMetrics {
by_task_kind: EnumMap<TaskKind, PageCacheMetricsForTaskKind>,
}

static PAGE_CACHE_READ_HITS: Lazy<IntCounterVec> = 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")
});
Expand All @@ -149,43 +154,55 @@ static PAGE_CACHE_READ_ACCESSES: Lazy<IntCounterVec> = 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<PageCacheMetrics> = 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 = <TaskKind as enum_map::Enum>::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,

Expand Down Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions pageserver/src/page_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ impl PageCache {
lsn: Lsn,
) -> Option<(Lsn, PageReadGuard)> {
crate::metrics::PAGE_CACHE
.for_task_kind(todo!())
.read_accesses_materialized_page
.inc();

Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions pageserver/src/task_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d51a1b4

Please sign in to comment.