feat(metrics): add histograms for worker spawn durations in proof task metrics

This commit is contained in:
Yong Kang
2025-10-30 18:39:20 +08:00
parent ff46daddb6
commit ea1bafcc64
2 changed files with 38 additions and 0 deletions

View File

@@ -141,6 +141,10 @@ impl ProofWorkerHandle {
let parent_span =
debug_span!(target: "trie::proof_task", "storage proof workers", ?storage_worker_count)
.entered();
// Capture timestamp before spawning storage workers
let storage_spawn_start = Instant::now();
// Spawn storage workers
for worker_id in 0..storage_worker_count {
let span = debug_span!(target: "trie::proof_task", "storage worker", ?worker_id);
@@ -159,6 +163,8 @@ impl ProofWorkerHandle {
worker_id,
storage_available_workers_clone,
#[cfg(feature = "metrics")]
storage_spawn_start,
#[cfg(feature = "metrics")]
metrics,
)
});
@@ -168,6 +174,10 @@ impl ProofWorkerHandle {
let parent_span =
debug_span!(target: "trie::proof_task", "account proof workers", ?storage_worker_count)
.entered();
// Capture timestamp before spawning account workers
let account_spawn_start = Instant::now();
// Spawn account workers
for worker_id in 0..account_worker_count {
let span = debug_span!(target: "trie::proof_task", "account worker", ?worker_id);
@@ -188,6 +198,8 @@ impl ProofWorkerHandle {
worker_id,
account_available_workers_clone,
#[cfg(feature = "metrics")]
account_spawn_start,
#[cfg(feature = "metrics")]
metrics,
)
});
@@ -632,6 +644,7 @@ fn storage_worker_loop<Factory>(
work_rx: CrossbeamReceiver<StorageWorkerJob>,
worker_id: usize,
available_workers: Arc<AtomicUsize>,
#[cfg(feature = "metrics")] spawn_start: Instant,
#[cfg(feature = "metrics")] metrics: ProofTaskTrieMetrics,
) where
Factory: DatabaseProviderROFactory<Provider: TrieCursorFactory + HashedCursorFactory>,
@@ -655,6 +668,10 @@ fn storage_worker_loop<Factory>(
// Initially mark this worker as available.
available_workers.fetch_add(1, Ordering::Relaxed);
// Record time from spawn start to worker marking itself available
#[cfg(feature = "metrics")]
metrics.record_storage_worker_spawn_to_available_duration(spawn_start.elapsed());
while let Ok(job) = work_rx.recv() {
// Mark worker as busy.
available_workers.fetch_sub(1, Ordering::Relaxed);
@@ -803,6 +820,7 @@ fn account_worker_loop<Factory>(
storage_work_tx: CrossbeamSender<StorageWorkerJob>,
worker_id: usize,
available_workers: Arc<AtomicUsize>,
#[cfg(feature = "metrics")] spawn_start: Instant,
#[cfg(feature = "metrics")] metrics: ProofTaskTrieMetrics,
) where
Factory: DatabaseProviderROFactory<Provider: TrieCursorFactory + HashedCursorFactory>,
@@ -826,6 +844,10 @@ fn account_worker_loop<Factory>(
// Count this worker as available only after successful initialization.
available_workers.fetch_add(1, Ordering::Relaxed);
// Record time from spawn start to worker marking itself available
#[cfg(feature = "metrics")]
metrics.record_account_worker_spawn_to_available_duration(spawn_start.elapsed());
while let Ok(job) = work_rx.recv() {
// Mark worker as busy.
available_workers.fetch_sub(1, Ordering::Relaxed);

View File

@@ -8,6 +8,12 @@ pub struct ProofTaskTrieMetrics {
blinded_account_nodes: Histogram,
/// A histogram for the number of blinded storage nodes fetched.
blinded_storage_nodes: Histogram,
/// A histogram tracking time from starting storage worker spawn to when each worker marks
/// itself available (after initialization, before grabbing first job).
storage_worker_spawn_to_available_duration: Histogram,
/// A histogram tracking time from starting account worker spawn to when each worker marks
/// itself available (after initialization, before grabbing first job).
account_worker_spawn_to_available_duration: Histogram,
}
impl ProofTaskTrieMetrics {
@@ -20,4 +26,14 @@ impl ProofTaskTrieMetrics {
pub fn record_storage_nodes(&self, count: usize) {
self.blinded_storage_nodes.record(count as f64);
}
/// Record storage worker spawn-to-available duration.
pub fn record_storage_worker_spawn_to_available_duration(&self, duration: std::time::Duration) {
self.storage_worker_spawn_to_available_duration.record(duration.as_secs_f64());
}
/// Record account worker spawn-to-available duration.
pub fn record_account_worker_spawn_to_available_duration(&self, duration: std::time::Duration) {
self.account_worker_spawn_to_available_duration.record(duration.as_secs_f64());
}
}