Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alloc-metrics: Record memory allocator metrics
As we want observability into the jemalloc allocator, this commit introduces a new crate, `readyset-alloc-metrics`, that fetches the current jemalloc state via `readyset-alloc`, and publishes those as metrics (gauges) to our prometheus handler. As the values are gauges, we need to sample the jemalloc stats periodically. This new crate is enabled in both adapter and server. Change-Id: If428829f3f3015ee8d40fdae4655161a8923ba88 Reviewed-on: https://gerrit.readyset.name/c/readyset/+/6246 Tested-by: Buildkite CI Reviewed-by: Luke Osborne <luke@readyset.io>
- Loading branch information
1 parent
b0546d7
commit 99e6fb8
Showing
9 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "readyset-alloc-metrics" | ||
version = "0.1.0" | ||
publish = false | ||
authors = ["ReadySet Technology, Inc. <info@readyset.io>"] | ||
edition = "2021" | ||
|
||
|
||
[dependencies] | ||
metrics = { workspace = true } | ||
metrics-exporter-prometheus = { workspace = true } | ||
tokio = { workspace = true, features = ["full"] } | ||
tracing = { version = "0.1", features = ["release_max_level_debug"] } | ||
|
||
# Local dependencies | ||
readyset-alloc = { path = "../readyset-alloc" } | ||
readyset-util = { path = "../readyset-util" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use std::time::Duration; | ||
|
||
use metrics::Gauge; | ||
use readyset_alloc::fetch_stats; | ||
use readyset_util::shutdown::ShutdownReceiver; | ||
use tokio::select; | ||
use tracing::info; | ||
|
||
const REPORTING_INTERVAL: Duration = Duration::from_secs(2); | ||
|
||
const ALLOCATED_BYTES: &str = "readyset_allocator_allocated_bytes"; | ||
const ACTIVE_BYTES: &str = "readyset_allocator_active_bytes"; | ||
const RETAINED_BYTES: &str = "readyset_allocator_retained_bytes"; | ||
const MAPPED_BYTES: &str = "readyset_allocator_mapped_bytes"; | ||
const DIRTY_BYTES: &str = "readyset_allocator_dirty_bytes"; | ||
const FRAGMENTED_BYTES: &str = "readyset_allocator_fragmented_bytes"; | ||
|
||
pub async fn report_allocator_metrics(mut shutdown_rx: ShutdownReceiver) { | ||
let mut interval = tokio::time::interval(REPORTING_INTERVAL); | ||
let mut reporter = AllocatorMetricsReporter::new(); | ||
|
||
loop { | ||
select! { | ||
_ = interval.tick() => reporter.report_metrics(), | ||
_ = shutdown_rx.recv() => break, | ||
} | ||
} | ||
} | ||
|
||
struct AllocatorMetricsReporter { | ||
allocated: Gauge, | ||
active: Gauge, | ||
retained: Gauge, | ||
mapped: Gauge, | ||
dirty: Gauge, | ||
fragmented: Gauge, | ||
} | ||
|
||
impl AllocatorMetricsReporter { | ||
fn new() -> Self { | ||
Self { | ||
allocated: metrics::register_gauge!(ALLOCATED_BYTES), | ||
active: metrics::register_gauge!(ACTIVE_BYTES), | ||
retained: metrics::register_gauge!(RETAINED_BYTES), | ||
mapped: metrics::register_gauge!(MAPPED_BYTES), | ||
dirty: metrics::register_gauge!(DIRTY_BYTES), | ||
fragmented: metrics::register_gauge!(FRAGMENTED_BYTES), | ||
} | ||
} | ||
|
||
fn report_metrics(&mut self) { | ||
// Note: we could call alloc::jemalloc::iterate_thread_allocation_stats() to get the | ||
// per-thread dump. `fetch_stats` is sufficient for now. | ||
// Additional note: iterate_thread_allocation_stats() doesn't automatically bump the | ||
// it's epoch, so you'll need to do that (just read the code if you are interested). | ||
|
||
match fetch_stats() { | ||
Ok(stats) => { | ||
info!("NEXT alloc stats: {:?}", stats); | ||
self.allocated.set(stats.allocated as f64); | ||
self.active.set(stats.active as f64); | ||
self.retained.set(stats.retained as f64); | ||
self.mapped.set(stats.mapped as f64); | ||
self.dirty.set(stats.dirty as f64); | ||
self.fragmented.set(stats.fragmentation as f64); | ||
} | ||
Err(e) => { | ||
// not sure what else to do but log, at a low level :shrug: | ||
info!("Failed to fetch memory allocator stats: {:?}", e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters