Make account shrink configurable #17544 (#17778)

1. Added both options for measuring space usage using total accounts usage and for individual store shrink ratio using an enum. Validator CLI options: --accounts-shrink-optimize-total-space and --accounts-shrink-ratio
2. Added code for selecting candidates based on total usage in a separate function select_candidates_by_total_usage
3. Added unit tests for the new functions added
4. The default implementations is kept at 0.8 shrink ratio with --accounts-shrink-optimize-total-space set to true

Fixes #17544
This commit is contained in:
Lijun Wang
2021-06-09 21:21:32 -07:00
committed by GitHub
parent a1fab0c5ca
commit 269d995832
15 changed files with 404 additions and 17 deletions

View File

@@ -8,6 +8,7 @@ use rand::Rng;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use solana_runtime::{
accounts::{create_test_accounts, AccountAddressFilter, Accounts},
accounts_db::AccountShrinkThreshold,
accounts_index::AccountSecondaryIndexes,
ancestors::Ancestors,
bank::*,
@@ -59,6 +60,7 @@ fn test_accounts_create(bencher: &mut Bencher) {
None,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
bencher.iter(|| {
let mut pubkeys: Vec<Pubkey> = vec![];
@@ -78,6 +80,7 @@ fn test_accounts_squash(bencher: &mut Bencher) {
None,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
));
let mut pubkeys: Vec<Pubkey> = vec![];
deposit_many(&prev_bank, &mut pubkeys, 250_000).unwrap();
@@ -103,6 +106,7 @@ fn test_accounts_hash_bank_hash(bencher: &mut Bencher) {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
let mut pubkeys: Vec<Pubkey> = vec![];
let num_accounts = 60_000;
@@ -121,6 +125,7 @@ fn test_update_accounts_hash(bencher: &mut Bencher) {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
let mut pubkeys: Vec<Pubkey> = vec![];
create_test_accounts(&accounts, &mut pubkeys, 50_000, 0);
@@ -138,6 +143,7 @@ fn test_accounts_delta_hash(bencher: &mut Bencher) {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
let mut pubkeys: Vec<Pubkey> = vec![];
create_test_accounts(&accounts, &mut pubkeys, 100_000, 0);
@@ -154,6 +160,7 @@ fn bench_delete_dependencies(bencher: &mut Bencher) {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
let mut old_pubkey = Pubkey::default();
let zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner());
@@ -187,6 +194,7 @@ fn store_accounts_with_possible_contention<F: 'static>(
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
));
let num_keys = 1000;
let slot = 0;
@@ -316,6 +324,7 @@ fn setup_bench_dashmap_iter() -> (Arc<Accounts>, DashMap<Pubkey, (AccountSharedD
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
));
let dashmap = DashMap::new();
@@ -370,6 +379,7 @@ fn bench_load_largest_accounts(b: &mut Bencher) {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
let mut rng = rand::thread_rng();
for _ in 0..10_000 {