Skip to content

Commit 1fc4e38

Browse files
add stats for write cache flushing (solana-labs#233)
* add stats for write cache flushing * some renames
1 parent cc3afa5 commit 1fc4e38

File tree

1 file changed

+49
-15
lines changed

1 file changed

+49
-15
lines changed

accounts-db/src/accounts_db.rs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,13 +1719,18 @@ struct FlushStats {
17191719
num_flushed: usize,
17201720
num_purged: usize,
17211721
total_size: u64,
1722+
store_accounts_timing: StoreAccountsTiming,
1723+
store_accounts_total_us: u64,
17221724
}
17231725

17241726
impl FlushStats {
17251727
fn accumulate(&mut self, other: &Self) {
17261728
saturating_add_assign!(self.num_flushed, other.num_flushed);
17271729
saturating_add_assign!(self.num_purged, other.num_purged);
17281730
saturating_add_assign!(self.total_size, other.total_size);
1731+
self.store_accounts_timing
1732+
.accumulate(&other.store_accounts_timing);
1733+
saturating_add_assign!(self.store_accounts_total_us, other.store_accounts_total_us);
17291734
}
17301735
}
17311736

@@ -6050,7 +6055,7 @@ impl AccountsDb {
60506055
// Note even if force_flush is false, we will still flush all roots <= the
60516056
// given `requested_flush_root`, even if some of the later roots cannot be used for
60526057
// cleaning due to an ongoing scan
6053-
let (total_new_cleaned_roots, num_cleaned_roots_flushed) = self
6058+
let (total_new_cleaned_roots, num_cleaned_roots_flushed, mut flush_stats) = self
60546059
.flush_rooted_accounts_cache(
60556060
requested_flush_root,
60566061
Some((&mut account_bytes_saved, &mut num_accounts_saved)),
@@ -6062,7 +6067,7 @@ impl AccountsDb {
60626067
// banks
60636068

60646069
// If 'should_aggressively_flush_cache', then flush the excess ones to storage
6065-
let (total_new_excess_roots, num_excess_roots_flushed) =
6070+
let (total_new_excess_roots, num_excess_roots_flushed, flush_stats_aggressively) =
60666071
if self.should_aggressively_flush_cache() {
60676072
// Start by flushing the roots
60686073
//
@@ -6071,8 +6076,9 @@ impl AccountsDb {
60716076
// for `should_clean`.
60726077
self.flush_rooted_accounts_cache(None, None)
60736078
} else {
6074-
(0, 0)
6079+
(0, 0, FlushStats::default())
60756080
};
6081+
flush_stats.accumulate(&flush_stats_aggressively);
60766082

60776083
let mut excess_slot_count = 0;
60786084
let mut unflushable_unrooted_slot_count = 0;
@@ -6123,14 +6129,34 @@ impl AccountsDb {
61236129
),
61246130
("account_bytes_saved", account_bytes_saved, i64),
61256131
("num_accounts_saved", num_accounts_saved, i64),
6132+
(
6133+
"store_accounts_total_us",
6134+
flush_stats.store_accounts_total_us,
6135+
i64
6136+
),
6137+
(
6138+
"update_index_us",
6139+
flush_stats.store_accounts_timing.update_index_elapsed,
6140+
i64
6141+
),
6142+
(
6143+
"store_accounts_elapsed_us",
6144+
flush_stats.store_accounts_timing.store_accounts_elapsed,
6145+
i64
6146+
),
6147+
(
6148+
"handle_reclaims_elapsed_us",
6149+
flush_stats.store_accounts_timing.handle_reclaims_elapsed,
6150+
i64
6151+
),
61266152
);
61276153
}
61286154

61296155
fn flush_rooted_accounts_cache(
61306156
&self,
61316157
requested_flush_root: Option<Slot>,
61326158
should_clean: Option<(&mut usize, &mut usize)>,
6133-
) -> (usize, usize) {
6159+
) -> (usize, usize, FlushStats) {
61346160
let max_clean_root = should_clean.as_ref().and_then(|_| {
61356161
// If there is a long running scan going on, this could prevent any cleaning
61366162
// based on updates from slots > `max_clean_root`.
@@ -6161,12 +6187,13 @@ impl AccountsDb {
61616187
// Iterate from highest to lowest so that we don't need to flush earlier
61626188
// outdated updates in earlier roots
61636189
let mut num_roots_flushed = 0;
6190+
let mut flush_stats = FlushStats::default();
61646191
for &root in cached_roots.iter().rev() {
6165-
if self
6166-
.flush_slot_cache_with_clean(root, should_flush_f.as_mut(), max_clean_root)
6167-
.is_some()
6192+
if let Some(stats) =
6193+
self.flush_slot_cache_with_clean(root, should_flush_f.as_mut(), max_clean_root)
61686194
{
61696195
num_roots_flushed += 1;
6196+
flush_stats.accumulate(&stats);
61706197
}
61716198

61726199
// Regardless of whether this slot was *just* flushed from the cache by the above
@@ -6183,7 +6210,7 @@ impl AccountsDb {
61836210
// so that clean will actually be able to clean the slots.
61846211
let num_new_roots = cached_roots.len();
61856212
self.accounts_index.add_uncleaned_roots(cached_roots);
6186-
(num_new_roots, num_roots_flushed)
6213+
(num_new_roots, num_roots_flushed, flush_stats)
61876214
}
61886215

61896216
fn do_flush_slot_cache(
@@ -6246,18 +6273,23 @@ impl AccountsDb {
62466273
&HashSet::default(),
62476274
);
62486275

6276+
let mut store_accounts_timing = StoreAccountsTiming::default();
6277+
let mut store_accounts_total_us = 0;
62496278
if !is_dead_slot {
62506279
// This ensures that all updates are written to an AppendVec, before any
62516280
// updates to the index happen, so anybody that sees a real entry in the index,
62526281
// will be able to find the account in storage
62536282
let flushed_store = self.create_and_insert_store(slot, total_size, "flush_slot_cache");
6254-
self.store_accounts_frozen(
6255-
(slot, &accounts[..]),
6256-
Some(hashes),
6257-
&flushed_store,
6258-
None,
6259-
StoreReclaims::Default,
6260-
);
6283+
let (store_accounts_timing_inner, store_accounts_total_inner_us) = measure_us!(self
6284+
.store_accounts_frozen(
6285+
(slot, &accounts[..]),
6286+
Some(hashes),
6287+
&flushed_store,
6288+
None,
6289+
StoreReclaims::Default,
6290+
));
6291+
store_accounts_timing = store_accounts_timing_inner;
6292+
store_accounts_total_us = store_accounts_total_inner_us;
62616293

62626294
// If the above sizing function is correct, just one AppendVec is enough to hold
62636295
// all the data for the slot
@@ -6273,6 +6305,8 @@ impl AccountsDb {
62736305
num_flushed,
62746306
num_purged,
62756307
total_size,
6308+
store_accounts_timing,
6309+
store_accounts_total_us,
62766310
}
62776311
}
62786312

0 commit comments

Comments
 (0)