Skip to content

Commit

Permalink
parallelize dirty store key insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
bw-solana committed Aug 19, 2022
1 parent b3c72bc commit 29ec1c7
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,7 @@ impl AccountsDb {
fn construct_candidate_clean_keys(
&self,
max_clean_root: Option<Slot>,
is_startup: bool,
last_full_snapshot_slot: Option<Slot>,
timings: &mut CleanKeyTimings,
) -> Vec<Pubkey> {
Expand All @@ -2447,11 +2448,33 @@ impl AccountsDb {
});
let dirty_stores_len = dirty_stores.len();
let pubkeys = DashSet::new();
timings.oldest_dirty_slot = max_slot.saturating_add(1);
for (slot, store) in dirty_stores {
timings.oldest_dirty_slot = std::cmp::min(timings.oldest_dirty_slot, slot);
store.accounts.account_iter().for_each(|account| {
pubkeys.insert(account.meta.pubkey);
let mut dirty_store_routine = || {
let chunk_size = 1.max(dirty_stores_len.saturating_div(rayon::current_num_threads()));
let oldest_dirty_slots: Vec<u64> = dirty_stores
.par_chunks(chunk_size)
.map(|dirty_store_chunk| {
let mut oldest_dirty_slot = max_slot.saturating_add(1);
dirty_store_chunk.iter().for_each(|(slot, store)| {
oldest_dirty_slot = oldest_dirty_slot.min(*slot);
store.accounts.account_iter().for_each(|account| {
pubkeys.insert(account.meta.pubkey);
});
});
oldest_dirty_slot
})
.collect();
timings.oldest_dirty_slot = *oldest_dirty_slots
.iter()
.min()
.unwrap_or(&max_slot.saturating_add(1));
};

if is_startup {
// Free to consume all the cores during startup
dirty_store_routine();
} else {
self.thread_pool_clean.install(|| {
dirty_store_routine();
});
}
trace!(
Expand Down Expand Up @@ -2538,6 +2561,7 @@ impl AccountsDb {
let mut key_timings = CleanKeyTimings::default();
let mut pubkeys = self.construct_candidate_clean_keys(
max_clean_root,
is_startup,
last_full_snapshot_slot,
&mut key_timings,
);
Expand Down

0 comments on commit 29ec1c7

Please sign in to comment.