Skip to content

Commit d1f641e

Browse files
committed
chore: add persist and RootStore metrics
1 parent 7d4d171 commit d1f641e

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

firewood/src/persist_worker.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ use parking_lot::{Condvar, Mutex, MutexGuard};
6464
use crate::{manager::CommittedRevision, root_store::RootStore};
6565
use crossbeam::channel::{self, Receiver, Sender};
6666

67+
use firewood_metrics::firewood_increment;
6768
use firewood_storage::logger::error;
6869

6970
/// Error type for persistence operations.
@@ -266,8 +267,11 @@ impl PersistSemaphore {
266267
#[inline]
267268
fn acquire(&self) {
268269
let mut permits = self.state.lock();
269-
while *permits == 0 {
270-
self.condvar.wait(&mut permits);
270+
if *permits == 0 {
271+
firewood_increment!(crate::registry::PERSIST_THROTTLE_BLOCKS, 1);
272+
while *permits == 0 {
273+
self.condvar.wait(&mut permits);
274+
}
271275
}
272276
// The background loop guarantees permits > 0
273277
*permits = permits.saturating_sub(1);
@@ -385,6 +389,7 @@ impl PersistLoop {
385389
}
386390

387391
/// Persists the given revision and releases semaphore permits.
392+
#[crate::metrics("persist.total", "persist revision to storage")]
388393
fn persist(
389394
&mut self,
390395
revision: &CommittedRevision,
@@ -444,9 +449,17 @@ impl PersistLoop {
444449
if let Some(ref store) = self.shared.root_store
445450
&& let (Some(hash), Some(addr)) = (revision.root_hash(), revision.root_address())
446451
{
447-
store
452+
let start = coarsetime::Instant::now();
453+
454+
let result = store
448455
.add_root(&hash, &addr)
449-
.map_err(|e| PersistError::RootStore(e.into()))?;
456+
.map_err(|e| PersistError::RootStore(e.into()));
457+
458+
let success = if result.is_err() { "false" } else { "true" };
459+
firewood_increment!(crate::registry::PERSIST_ROOT_STORE, 1, "success" => success);
460+
firewood_increment!(crate::registry::PERSIST_ROOT_STORE_MS, start.elapsed().as_millis(), "success" => success);
461+
462+
result?;
450463
}
451464

452465
Ok(())

firewood/src/registry.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ pub const ACTIVE_REVISIONS: &str = "active_revisions";
3535
/// Maximum number of revisions configured.
3636
pub const MAX_REVISIONS: &str = "max_revisions";
3737

38+
/// Number of times a commit blocked waiting for persistence to catch up.
39+
pub const PERSIST_THROTTLE_BLOCKS: &str = "persist.throttle_blocks";
40+
41+
/// Number of persist operations.
42+
pub const PERSIST_TOTAL: &str = "persist.total";
43+
44+
/// Persist latency in milliseconds.
45+
pub const PERSIST_TOTAL_MS: &str = "persist.total_ms";
46+
47+
/// Number of root store save operations.
48+
pub const PERSIST_ROOT_STORE: &str = "persist.root_store";
49+
50+
/// Root store save latency in milliseconds.
51+
pub const PERSIST_ROOT_STORE_MS: &str = "persist.root_store_ms";
52+
3853
/// Registers all firewood metric descriptions.
3954
pub fn register() {
4055
describe_counter!(PROPOSALS, "Number of proposals created");
@@ -59,4 +74,12 @@ pub fn register() {
5974
describe_counter!(COMMIT_LATENCY_MS, "Commit latency (ms)");
6075
describe_gauge!(ACTIVE_REVISIONS, "Current number of active revisions");
6176
describe_gauge!(MAX_REVISIONS, "Maximum number of revisions configured");
77+
describe_counter!(
78+
PERSIST_THROTTLE_BLOCKS,
79+
"Number of times a commit blocked waiting for persistence"
80+
);
81+
describe_counter!(PERSIST_TOTAL, "Number of persist operations");
82+
describe_counter!(PERSIST_TOTAL_MS, "Persist latency (ms)");
83+
describe_counter!(PERSIST_ROOT_STORE, "Number of root store save operations");
84+
describe_counter!(PERSIST_ROOT_STORE_MS, "Root store save latency (ms)");
6285
}

0 commit comments

Comments
 (0)