Skip to content

Commit 707557a

Browse files
committed
Clean up hdiff timing metrics
1 parent 22f7f73 commit 707557a

File tree

3 files changed

+98
-68
lines changed

3 files changed

+98
-68
lines changed

beacon_node/store/src/historic_state_cache.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ impl<E: EthSpec> HistoricStateCache<E> {
3434

3535
pub fn get_hdiff_buffer(&mut self, slot: Slot) -> Option<HDiffBuffer> {
3636
if let Some(buffer_ref) = self.hdiff_buffers.get(&slot) {
37-
let _timer = metrics::start_timer(&metrics::BEACON_COLD_HDIFF_BUFFER_CLONE_TIMES);
37+
let _timer = metrics::start_timer_vec(
38+
&metrics::BEACON_HDIFF_BUFFER_CLONE_TIME,
39+
metrics::COLD_METRIC,
40+
);
3841
Some(buffer_ref.clone())
3942
} else if let Some(state) = self.states.get(&slot) {
4043
let buffer = HDiffBuffer::from_state(state.clone());
41-
let _timer = metrics::start_timer(&metrics::BEACON_COLD_HDIFF_BUFFER_CLONE_TIMES);
44+
let _timer = metrics::start_timer_vec(
45+
&metrics::BEACON_HDIFF_BUFFER_CLONE_TIME,
46+
metrics::COLD_METRIC,
47+
);
4248
let cloned = buffer.clone();
4349
drop(_timer);
4450
self.hdiff_buffers.put(slot, cloned);

beacon_node/store/src/hot_cold_store.rs

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ use crate::metadata::{
1313
};
1414
use crate::state_cache::{PutStateOutcome, StateCache};
1515
use crate::{
16-
get_data_column_key, metrics, parse_data_column_key, BlobSidecarListFromRoot, DBColumn,
17-
DatabaseBlock, Error, ItemStore, KeyValueStoreOp, StoreItem, StoreOp,
16+
get_data_column_key,
17+
metrics::{self, COLD_METRIC, HOT_METRIC},
18+
parse_data_column_key, BlobSidecarListFromRoot, DBColumn, DatabaseBlock, Error, ItemStore,
19+
KeyValueStoreOp, StoreItem, StoreOp,
1820
};
1921
use itertools::{process_results, Itertools};
2022
use lru::LruCache;
@@ -1567,15 +1569,24 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
15671569
from_root: Hash256,
15681570
ops: &mut Vec<KeyValueStoreOp>,
15691571
) -> Result<(), Error> {
1570-
let base_buffer = self.load_hot_hdiff_buffer(from_root).map_err(|e| {
1571-
Error::LoadingHotHdiffBufferError(
1572-
format!("store state as diff {state_root:?} {}", state.slot()),
1573-
from_root,
1574-
e.into(),
1575-
)
1576-
})?;
1572+
let base_buffer = {
1573+
let _t = metrics::start_timer_vec(
1574+
&metrics::BEACON_HDIFF_BUFFER_LOAD_BEFORE_STORE_TIME,
1575+
HOT_METRIC,
1576+
);
1577+
self.load_hot_hdiff_buffer(from_root).map_err(|e| {
1578+
Error::LoadingHotHdiffBufferError(
1579+
format!("store state as diff {state_root:?} {}", state.slot()),
1580+
from_root,
1581+
e.into(),
1582+
)
1583+
})?
1584+
};
15771585
let target_buffer = HDiffBuffer::from_state(state.clone());
1578-
let diff = HDiff::compute(&base_buffer, &target_buffer, &self.config)?;
1586+
let diff = {
1587+
let _timer = metrics::start_timer_vec(&metrics::BEACON_HDIFF_COMPUTE_TIME, HOT_METRIC);
1588+
HDiff::compute(&base_buffer, &target_buffer, &self.config)?
1589+
};
15791590
let diff_bytes = diff.as_ssz_bytes();
15801591
ops.push(KeyValueStoreOp::PutKeyValue(
15811592
DBColumn::BeaconStateHotDiff,
@@ -1669,7 +1680,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
16691680
)
16701681
})?;
16711682
let diff = self.load_hot_hdiff(state_root)?;
1672-
diff.apply(&mut buffer, &self.config)?;
1683+
{
1684+
let _timer =
1685+
metrics::start_timer_vec(&metrics::BEACON_HDIFF_APPLY_TIME, HOT_METRIC);
1686+
diff.apply(&mut buffer, &self.config)?;
1687+
}
16731688
Ok(buffer)
16741689
}
16751690
StorageStrategy::ReplayFrom(from_slot) => {
@@ -1687,13 +1702,13 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
16871702

16881703
fn load_hot_hdiff(&self, state_root: Hash256) -> Result<HDiff, Error> {
16891704
let bytes = {
1690-
let _t = metrics::start_timer(&metrics::BEACON_HOT_HDIFF_READ_TIMES);
1705+
let _t = metrics::start_timer_vec(&metrics::BEACON_HDIFF_READ_TIME, HOT_METRIC);
16911706
self.hot_db
16921707
.get_bytes(DBColumn::BeaconStateHotDiff, state_root.as_slice())?
16931708
.ok_or(HotColdDBError::MissingHotHDiff(state_root))?
16941709
};
16951710
let hdiff = {
1696-
let _t = metrics::start_timer(&metrics::BEACON_HOT_HDIFF_DECODE_TIMES);
1711+
let _t = metrics::start_timer_vec(&metrics::BEACON_HDIFF_DECODE_TIME, HOT_METRIC);
16971712
HDiff::from_ssz_bytes(&bytes)?
16981713
};
16991714
Ok(hdiff)
@@ -1721,13 +1736,18 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
17211736
{
17221737
let mut state = match self.hot_storage_strategy(slot)? {
17231738
strat @ StorageStrategy::Snapshot | strat @ StorageStrategy::DiffFrom(_) => {
1739+
let buffer_timer = metrics::start_timer_vec(
1740+
&metrics::BEACON_HDIFF_BUFFER_LOAD_TIME,
1741+
HOT_METRIC,
1742+
);
17241743
let buffer = self.load_hot_hdiff_buffer(*state_root).map_err(|e| {
17251744
Error::LoadingHotHdiffBufferError(
17261745
format!("load state {strat:?} {slot}"),
17271746
*state_root,
17281747
e.into(),
17291748
)
17301749
})?;
1750+
drop(buffer_timer);
17311751
let mut state = buffer.as_state(&self.spec)?;
17321752

17331753
// Immediately rebase the state from diffs on the finalized state so that we
@@ -2006,12 +2026,15 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
20062026
) -> Result<(), Error> {
20072027
// Load diff base state bytes.
20082028
let (_, base_buffer) = {
2009-
let _t = metrics::start_timer(&metrics::STORE_BEACON_HDIFF_BUFFER_LOAD_FOR_STORE_TIME);
2029+
let _t = metrics::start_timer_vec(
2030+
&metrics::BEACON_HDIFF_BUFFER_LOAD_BEFORE_STORE_TIME,
2031+
COLD_METRIC,
2032+
);
20102033
self.load_hdiff_buffer_for_slot(from_slot)?
20112034
};
20122035
let target_buffer = HDiffBuffer::from_state(state.clone());
20132036
let diff = {
2014-
let _timer = metrics::start_timer(&metrics::STORE_BEACON_HDIFF_BUFFER_COMPUTE_TIME);
2037+
let _timer = metrics::start_timer_vec(&metrics::BEACON_HDIFF_COMPUTE_TIME, COLD_METRIC);
20152038
HDiff::compute(&base_buffer, &target_buffer, &self.config)?
20162039
};
20172040
let diff_bytes = diff.as_ssz_bytes();
@@ -2070,7 +2093,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
20702093
match self.cold_storage_strategy(slot)? {
20712094
StorageStrategy::Snapshot | StorageStrategy::DiffFrom(_) => {
20722095
let buffer_timer =
2073-
metrics::start_timer(&metrics::STORE_BEACON_HDIFF_BUFFER_LOAD_TIME);
2096+
metrics::start_timer_vec(&metrics::BEACON_HDIFF_BUFFER_LOAD_TIME, COLD_METRIC);
20742097
let (_, buffer) = self.load_hdiff_buffer_for_slot(slot)?;
20752098
drop(buffer_timer);
20762099
let state = buffer.as_state(&self.spec)?;
@@ -2139,13 +2162,13 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
21392162

21402163
fn load_hdiff_for_slot(&self, slot: Slot) -> Result<HDiff, Error> {
21412164
let bytes = {
2142-
let _t = metrics::start_timer(&metrics::BEACON_COLD_HDIFF_READ_TIMES);
2165+
let _t = metrics::start_timer_vec(&metrics::BEACON_HDIFF_READ_TIME, COLD_METRIC);
21432166
self.cold_db
21442167
.get_bytes(DBColumn::BeaconStateDiff, &slot.as_u64().to_be_bytes())?
21452168
.ok_or(HotColdDBError::MissingHDiff(slot))?
21462169
};
21472170
let hdiff = {
2148-
let _t = metrics::start_timer(&metrics::BEACON_COLD_HDIFF_DECODE_TIMES);
2171+
let _t = metrics::start_timer_vec(&metrics::BEACON_HDIFF_DECODE_TIME, COLD_METRIC);
21492172
HDiff::from_ssz_bytes(&bytes)?
21502173
};
21512174
Ok(hdiff)
@@ -2196,7 +2219,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
21962219
let diff = self.load_hdiff_for_slot(slot)?;
21972220
{
21982221
let _timer =
2199-
metrics::start_timer(&metrics::STORE_BEACON_HDIFF_BUFFER_APPLY_TIME);
2222+
metrics::start_timer_vec(&metrics::BEACON_HDIFF_APPLY_TIME, COLD_METRIC);
22002223
diff.apply(&mut buffer, &self.config)?;
22012224
}
22022225

beacon_node/store/src/metrics.rs

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ use directory::size_of_dir;
44
use std::path::Path;
55
use std::sync::LazyLock;
66

7+
// Labels used for histogram timer vecs that are tracked per DB (hot and cold).
8+
pub const HOT_METRIC: &[&str] = &["hot"];
9+
pub const COLD_METRIC: &[&str] = &["cold"];
10+
711
/*
812
* General
913
*/
@@ -142,35 +146,59 @@ pub static BEACON_STATE_HOT_GET_COUNT: LazyLock<Result<IntCounter>> = LazyLock::
142146
"Total number of hot beacon states requested from the store (cache or DB)",
143147
)
144148
});
145-
pub static BEACON_HOT_HDIFF_READ_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
146-
try_create_histogram(
147-
"store_hot_hdiff_read_seconds",
148-
"Time required to read hierarchical diff bytes from the hot database",
149+
150+
/*
151+
* HDiffs
152+
*/
153+
pub static BEACON_HDIFF_READ_TIME: LazyLock<Result<HistogramVec>> = LazyLock::new(|| {
154+
try_create_histogram_vec(
155+
"store_hdiff_read_seconds",
156+
"Time taken to read hdiff bytes from disk",
157+
&["db"],
149158
)
150159
});
151-
pub static BEACON_HOT_HDIFF_DECODE_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
152-
try_create_histogram(
153-
"store_hot_hdiff_decode_seconds",
154-
"Time required to decode hierarchical diff bytes from the hot database",
160+
pub static BEACON_HDIFF_DECODE_TIME: LazyLock<Result<HistogramVec>> = LazyLock::new(|| {
161+
try_create_histogram_vec(
162+
"store_hdiff_decode_seconds",
163+
"Time taken to decode hdiff bytes",
164+
&["db"],
155165
)
156166
});
157-
pub static BEACON_COLD_HDIFF_READ_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
158-
try_create_histogram(
159-
"store_cold_hdiff_read_seconds",
160-
"Time required to read the hierarchical diff bytes from the database",
167+
pub static BEACON_HDIFF_APPLY_TIME: LazyLock<Result<HistogramVec>> = LazyLock::new(|| {
168+
try_create_histogram_vec(
169+
"store_hdiff_apply_seconds",
170+
"Time taken to apply an hdiff to a buffer",
171+
&["db"],
161172
)
162173
});
163-
pub static BEACON_COLD_HDIFF_DECODE_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
164-
try_create_histogram(
165-
"store_cold_hdiff_decode_seconds",
166-
"Time required to decode hierarchical diff bytes",
174+
pub static BEACON_HDIFF_COMPUTE_TIME: LazyLock<Result<HistogramVec>> = LazyLock::new(|| {
175+
try_create_histogram_vec(
176+
"store_hdiff_compute_seconds",
177+
"Time taken to compute an hdiff for a state",
178+
&["db"],
179+
)
180+
});
181+
pub static BEACON_HDIFF_BUFFER_LOAD_TIME: LazyLock<Result<HistogramVec>> = LazyLock::new(|| {
182+
try_create_histogram_vec(
183+
"store_hdiff_buffer_load_seconds",
184+
"Time taken to load an hdiff buffer for a state",
185+
&["db"],
167186
)
168187
});
169-
pub static BEACON_COLD_HDIFF_BUFFER_CLONE_TIMES: LazyLock<Result<Histogram>> =
188+
// NB: the `hot` version of this metric doesn't currently exist as we don't cache hot buffers
189+
pub static BEACON_HDIFF_BUFFER_CLONE_TIME: LazyLock<Result<HistogramVec>> = LazyLock::new(|| {
190+
try_create_histogram_vec(
191+
"store_hdiff_buffer_clone_seconds",
192+
"Time taken to clone an hdiff buffer from a cache",
193+
&["db"],
194+
)
195+
});
196+
pub static BEACON_HDIFF_BUFFER_LOAD_BEFORE_STORE_TIME: LazyLock<Result<HistogramVec>> =
170197
LazyLock::new(|| {
171-
try_create_histogram(
172-
"store_cold_hdiff_buffer_clone_seconds",
173-
"Time required to clone hierarchical diff buffer bytes",
198+
try_create_histogram_vec(
199+
"store_hdiff_buffer_load_before_store_seconds",
200+
"Time taken to load the hdiff buffer required for the storage of a new state",
201+
&["db"],
174202
)
175203
});
176204
// This metric is not split hot/cold because it is recorded in a place where that info is not known.
@@ -258,33 +286,6 @@ pub static STORE_BEACON_STATE_FREEZER_DECOMPRESS_TIME: LazyLock<Result<Histogram
258286
"Time taken to decompress a state snapshot for the freezer DB",
259287
)
260288
});
261-
pub static STORE_BEACON_HDIFF_BUFFER_APPLY_TIME: LazyLock<Result<Histogram>> =
262-
LazyLock::new(|| {
263-
try_create_histogram(
264-
"store_beacon_hdiff_buffer_apply_seconds",
265-
"Time taken to apply hdiff buffer to a state buffer",
266-
)
267-
});
268-
pub static STORE_BEACON_HDIFF_BUFFER_COMPUTE_TIME: LazyLock<Result<Histogram>> =
269-
LazyLock::new(|| {
270-
try_create_histogram(
271-
"store_beacon_hdiff_buffer_compute_seconds",
272-
"Time taken to compute hdiff buffer to a state buffer",
273-
)
274-
});
275-
pub static STORE_BEACON_HDIFF_BUFFER_LOAD_TIME: LazyLock<Result<Histogram>> = LazyLock::new(|| {
276-
try_create_histogram(
277-
"store_beacon_hdiff_buffer_load_seconds",
278-
"Time taken to load an hdiff buffer",
279-
)
280-
});
281-
pub static STORE_BEACON_HDIFF_BUFFER_LOAD_FOR_STORE_TIME: LazyLock<Result<Histogram>> =
282-
LazyLock::new(|| {
283-
try_create_histogram(
284-
"store_beacon_hdiff_buffer_load_for_store_seconds",
285-
"Time taken to load an hdiff buffer to store another hdiff",
286-
)
287-
});
288289
pub static STORE_BEACON_HISTORIC_STATE_CACHE_HIT: LazyLock<Result<IntCounter>> =
289290
LazyLock::new(|| {
290291
try_create_int_counter(

0 commit comments

Comments
 (0)