AcctIdx: stats are usize (#21493)
* AcctIdx: stats are usize * rename test function
This commit is contained in:
parent
38fcfb7542
commit
7ec88226ee
@ -6921,10 +6921,10 @@ impl AccountsDb {
|
|||||||
.account_maps
|
.account_maps
|
||||||
.iter()
|
.iter()
|
||||||
.map(|map_bin| {
|
.map(|map_bin| {
|
||||||
let len = map_bin.read().unwrap().len();
|
let len = map_bin.read().unwrap().len_for_stats();
|
||||||
min_bin_size = std::cmp::min(min_bin_size, len);
|
min_bin_size = std::cmp::min(min_bin_size, len);
|
||||||
max_bin_size = std::cmp::max(max_bin_size, len);
|
max_bin_size = std::cmp::max(max_bin_size, len);
|
||||||
len
|
len as usize
|
||||||
})
|
})
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
|
@ -3052,10 +3052,10 @@ pub mod tests {
|
|||||||
|
|
||||||
let new_entry =
|
let new_entry =
|
||||||
PreAllocatedAccountMapEntry::new(slot, account_info, &index.storage.storage, false);
|
PreAllocatedAccountMapEntry::new(slot, account_info, &index.storage.storage, false);
|
||||||
assert_eq!(0, account_maps_len_expensive(&index));
|
assert_eq!(0, account_maps_stats_len(&index));
|
||||||
assert_eq!((slot, account_info), new_entry.clone().into());
|
assert_eq!((slot, account_info), new_entry.clone().into());
|
||||||
|
|
||||||
assert_eq!(0, account_maps_len_expensive(&index));
|
assert_eq!(0, account_maps_stats_len(&index));
|
||||||
let w_account_maps = index.get_account_maps_write_lock(&key.pubkey());
|
let w_account_maps = index.get_account_maps_write_lock(&key.pubkey());
|
||||||
w_account_maps.upsert(
|
w_account_maps.upsert(
|
||||||
&key.pubkey(),
|
&key.pubkey(),
|
||||||
@ -3064,7 +3064,7 @@ pub mod tests {
|
|||||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||||
);
|
);
|
||||||
drop(w_account_maps);
|
drop(w_account_maps);
|
||||||
assert_eq!(1, account_maps_len_expensive(&index));
|
assert_eq!(1, account_maps_stats_len(&index));
|
||||||
|
|
||||||
let mut ancestors = Ancestors::default();
|
let mut ancestors = Ancestors::default();
|
||||||
assert!(index.get(&key.pubkey(), Some(&ancestors), None).is_none());
|
assert!(index.get(&key.pubkey(), Some(&ancestors), None).is_none());
|
||||||
@ -3615,12 +3615,8 @@ pub mod tests {
|
|||||||
assert!(found_key);
|
assert!(found_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn account_maps_len_expensive<T: IndexValue>(index: &AccountsIndex<T>) -> usize {
|
fn account_maps_stats_len<T: IndexValue>(index: &AccountsIndex<T>) -> usize {
|
||||||
index
|
index.storage.storage.stats.total_count()
|
||||||
.account_maps
|
|
||||||
.iter()
|
|
||||||
.map(|bin_map| bin_map.read().unwrap().len())
|
|
||||||
.sum()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -3628,7 +3624,7 @@ pub mod tests {
|
|||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let index = AccountsIndex::<u64>::default_for_tests();
|
let index = AccountsIndex::<u64>::default_for_tests();
|
||||||
let mut gc = Vec::new();
|
let mut gc = Vec::new();
|
||||||
assert_eq!(0, account_maps_len_expensive(&index));
|
assert_eq!(0, account_maps_stats_len(&index));
|
||||||
index.upsert(
|
index.upsert(
|
||||||
1,
|
1,
|
||||||
&key.pubkey(),
|
&key.pubkey(),
|
||||||
@ -3639,7 +3635,7 @@ pub mod tests {
|
|||||||
&mut gc,
|
&mut gc,
|
||||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||||
);
|
);
|
||||||
assert_eq!(1, account_maps_len_expensive(&index));
|
assert_eq!(1, account_maps_stats_len(&index));
|
||||||
|
|
||||||
index.upsert(
|
index.upsert(
|
||||||
1,
|
1,
|
||||||
@ -3651,7 +3647,7 @@ pub mod tests {
|
|||||||
&mut gc,
|
&mut gc,
|
||||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||||
);
|
);
|
||||||
assert_eq!(1, account_maps_len_expensive(&index));
|
assert_eq!(1, account_maps_stats_len(&index));
|
||||||
|
|
||||||
let purges = index.purge_roots(&key.pubkey());
|
let purges = index.purge_roots(&key.pubkey());
|
||||||
assert_eq!(purges, (vec![], false));
|
assert_eq!(purges, (vec![], false));
|
||||||
@ -3660,7 +3656,7 @@ pub mod tests {
|
|||||||
let purges = index.purge_roots(&key.pubkey());
|
let purges = index.purge_roots(&key.pubkey());
|
||||||
assert_eq!(purges, (vec![(1, 10)], true));
|
assert_eq!(purges, (vec![(1, 10)], true));
|
||||||
|
|
||||||
assert_eq!(1, account_maps_len_expensive(&index));
|
assert_eq!(1, account_maps_stats_len(&index));
|
||||||
index.upsert(
|
index.upsert(
|
||||||
1,
|
1,
|
||||||
&key.pubkey(),
|
&key.pubkey(),
|
||||||
@ -3671,7 +3667,7 @@ pub mod tests {
|
|||||||
&mut gc,
|
&mut gc,
|
||||||
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
|
||||||
);
|
);
|
||||||
assert_eq!(1, account_maps_len_expensive(&index));
|
assert_eq!(1, account_maps_stats_len(&index));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -2,7 +2,7 @@ use crate::accounts_index::IndexValue;
|
|||||||
use crate::bucket_map_holder::BucketMapHolder;
|
use crate::bucket_map_holder::BucketMapHolder;
|
||||||
use solana_sdk::timing::AtomicInterval;
|
use solana_sdk::timing::AtomicInterval;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicU64, AtomicU8, AtomicUsize, Ordering};
|
||||||
|
|
||||||
// stats logged every 10 s
|
// stats logged every 10 s
|
||||||
const STATS_INTERVAL_MS: u64 = 10_000;
|
const STATS_INTERVAL_MS: u64 = 10_000;
|
||||||
@ -28,11 +28,11 @@ pub struct BucketMapHolderStats {
|
|||||||
pub keys: AtomicU64,
|
pub keys: AtomicU64,
|
||||||
pub deletes: AtomicU64,
|
pub deletes: AtomicU64,
|
||||||
pub inserts: AtomicU64,
|
pub inserts: AtomicU64,
|
||||||
count: AtomicU64,
|
count: AtomicUsize,
|
||||||
pub bg_waiting_us: AtomicU64,
|
pub bg_waiting_us: AtomicU64,
|
||||||
pub bg_throttling_wait_us: AtomicU64,
|
pub bg_throttling_wait_us: AtomicU64,
|
||||||
pub count_in_mem: AtomicU64,
|
pub count_in_mem: AtomicUsize,
|
||||||
pub per_bucket_count: Vec<AtomicU64>,
|
pub per_bucket_count: Vec<AtomicUsize>,
|
||||||
pub flush_entries_updated_on_disk: AtomicU64,
|
pub flush_entries_updated_on_disk: AtomicU64,
|
||||||
pub flush_entries_removed_from_mem: AtomicU64,
|
pub flush_entries_removed_from_mem: AtomicU64,
|
||||||
pub active_threads: AtomicU64,
|
pub active_threads: AtomicU64,
|
||||||
@ -53,7 +53,7 @@ impl BucketMapHolderStats {
|
|||||||
bins: bins as u64,
|
bins: bins as u64,
|
||||||
per_bucket_count: (0..bins)
|
per_bucket_count: (0..bins)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|_| AtomicU64::default())
|
.map(|_| AtomicUsize::default())
|
||||||
.collect(),
|
.collect(),
|
||||||
..BucketMapHolderStats::default()
|
..BucketMapHolderStats::default()
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ impl BucketMapHolderStats {
|
|||||||
self.insert_or_delete_mem_count(insert, bin, 1)
|
self.insert_or_delete_mem_count(insert, bin, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_or_delete_mem_count(&self, insert: bool, bin: usize, count: u64) {
|
pub fn insert_or_delete_mem_count(&self, insert: bool, bin: usize, count: usize) {
|
||||||
let per_bucket = self.per_bucket_count.get(bin);
|
let per_bucket = self.per_bucket_count.get(bin);
|
||||||
if insert {
|
if insert {
|
||||||
self.count_in_mem.fetch_add(count, Ordering::Relaxed);
|
self.count_in_mem.fetch_add(count, Ordering::Relaxed);
|
||||||
@ -113,7 +113,7 @@ impl BucketMapHolderStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// return min, max, sum, median of data
|
/// return min, max, sum, median of data
|
||||||
fn get_stats(mut data: Vec<u64>) -> (u64, u64, u64, u64) {
|
fn get_stats(mut data: Vec<usize>) -> (usize, usize, usize, usize) {
|
||||||
if data.is_empty() {
|
if data.is_empty() {
|
||||||
(0, 0, 0, 0)
|
(0, 0, 0, 0)
|
||||||
} else {
|
} else {
|
||||||
@ -135,6 +135,18 @@ impl BucketMapHolderStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn total_count(&self) -> usize {
|
||||||
|
self.count.load(Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn count_in_bucket(&self, bucket: usize) -> usize {
|
||||||
|
if bucket < self.per_bucket_count.len() {
|
||||||
|
self.per_bucket_count[bucket].load(Ordering::Relaxed)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn report_stats<T: IndexValue>(&self, storage: &BucketMapHolder<T>) {
|
pub fn report_stats<T: IndexValue>(&self, storage: &BucketMapHolder<T>) {
|
||||||
let elapsed_ms = self.last_time.elapsed_ms();
|
let elapsed_ms = self.last_time.elapsed_ms();
|
||||||
if elapsed_ms < STATS_INTERVAL_MS {
|
if elapsed_ms < STATS_INTERVAL_MS {
|
||||||
@ -158,7 +170,7 @@ impl BucketMapHolderStats {
|
|||||||
disk.stats
|
disk.stats
|
||||||
.per_bucket_count
|
.per_bucket_count
|
||||||
.iter()
|
.iter()
|
||||||
.map(|count| count.load(Ordering::Relaxed))
|
.map(|count| count.load(Ordering::Relaxed) as usize)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
@ -186,7 +198,7 @@ impl BucketMapHolderStats {
|
|||||||
self.count_in_mem.load(Ordering::Relaxed),
|
self.count_in_mem.load(Ordering::Relaxed),
|
||||||
i64
|
i64
|
||||||
),
|
),
|
||||||
("count", self.count.load(Ordering::Relaxed), i64),
|
("count", self.total_count(), i64),
|
||||||
(
|
(
|
||||||
"bg_waiting_percent",
|
"bg_waiting_percent",
|
||||||
Self::calc_percent(
|
Self::calc_percent(
|
||||||
@ -424,7 +436,7 @@ impl BucketMapHolderStats {
|
|||||||
self.count_in_mem.load(Ordering::Relaxed),
|
self.count_in_mem.load(Ordering::Relaxed),
|
||||||
i64
|
i64
|
||||||
),
|
),
|
||||||
("count", self.count.load(Ordering::Relaxed), i64),
|
("count", self.total_count(), i64),
|
||||||
(
|
(
|
||||||
"bg_waiting_percent",
|
"bg_waiting_percent",
|
||||||
Self::calc_percent(
|
Self::calc_percent(
|
||||||
|
@ -463,12 +463,8 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn len_for_stats(&self) -> usize {
|
||||||
self.map().read().unwrap().len()
|
self.stats().count_in_bucket(self.bin)
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
|
||||||
self.len() == 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_returner(
|
fn insert_returner(
|
||||||
@ -880,12 +876,12 @@ impl<T: IndexValue> InMemAccountsIndex<T> {
|
|||||||
}
|
}
|
||||||
self.stats()
|
self.stats()
|
||||||
.insert_or_delete_mem_count(false, self.bin, removed);
|
.insert_or_delete_mem_count(false, self.bin, removed);
|
||||||
Self::update_stat(&self.stats().flush_entries_removed_from_mem, removed);
|
Self::update_stat(&self.stats().flush_entries_removed_from_mem, removed as u64);
|
||||||
|
|
||||||
completed_scan
|
completed_scan
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stats(&self) -> &BucketMapHolderStats {
|
pub fn stats(&self) -> &BucketMapHolderStats {
|
||||||
&self.storage.stats
|
&self.storage.stats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user