Skip to content

Commit

Permalink
log roots range metric (#16636)
Browse files Browse the repository at this point in the history
* log roots range metric

* rename
  • Loading branch information
jeffwashington authored Apr 23, 2021
1 parent 2c82f21 commit 1cc9a1c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
8 changes: 8 additions & 0 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ struct LatestAccountsIndexRootsStats {
roots_len: AtomicUsize,
uncleaned_roots_len: AtomicUsize,
previous_uncleaned_roots_len: AtomicUsize,
roots_range: AtomicU64,
}

impl LatestAccountsIndexRootsStats {
Expand All @@ -964,6 +965,8 @@ impl LatestAccountsIndexRootsStats {
accounts_index_roots_stats.previous_uncleaned_roots_len,
Ordering::Relaxed,
);
self.roots_range
.store(accounts_index_roots_stats.roots_range, Ordering::Relaxed);
}

fn report(&self) {
Expand All @@ -984,6 +987,11 @@ impl LatestAccountsIndexRootsStats {
self.previous_uncleaned_roots_len.load(Ordering::Relaxed) as i64,
i64
),
(
"roots_range_width",
self.roots_range.load(Ordering::Relaxed) as i64,
i64
),
);

// Don't need to reset since this tracks the latest updates, not a cumulative total
Expand Down
42 changes: 35 additions & 7 deletions runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ impl RollingBitField {
);
}

pub fn range_width(&self) -> u64 {
// note that max isn't updated on remove, so it can be above the current max
self.max - self.min
}

pub fn insert(&mut self, key: u64) {
self.check_range(key);
let address = self.get_address(&key);
Expand Down Expand Up @@ -254,14 +259,19 @@ impl RollingBitField {

// after removing 'key' where 'key' = min, make min the correct new min value
fn purge(&mut self, key: &u64) {
if key == &self.min && self.count > 0 {
let start = self.min + 1; // min just got removed
for key in start..self.max {
if self.contains_assume_in_range(&key) {
self.min = key;
break;
if self.count > 0 {
if key == &self.min {
let start = self.min + 1; // min just got removed
for key in start..self.max {
if self.contains_assume_in_range(&key) {
self.min = key;
break;
}
}
}
} else {
self.min = Slot::default();
self.max = Slot::default();
}
}

Expand Down Expand Up @@ -335,6 +345,7 @@ pub struct AccountsIndexRootsStats {
pub roots_len: usize,
pub uncleaned_roots_len: usize,
pub previous_uncleaned_roots_len: usize,
pub roots_range: u64,
}

pub struct AccountsIndexIterator<'a, T> {
Expand Down Expand Up @@ -1222,7 +1233,7 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
/// Accounts no longer reference this slot.
pub fn clean_dead_slot(&self, slot: Slot) -> Option<AccountsIndexRootsStats> {
if self.is_root(slot) {
let (roots_len, uncleaned_roots_len, previous_uncleaned_roots_len) = {
let (roots_len, uncleaned_roots_len, previous_uncleaned_roots_len, roots_range) = {
let mut w_roots_tracker = self.roots_tracker.write().unwrap();
w_roots_tracker.roots.remove(&slot);
w_roots_tracker.uncleaned_roots.remove(&slot);
Expand All @@ -1231,12 +1242,14 @@ impl<T: 'static + Clone + IsCached + ZeroLamport> AccountsIndex<T> {
w_roots_tracker.roots.len(),
w_roots_tracker.uncleaned_roots.len(),
w_roots_tracker.previous_uncleaned_roots.len(),
w_roots_tracker.roots.range_width(),
)
};
Some(AccountsIndexRootsStats {
roots_len,
uncleaned_roots_len,
previous_uncleaned_roots_len,
roots_range,
})
} else {
None
Expand Down Expand Up @@ -1561,9 +1574,24 @@ pub mod tests {
fn compare(hashset: &HashSet<u64>, bitfield: &RollingBitField) {
assert_eq!(hashset.len(), bitfield.len());
assert_eq!(hashset.is_empty(), bitfield.is_empty());
let mut min = Slot::MAX;
let mut max = Slot::MIN;
for item in bitfield.get_all() {
min = std::cmp::min(min, item);
max = std::cmp::max(max, item);
assert!(hashset.contains(&item));
}
assert!(
bitfield.range_width()
>= if bitfield.is_empty() {
0
} else {
max + 1 - min
},
"hashset: {:?}, bitfield: {:?}",
hashset,
bitfield.get_all()
);
}

#[test]
Expand Down

0 comments on commit 1cc9a1c

Please sign in to comment.