Skip to content

Commit

Permalink
metric: report estimated_mem_bytes for in-mem index (#2898)
Browse files Browse the repository at this point in the history
* report estimated_mem_bytes

* pr feedback

* Update accounts-db/src/accounts_index/in_mem_accounts_index.rs

Co-authored-by: Brooks <brooks@prumo.org>

---------

Co-authored-by: HaoranYi <haoran.yi@anza.xyz>
Co-authored-by: Brooks <brooks@prumo.org>
  • Loading branch information
3 people committed Sep 12, 2024
1 parent fc4069a commit 3f2a4ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions accounts-db/src/accounts_index/in_mem_accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,13 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> InMemAccountsIndex<T,
thread_rng().gen_range(0..N) == 0
}

/// assumes 1 entry in the slot list. Ignores overhead of the HashMap and such
pub const fn approx_size_of_one_entry() -> usize {
std::mem::size_of::<T>()
+ std::mem::size_of::<Pubkey>()
+ std::mem::size_of::<AccountMapEntry<T>>()
}

fn should_evict_based_on_age(
current_age: Age,
entry: &AccountMapEntry<T>,
Expand Down
6 changes: 3 additions & 3 deletions accounts-db/src/bucket_map_holder_stats.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::{
accounts_index::{DiskIndexValue, IndexValue},
accounts_index::{in_mem_accounts_index::InMemAccountsIndex, DiskIndexValue, IndexValue},
bucket_map_holder::{Age, AtomicAge, BucketMapHolder},
},
solana_sdk::timing::AtomicInterval,
Expand Down Expand Up @@ -61,7 +61,6 @@ pub struct BucketMapHolderStats {
last_was_startup: AtomicBool,
last_time: AtomicInterval,
bins: u64,
pub estimate_mem: AtomicU64,
pub flush_should_evict_us: AtomicU64,
}

Expand Down Expand Up @@ -263,7 +262,8 @@ impl BucketMapHolderStats {
},
(
"estimate_mem_bytes",
self.estimate_mem.load(Ordering::Relaxed),
self.count_in_mem.load(Ordering::Relaxed)
* InMemAccountsIndex::<T, U>::approx_size_of_one_entry(),
i64
),
(
Expand Down

0 comments on commit 3f2a4ae

Please sign in to comment.