Skip to content

Commit 9c8e58c

Browse files
committed
Metric for hdiff sizes
1 parent 707557a commit 9c8e58c

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

beacon_node/store/src/hdiff.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,10 @@ impl HierarchyConfig {
649649
Err(Error::InvalidHierarchy)
650650
}
651651
}
652+
653+
pub fn exponent_for_slot(slot: Slot) -> u32 {
654+
slot.as_u64().trailing_zeros()
655+
}
652656
}
653657

654658
impl HierarchyModuli {

beacon_node/store/src/hot_cold_store.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::config::{OnDiskStoreConfig, StoreConfig};
22
use crate::database::interface::BeaconNodeBackend;
33
use crate::forwards_iter::{HybridForwardsBlockRootsIterator, HybridForwardsStateRootsIterator};
4-
use crate::hdiff::{HDiff, HDiffBuffer, HierarchyModuli, StorageStrategy};
4+
use crate::hdiff::{HDiff, HDiffBuffer, HierarchyConfig, HierarchyModuli, StorageStrategy};
55
use crate::historic_state_cache::HistoricStateCache;
66
use crate::iter::{BlockRootsIterator, ParentRootBlockIterator, RootsIterator};
77
use crate::memory_store::MemoryStore;
@@ -1588,6 +1588,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
15881588
HDiff::compute(&base_buffer, &target_buffer, &self.config)?
15891589
};
15901590
let diff_bytes = diff.as_ssz_bytes();
1591+
let layer = HierarchyConfig::exponent_for_slot(state.slot());
1592+
metrics::observe_vec(
1593+
&metrics::BEACON_HDIFF_SIZES,
1594+
&[&layer.to_string()],
1595+
diff_bytes.len() as f64,
1596+
);
15911597
ops.push(KeyValueStoreOp::PutKeyValue(
15921598
DBColumn::BeaconStateHotDiff,
15931599
state_root.as_slice().to_vec(),
@@ -2038,6 +2044,12 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
20382044
HDiff::compute(&base_buffer, &target_buffer, &self.config)?
20392045
};
20402046
let diff_bytes = diff.as_ssz_bytes();
2047+
let layer = HierarchyConfig::exponent_for_slot(state.slot());
2048+
metrics::observe_vec(
2049+
&metrics::BEACON_HDIFF_SIZES,
2050+
&[&layer.to_string()],
2051+
diff_bytes.len() as f64,
2052+
);
20412053

20422054
ops.push(KeyValueStoreOp::PutKeyValue(
20432055
DBColumn::BeaconStateDiff,

beacon_node/store/src/metrics.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,24 @@ pub static BEACON_HDIFF_BUFFER_APPLY_RESIZES: LazyLock<Result<Histogram>> = Lazy
209209
Ok(vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0])
210210
)
211211
});
212+
// This metric is not split hot/cold because both databases use the same hierarchy config anyway
213+
// and that's all that affects diff sizes.
214+
pub static BEACON_HDIFF_SIZES: LazyLock<Result<HistogramVec>> = LazyLock::new(|| {
215+
try_create_histogram_vec_with_buckets(
216+
"store_hdiff_sizes",
217+
"Size of hdiffs in bytes by layer (exponent)",
218+
Ok(vec![
219+
0.0,
220+
2_000.0,
221+
20_000.0,
222+
200_000.0,
223+
500_000.0,
224+
2_000_000.0,
225+
10_000_000.0,
226+
]),
227+
&["exponent"],
228+
)
229+
});
212230
/*
213231
* Beacon Block
214232
*/

0 commit comments

Comments
 (0)