Skip to content

Commit 1805924

Browse files
authored
clean up shrink candidate stat (solana-labs#3037)
rework shrink select stat Co-authored-by: HaoranYi <[email protected]>
1 parent d940e77 commit 1805924

File tree

1 file changed

+31
-48
lines changed

1 file changed

+31
-48
lines changed

accounts-db/src/accounts_db.rs

+31-48
Original file line numberDiff line numberDiff line change
@@ -4576,17 +4576,13 @@ impl AccountsDb {
45764576
alive_ratio: f64,
45774577
store: Arc<AccountStorageEntry>,
45784578
}
4579-
let mut measure = Measure::start("select_top_sparse_storage_entries-ms");
45804579
let mut store_usage: Vec<StoreUsageInfo> = Vec::with_capacity(shrink_slots.len());
45814580
let mut total_alive_bytes: u64 = 0;
4582-
let mut candidates_count: usize = 0;
45834581
let mut total_bytes: u64 = 0;
4584-
let mut total_candidate_stores: usize = 0;
45854582
for slot in shrink_slots {
45864583
let Some(store) = self.storage.get_slot_storage_entry(*slot) else {
45874584
continue;
45884585
};
4589-
candidates_count += 1;
45904586
let alive_bytes = store.alive_bytes();
45914587
total_alive_bytes += alive_bytes as u64;
45924588
total_bytes += store.capacity();
@@ -4596,7 +4592,6 @@ impl AccountsDb {
45964592
alive_ratio,
45974593
store: store.clone(),
45984594
});
4599-
total_candidate_stores += 1;
46004595
}
46014596
store_usage.sort_by(|a, b| {
46024597
a.alive_ratio
@@ -4633,20 +4628,6 @@ impl AccountsDb {
46334628
shrink_slots.insert(usage.slot, Arc::clone(store));
46344629
}
46354630
}
4636-
measure.stop();
4637-
inc_new_counter_debug!(
4638-
"shrink_select_top_sparse_storage_entries-ms",
4639-
measure.as_ms() as usize
4640-
);
4641-
inc_new_counter_debug!(
4642-
"shrink_select_top_sparse_storage_entries-seeds",
4643-
candidates_count
4644-
);
4645-
inc_new_counter_debug!(
4646-
"shrink_total_preliminary_candidate_stores",
4647-
total_candidate_stores
4648-
);
4649-
46504631
(shrink_slots, shrink_slots_next_batch)
46514632
}
46524633

@@ -5050,8 +5031,8 @@ impl AccountsDb {
50505031

50515032
let shrink_candidates_slots =
50525033
std::mem::take(&mut *self.shrink_candidate_slots.lock().unwrap());
5053-
5054-
let (shrink_slots, shrink_slots_next_batch) = {
5034+
let candidates_count = shrink_candidates_slots.len();
5035+
let ((shrink_slots, shrink_slots_next_batch), select_time_us) = measure_us!({
50555036
if let AccountShrinkThreshold::TotalSpace { shrink_ratio } = self.shrink_ratio {
50565037
let (shrink_slots, shrink_slots_next_batch) =
50575038
self.select_candidates_by_total_usage(&shrink_candidates_slots, shrink_ratio);
@@ -5070,7 +5051,7 @@ impl AccountsDb {
50705051
None,
50715052
)
50725053
}
5073-
};
5054+
});
50745055

50755056
if shrink_slots.is_empty()
50765057
&& shrink_slots_next_batch
@@ -5084,41 +5065,43 @@ impl AccountsDb {
50845065
let _guard = (!shrink_slots.is_empty())
50855066
.then_some(|| self.active_stats.activate(ActiveStatItem::Shrink));
50865067

5087-
let mut measure_shrink_all_candidates = Measure::start("shrink_all_candidate_slots-ms");
5088-
let num_candidates = shrink_slots.len();
5089-
let shrink_candidates_count = shrink_slots.len();
5090-
self.thread_pool_clean.install(|| {
5091-
shrink_slots
5092-
.into_par_iter()
5093-
.for_each(|(slot, slot_shrink_candidate)| {
5094-
if self.ancient_append_vec_offset.is_some() && slot < oldest_non_ancient_slot {
5095-
self.shrink_stats
5096-
.num_ancient_slots_shrunk
5097-
.fetch_add(1, Ordering::Relaxed);
5098-
}
5099-
let mut measure = Measure::start("shrink_candidate_slots-ms");
5100-
self.shrink_storage(&slot_shrink_candidate);
5101-
measure.stop();
5102-
inc_new_counter_info!("shrink_candidate_slots-ms", measure.as_ms() as usize);
5103-
});
5068+
let num_selected = shrink_slots.len();
5069+
let (_, shrink_all_us) = measure_us!({
5070+
self.thread_pool_clean.install(|| {
5071+
shrink_slots
5072+
.into_par_iter()
5073+
.for_each(|(slot, slot_shrink_candidate)| {
5074+
if self.ancient_append_vec_offset.is_some()
5075+
&& slot < oldest_non_ancient_slot
5076+
{
5077+
self.shrink_stats
5078+
.num_ancient_slots_shrunk
5079+
.fetch_add(1, Ordering::Relaxed);
5080+
}
5081+
self.shrink_storage(&slot_shrink_candidate);
5082+
});
5083+
})
51045084
});
5105-
measure_shrink_all_candidates.stop();
5106-
inc_new_counter_info!(
5107-
"shrink_all_candidate_slots-ms",
5108-
measure_shrink_all_candidates.as_ms() as usize
5109-
);
5110-
inc_new_counter_info!("shrink_all_candidate_slots-count", shrink_candidates_count);
5085+
51115086
let mut pended_counts: usize = 0;
51125087
if let Some(shrink_slots_next_batch) = shrink_slots_next_batch {
51135088
let mut shrink_slots = self.shrink_candidate_slots.lock().unwrap();
5114-
pended_counts += shrink_slots_next_batch.len();
5089+
pended_counts = shrink_slots_next_batch.len();
51155090
for slot in shrink_slots_next_batch {
51165091
shrink_slots.insert(slot);
51175092
}
51185093
}
5119-
inc_new_counter_info!("shrink_pended_stores-count", pended_counts);
51205094

5121-
num_candidates
5095+
datapoint_info!(
5096+
"shrink_candidate_slots",
5097+
("select_time_us", select_time_us, i64),
5098+
("shrink_all_us", shrink_all_us, i64),
5099+
("candidates_count", candidates_count, i64),
5100+
("selected_count", num_selected, i64),
5101+
("deferred_to_next_round_count", pended_counts, i64)
5102+
);
5103+
5104+
num_selected
51225105
}
51235106

51245107
/// This is only called at startup from bank when we are being extra careful such as when we downloaded a snapshot.

0 commit comments

Comments
 (0)