Shrink slots by sparseness of written data size (#14072)
This commit is contained in:
parent
9f2d154588
commit
5788e75188
|
@ -257,10 +257,15 @@ impl AccountsBackgroundService {
|
||||||
assert!(last_cleaned_block_height <= snapshot_block_height);
|
assert!(last_cleaned_block_height <= snapshot_block_height);
|
||||||
last_cleaned_block_height = snapshot_block_height;
|
last_cleaned_block_height = snapshot_block_height;
|
||||||
} else {
|
} else {
|
||||||
consumed_budget = bank.process_stale_slot_with_budget(
|
// under sustained writes, shrink can lag behind so cap to
|
||||||
consumed_budget,
|
// SHRUNKEN_ACCOUNT_PER_INTERVAL (which is based on INTERVAL_MS,
|
||||||
SHRUNKEN_ACCOUNT_PER_INTERVAL,
|
// which in turn roughly asscociated block time)
|
||||||
);
|
consumed_budget = bank
|
||||||
|
.process_stale_slot_with_budget(
|
||||||
|
consumed_budget,
|
||||||
|
SHRUNKEN_ACCOUNT_PER_INTERVAL,
|
||||||
|
)
|
||||||
|
.min(SHRUNKEN_ACCOUNT_PER_INTERVAL);
|
||||||
|
|
||||||
if bank.block_height() - last_cleaned_block_height
|
if bank.block_height() - last_cleaned_block_height
|
||||||
> (CLEAN_INTERVAL_BLOCKS + thread_rng().gen_range(0, 10))
|
> (CLEAN_INTERVAL_BLOCKS + thread_rng().gen_range(0, 10))
|
||||||
|
|
|
@ -266,6 +266,14 @@ impl AccountStorageEntry {
|
||||||
self.approx_store_count.load(Ordering::Relaxed)
|
self.approx_store_count.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn written_bytes(&self) -> u64 {
|
||||||
|
self.accounts.len() as u64
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn total_bytes(&self) -> u64 {
|
||||||
|
self.accounts.capacity()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn has_accounts(&self) -> bool {
|
pub fn has_accounts(&self) -> bool {
|
||||||
self.count() > 0
|
self.count() > 0
|
||||||
}
|
}
|
||||||
|
@ -1019,9 +1027,13 @@ impl AccountsDB {
|
||||||
let stores = stores_lock.read().unwrap();
|
let stores = stores_lock.read().unwrap();
|
||||||
let mut alive_count = 0;
|
let mut alive_count = 0;
|
||||||
let mut stored_count = 0;
|
let mut stored_count = 0;
|
||||||
|
let mut written_bytes = 0;
|
||||||
|
let mut total_bytes = 0;
|
||||||
for store in stores.values() {
|
for store in stores.values() {
|
||||||
alive_count += store.count();
|
alive_count += store.count();
|
||||||
stored_count += store.approx_stored_count();
|
stored_count += store.approx_stored_count();
|
||||||
|
written_bytes += store.written_bytes();
|
||||||
|
total_bytes += store.total_bytes();
|
||||||
}
|
}
|
||||||
if alive_count == stored_count && stores.values().len() == 1 {
|
if alive_count == stored_count && stores.values().len() == 1 {
|
||||||
trace!(
|
trace!(
|
||||||
|
@ -1032,14 +1044,17 @@ impl AccountsDB {
|
||||||
if forced { " (forced)" } else { "" },
|
if forced { " (forced)" } else { "" },
|
||||||
);
|
);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (alive_count as f32 / stored_count as f32) >= 0.80 && !forced {
|
} else if !forced {
|
||||||
trace!(
|
let sparse_by_count = (alive_count as f32 / stored_count as f32) <= 0.8;
|
||||||
"shrink_stale_slot ({}): not enough space to shrink: {} / {}",
|
let sparse_by_bytes = (written_bytes as f32 / total_bytes as f32) <= 0.8;
|
||||||
slot,
|
let skip_shrink = !sparse_by_count && !sparse_by_bytes;
|
||||||
alive_count,
|
info!(
|
||||||
stored_count,
|
"shrink_stale_slot ({}): skip_shrink: {} count: {}/{} byte: {}/{}",
|
||||||
|
slot, skip_shrink, alive_count, stored_count, written_bytes, total_bytes,
|
||||||
);
|
);
|
||||||
return 0;
|
if skip_shrink {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for store in stores.values() {
|
for store in stores.values() {
|
||||||
let mut start = 0;
|
let mut start = 0;
|
||||||
|
@ -5293,7 +5308,7 @@ pub mod tests {
|
||||||
|
|
||||||
let accounts = AccountsDB::new_single();
|
let accounts = AccountsDB::new_single();
|
||||||
|
|
||||||
let pubkey_count = 100;
|
let pubkey_count = 30000;
|
||||||
let pubkeys: Vec<_> = (0..pubkey_count)
|
let pubkeys: Vec<_> = (0..pubkey_count)
|
||||||
.map(|_| solana_sdk::pubkey::new_rand())
|
.map(|_| solana_sdk::pubkey::new_rand())
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -5314,7 +5329,7 @@ pub mod tests {
|
||||||
accounts.add_root(current_slot);
|
accounts.add_root(current_slot);
|
||||||
|
|
||||||
current_slot += 1;
|
current_slot += 1;
|
||||||
let pubkey_count_after_shrink = 90;
|
let pubkey_count_after_shrink = 25000;
|
||||||
let updated_pubkeys = &pubkeys[0..pubkey_count - pubkey_count_after_shrink];
|
let updated_pubkeys = &pubkeys[0..pubkey_count - pubkey_count_after_shrink];
|
||||||
|
|
||||||
for pubkey in updated_pubkeys {
|
for pubkey in updated_pubkeys {
|
||||||
|
|
Loading…
Reference in New Issue