From 3a46f45650b0ccc62e5fac50307e807d506eb7cd Mon Sep 17 00:00:00 2001 From: "Jeff Washington (jwash)" Date: Thu, 17 Mar 2022 08:46:00 -0500 Subject: [PATCH] AcctIdx: add stats for flushing and estimated memory (#23709) --- runtime/src/bucket_map_holder_stats.rs | 12 ++++++++++++ runtime/src/in_mem_accounts_index.rs | 12 +++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/runtime/src/bucket_map_holder_stats.rs b/runtime/src/bucket_map_holder_stats.rs index 18a3a088ec..69cbd1460e 100644 --- a/runtime/src/bucket_map_holder_stats.rs +++ b/runtime/src/bucket_map_holder_stats.rs @@ -49,6 +49,8 @@ pub struct BucketMapHolderStats { last_was_startup: AtomicBool, last_time: AtomicInterval, bins: u64, + pub estimate_mem: AtomicU64, + pub flush_should_evict_us: AtomicU64, } impl BucketMapHolderStats { @@ -196,6 +198,16 @@ impl BucketMapHolderStats { } else { "accounts_index" }, + ( + "estimate_mem_bytes", + self.estimate_mem.load(Ordering::Relaxed), + i64 + ), + ( + "flush_should_evict_us", + self.flush_should_evict_us.swap(0, Ordering::Relaxed), + i64 + ), ( "count_in_mem", self.count_in_mem.load(Ordering::Relaxed), diff --git a/runtime/src/in_mem_accounts_index.rs b/runtime/src/in_mem_accounts_index.rs index 29c91e971e..cb93535170 100644 --- a/runtime/src/in_mem_accounts_index.rs +++ b/runtime/src/in_mem_accounts_index.rs @@ -941,9 +941,13 @@ impl InMemAccountsIndex { let in_mem_count = self.stats().count_in_mem.load(Ordering::Relaxed); let limit = self.storage.mem_budget_mb; + let estimate_mem = in_mem_count * Self::approx_size_of_one_entry(); let exceeds_budget = limit - .map(|limit| in_mem_count * Self::approx_size_of_one_entry() >= limit * 1024 * 1024) + .map(|limit| estimate_mem >= limit * 1024 * 1024) .unwrap_or_default(); + self.stats() + .estimate_mem + .store(estimate_mem as u64, Ordering::Relaxed); // may have to loop if disk has to grow and we have to restart loop { @@ -953,6 +957,7 @@ impl InMemAccountsIndex { let mut flush_entries_updated_on_disk = 0; let mut disk_resize = Ok(()); + let mut flush_should_evict_us = 0; // scan and update loop // holds read lock { @@ -960,8 +965,11 @@ impl InMemAccountsIndex { evictions = Vec::with_capacity(map.len()); let m = Measure::start("flush_scan_and_update"); // we don't care about lock time in this metric - bg threads can wait for (k, v) in map.iter() { + let mut mse = Measure::start("flush_should_evict"); let (evict_for_age, slot_list) = self.should_evict_from_mem(current_age, v, startup, true, exceeds_budget); + mse.stop(); + flush_should_evict_us += mse.as_us(); if !evict_for_age && !Self::random_chance_of_eviction() { // not planning to remove this item from memory now, so don't write it to disk yet continue; @@ -999,6 +1007,8 @@ impl InMemAccountsIndex { } Self::update_time_stat(&self.stats().flush_scan_update_us, m); } + Self::update_stat(&self.stats().flush_should_evict_us, flush_should_evict_us); + Self::update_stat( &self.stats().flush_entries_updated_on_disk, flush_entries_updated_on_disk,