move around some index metrics to reduce locks (#24161)

This commit is contained in:
Jeff Washington (jwash)
2022-04-07 09:43:19 -05:00
committed by GitHub
parent 42c094739d
commit f7b2951c79

View File

@ -185,25 +185,33 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
pubkey: &K, pubkey: &K,
callback: impl for<'a> FnOnce(Option<&'a AccountMapEntry<T>>) -> RT, callback: impl for<'a> FnOnce(Option<&'a AccountMapEntry<T>>) -> RT,
) -> RT { ) -> RT {
let m = Measure::start("get"); let mut found = true;
let mut m = Measure::start("get");
let result = {
let map = self.map().read().unwrap(); let map = self.map().read().unwrap();
let result = map.get(pubkey); let result = map.get(pubkey);
let stats = self.stats(); m.stop();
let (count, time) = if result.is_some() {
(&stats.gets_from_mem, &stats.get_mem_us)
} else {
(&stats.gets_missing, &stats.get_missing_us)
};
Self::update_time_stat(time, m);
Self::update_stat(count, 1);
callback(if let Some(entry) = result { callback(if let Some(entry) = result {
entry.set_age(self.storage.future_age_to_flush()); entry.set_age(self.storage.future_age_to_flush());
Some(entry) Some(entry)
} else { } else {
drop(map); drop(map);
found = false;
None None
}) })
};
let stats = self.stats();
let (count, time) = if found {
(&stats.gets_from_mem, &stats.get_mem_us)
} else {
(&stats.gets_missing, &stats.get_missing_us)
};
Self::update_stat(time, m.as_us());
Self::update_stat(count, 1);
result
} }
/// lookup 'pubkey' in index (in mem or on disk) /// lookup 'pubkey' in index (in mem or on disk)
@ -352,6 +360,7 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
reclaims: &mut SlotList<T>, reclaims: &mut SlotList<T>,
previous_slot_entry_was_cached: bool, previous_slot_entry_was_cached: bool,
) { ) {
let mut updated_in_mem = true;
// try to get it just from memory first using only a read lock // try to get it just from memory first using only a read lock
self.get_only_in_mem(pubkey, |entry| { self.get_only_in_mem(pubkey, |entry| {
if let Some(entry) = entry { if let Some(entry) = entry {
@ -362,7 +371,7 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
reclaims, reclaims,
previous_slot_entry_was_cached, previous_slot_entry_was_cached,
); );
Self::update_stat(&self.stats().updates_in_mem, 1); // age is incremented by caller
} else { } else {
let mut m = Measure::start("entry"); let mut m = Measure::start("entry");
let mut map = self.map().write().unwrap(); let mut map = self.map().write().unwrap();
@ -380,10 +389,10 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
previous_slot_entry_was_cached, previous_slot_entry_was_cached,
); );
current.set_age(self.storage.future_age_to_flush()); current.set_age(self.storage.future_age_to_flush());
Self::update_stat(&self.stats().updates_in_mem, 1);
} }
Entry::Vacant(vacant) => { Entry::Vacant(vacant) => {
// not in cache, look on disk // not in cache, look on disk
updated_in_mem = false;
// desired to be this for filler accounts: self.storage.get_startup(); // desired to be this for filler accounts: self.storage.get_startup();
// but, this has proven to be far too slow at high account counts // but, this has proven to be far too slow at high account counts
@ -430,7 +439,10 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
drop(map); drop(map);
self.update_entry_stats(m, found); self.update_entry_stats(m, found);
}; };
}) });
if updated_in_mem {
Self::update_stat(&self.stats().updates_in_mem, 1);
}
} }
fn update_entry_stats(&self, stopped_measure: Measure, found: bool) { fn update_entry_stats(&self, stopped_measure: Measure, found: bool) {