perf(db): throttle metrics reporting (#20974)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
DaniPopes
2026-01-12 22:44:24 +00:00
committed by GitHub
parent 98a35cc870
commit c5e00e4aeb
4 changed files with 117 additions and 34 deletions

View File

@@ -79,9 +79,12 @@ use reth_stages::{
};
use reth_static_file::StaticFileProducer;
use reth_tasks::TaskExecutor;
use reth_tracing::tracing::{debug, error, info, warn};
use reth_tracing::{
throttle,
tracing::{debug, error, info, warn},
};
use reth_transaction_pool::TransactionPool;
use std::{sync::Arc, thread::available_parallelism};
use std::{sync::Arc, thread::available_parallelism, time::Duration};
use tokio::sync::{
mpsc::{unbounded_channel, UnboundedSender},
oneshot, watch,
@@ -650,23 +653,13 @@ where
},
ChainSpecInfo { name: self.chain_id().to_string() },
self.task_executor().clone(),
Hooks::builder()
.with_hook({
let db = self.database().clone();
move || db.report_metrics()
})
.with_hook({
let sfp = self.static_file_provider();
move || {
if let Err(error) = sfp.report_metrics() {
error!(%error, "Failed to report metrics for the static file provider");
}
}
})
.build(),
metrics_hooks(self.provider_factory()),
self.data_dir().pprof_dumps(),
)
.with_push_gateway(self.node_config().metrics.push_gateway_url.clone(), self.node_config().metrics.push_gateway_interval);
.with_push_gateway(
self.node_config().metrics.push_gateway_url.clone(),
self.node_config().metrics.push_gateway_interval,
);
MetricServer::new(config).serve().await?;
}
@@ -1266,6 +1259,26 @@ where
head: Head,
}
/// Returns the metrics hooks for the node.
pub fn metrics_hooks<N: NodeTypesWithDB>(provider_factory: &ProviderFactory<N>) -> Hooks {
Hooks::builder()
.with_hook({
let db = provider_factory.db_ref().clone();
move || throttle!(Duration::from_secs(5 * 60), || db.report_metrics())
})
.with_hook({
let sfp = provider_factory.static_file_provider();
move || {
throttle!(Duration::from_secs(5 * 60), || {
if let Err(error) = sfp.report_metrics() {
error!(%error, "Failed to report metrics from static file provider");
}
})
}
})
.build()
}
#[cfg(test)]
mod tests {
use super::{LaunchContext, NodeConfig};