From c05226620f055ca798f676b119932d2f020bcee9 Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" <75863576+jeffwashington@users.noreply.github.com> Date: Mon, 13 Sep 2021 08:33:45 -0500 Subject: [PATCH] metrics on accounts index entry (#19806) --- runtime/src/bucket_map_holder_stats.rs | 24 ++++++++++++++++++++++++ runtime/src/in_mem_accounts_index.rs | 12 ++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/runtime/src/bucket_map_holder_stats.rs b/runtime/src/bucket_map_holder_stats.rs index 72e840d691..cd274ce472 100644 --- a/runtime/src/bucket_map_holder_stats.rs +++ b/runtime/src/bucket_map_holder_stats.rs @@ -7,6 +7,10 @@ pub struct BucketMapHolderStats { pub gets_from_mem: AtomicU64, pub get_missing_us: AtomicU64, pub gets_missing: AtomicU64, + pub entry_mem_us: AtomicU64, + pub entries_from_mem: AtomicU64, + pub entry_missing_us: AtomicU64, + pub entries_missing: AtomicU64, pub items: AtomicU64, pub keys: AtomicU64, pub deletes: AtomicU64, @@ -36,6 +40,26 @@ impl BucketMapHolderStats { self.get_missing_us.swap(0, Ordering::Relaxed) / 1000, i64 ), + ( + "entries_from_mem", + self.entries_from_mem.swap(0, Ordering::Relaxed), + i64 + ), + ( + "entry_mem_us", + self.entry_mem_us.swap(0, Ordering::Relaxed) / 1000, + i64 + ), + ( + "entries_missing", + self.entries_missing.swap(0, Ordering::Relaxed), + i64 + ), + ( + "entry_missing_us", + self.entry_missing_us.swap(0, Ordering::Relaxed) / 1000, + i64 + ), ("deletes", self.deletes.swap(0, Ordering::Relaxed), i64), ("items", self.items.swap(0, Ordering::Relaxed), i64), ("keys", self.keys.swap(0, Ordering::Relaxed), i64), diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 57ff30ac37..1f20b31e88 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -37,14 +37,14 @@ impl InMemAccountsIndex { Arc::new(BucketMapHolder::new()) } - pub fn entry(&mut self, pubkey: Pubkey) -> Entry> { + fn entry(&mut self, pubkey: Pubkey) -> Entry> { let m = Measure::start("entry"); let result = self.map.entry(pubkey); let stats = &self.storage.stats; let (count, time) = if matches!(result, Entry::Occupied(_)) { - (&stats.gets_from_mem, &stats.get_mem_us) + (&stats.entries_from_mem, &stats.entry_mem_us) } else { - (&stats.gets_missing, &stats.get_missing_us) + (&stats.entries_missing, &stats.entry_missing_us) }; Self::update_time_stat(time, m); Self::update_stat(count, 1); @@ -87,7 +87,7 @@ impl InMemAccountsIndex { // If the slot list for pubkey exists in the index and is empty, remove the index entry for pubkey and return true. // Return false otherwise. pub fn remove_if_slot_list_empty(&mut self, pubkey: Pubkey) -> bool { - if let Entry::Occupied(index_entry) = self.map.entry(pubkey) { + if let Entry::Occupied(index_entry) = self.entry(pubkey) { if index_entry.get().slot_list.read().unwrap().is_empty() { index_entry.remove(); return true; @@ -102,7 +102,7 @@ impl InMemAccountsIndex { reclaims: &mut SlotList, previous_slot_entry_was_cached: bool, ) { - match self.map.entry(*pubkey) { + match self.entry(*pubkey) { Entry::Occupied(mut occupied) => { let current = occupied.get_mut(); Self::lock_and_update_slot_list( @@ -212,7 +212,7 @@ impl InMemAccountsIndex { pubkey: Pubkey, new_entry: AccountMapEntry, ) -> Option<(WriteAccountMapEntry, T, Pubkey)> { - let account_entry = self.map.entry(pubkey); + let account_entry = self.entry(pubkey); match account_entry { Entry::Occupied(account_entry) => Some(( WriteAccountMapEntry::from_account_map_entry(account_entry.get().clone()),