mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Task Executor Metrics (#2580)
Co-authored-by: Aditya Pandey <aditya.p@Aditya-P.local>
This commit is contained in:
@ -7,7 +7,10 @@
|
||||
|
||||
//! reth task management
|
||||
|
||||
use crate::shutdown::{signal, Shutdown, Signal};
|
||||
use crate::{
|
||||
metrics::TaskExecutorMetrics,
|
||||
shutdown::{signal, Shutdown, Signal},
|
||||
};
|
||||
use dyn_clone::DynClone;
|
||||
use futures_util::{
|
||||
future::{select, BoxFuture},
|
||||
@ -25,6 +28,7 @@ use tokio::{
|
||||
use tracing::error;
|
||||
use tracing_futures::Instrument;
|
||||
|
||||
pub mod metrics;
|
||||
pub mod shutdown;
|
||||
|
||||
/// A type that can spawn tasks.
|
||||
@ -160,6 +164,7 @@ impl TaskManager {
|
||||
handle: self.handle.clone(),
|
||||
on_shutdown: self.on_shutdown.clone(),
|
||||
panicked_tasks_tx: self.panicked_tasks_tx.clone(),
|
||||
metrics: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -192,6 +197,8 @@ pub struct TaskExecutor {
|
||||
on_shutdown: Shutdown,
|
||||
/// Sender half for sending panic signals to this type
|
||||
panicked_tasks_tx: UnboundedSender<&'static str>,
|
||||
// Task Executor Metrics
|
||||
metrics: TaskExecutorMetrics,
|
||||
}
|
||||
|
||||
// === impl TaskExecutor ===
|
||||
@ -358,10 +365,12 @@ impl TaskExecutor {
|
||||
|
||||
impl TaskSpawner for TaskExecutor {
|
||||
fn spawn(&self, fut: BoxFuture<'static, ()>) -> JoinHandle<()> {
|
||||
self.metrics.inc_regular_task();
|
||||
self.spawn(fut)
|
||||
}
|
||||
|
||||
fn spawn_critical(&self, name: &'static str, fut: BoxFuture<'static, ()>) -> JoinHandle<()> {
|
||||
self.metrics.inc_critical_tasks();
|
||||
TaskExecutor::spawn_critical(self, name, fut)
|
||||
}
|
||||
|
||||
|
||||
24
crates/tasks/src/metrics.rs
Normal file
24
crates/tasks/src/metrics.rs
Normal file
@ -0,0 +1,24 @@
|
||||
//! Task Executor Metrics
|
||||
use metrics::Counter;
|
||||
use reth_metrics_derive::Metrics;
|
||||
|
||||
/// Task Executor Metrics
|
||||
#[derive(Metrics, Clone)]
|
||||
#[metrics(scope = "executor.spawn")]
|
||||
pub struct TaskExecutorMetrics {
|
||||
/// Number of spawned critical tasks
|
||||
pub(crate) critical_tasks: Counter,
|
||||
|
||||
/// Number of spawned regular tasks
|
||||
pub(crate) regular_tasks: Counter,
|
||||
}
|
||||
|
||||
impl TaskExecutorMetrics {
|
||||
pub(crate) fn inc_critical_tasks(&self) {
|
||||
self.critical_tasks.increment(1);
|
||||
}
|
||||
|
||||
pub(crate) fn inc_regular_task(&self) {
|
||||
self.regular_tasks.increment(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user