Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Make account shrink configurable #17544 (#17778)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lijunwangs authored Jun 10, 2021
1 parent a1fab0c commit 269d995
Show file tree
Hide file tree
Showing 15 changed files with 402 additions and 15 deletions.
2 changes: 2 additions & 0 deletions accounts-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rayon::prelude::*;
use solana_measure::measure::Measure;
use solana_runtime::{
accounts::{create_test_accounts, update_accounts_bench, Accounts},
accounts_db::AccountShrinkThreshold,
accounts_index::AccountSecondaryIndexes,
ancestors::Ancestors,
};
Expand Down Expand Up @@ -64,6 +65,7 @@ fn main() {
&ClusterType::Testnet,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
println!("Creating {} accounts", num_accounts);
let mut create_time = Measure::start("create accounts");
Expand Down
2 changes: 2 additions & 0 deletions core/src/tvu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use solana_runtime::{
accounts_background_service::{
AbsRequestHandler, AbsRequestSender, AccountsBackgroundService, SnapshotRequestHandler,
},
accounts_db::AccountShrinkThreshold,
bank_forks::{BankForks, SnapshotConfig},
commitment::BlockCommitmentCache,
vote_sender_types::ReplayVoteSender,
Expand Down Expand Up @@ -89,6 +90,7 @@ pub struct TvuConfig {
pub rocksdb_compaction_interval: Option<u64>,
pub rocksdb_max_compaction_jitter: Option<u64>,
pub wait_for_vote_to_start_leader: bool,
pub accounts_shrink_ratio: AccountShrinkThreshold,
}

impl Tvu {
Expand Down
5 changes: 5 additions & 0 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use solana_rpc::{
transaction_status_service::TransactionStatusService,
};
use solana_runtime::{
accounts_db::AccountShrinkThreshold,
accounts_index::AccountSecondaryIndexes,
bank::Bank,
bank_forks::{BankForks, SnapshotConfig},
Expand Down Expand Up @@ -139,6 +140,7 @@ pub struct ValidatorConfig {
pub tpu_coalesce_ms: u64,
pub validator_exit: Arc<RwLock<Exit>>,
pub no_wait_for_vote_to_start_leader: bool,
pub accounts_shrink_ratio: AccountShrinkThreshold,
}

impl Default for ValidatorConfig {
Expand Down Expand Up @@ -195,6 +197,7 @@ impl Default for ValidatorConfig {
tpu_coalesce_ms: DEFAULT_TPU_COALESCE_MS,
validator_exit: Arc::new(RwLock::new(Exit::default())),
no_wait_for_vote_to_start_leader: true,
accounts_shrink_ratio: AccountShrinkThreshold::default(),
}
}
}
Expand Down Expand Up @@ -726,6 +729,7 @@ impl Validator {
rocksdb_compaction_interval: config.rocksdb_compaction_interval,
rocksdb_max_compaction_jitter: config.rocksdb_compaction_interval,
wait_for_vote_to_start_leader,
accounts_shrink_ratio: config.accounts_shrink_ratio,
},
&max_slots,
&cost_model,
Expand Down Expand Up @@ -1099,6 +1103,7 @@ fn new_banks_from_ledger(
debug_keys: config.debug_keys.clone(),
account_indexes: config.account_indexes.clone(),
accounts_db_caching_enabled: config.accounts_db_caching_enabled,
shrink_ratio: config.accounts_shrink_ratio,
..blockstore_processor::ProcessOptions::default()
};

Expand Down
2 changes: 2 additions & 0 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ mod tests {
None,
AccountSecondaryIndexes::default(),
false,
accounts_db::AccountShrinkThreshold::default(),
);
bank0.freeze();
let mut bank_forks = BankForks::new(bank0);
Expand Down Expand Up @@ -165,6 +166,7 @@ mod tests {
AccountSecondaryIndexes::default(),
false,
None,
accounts_db::AccountShrinkThreshold::default(),
)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions ledger/src/bank_forks_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ fn load_from_snapshot(
process_options.account_indexes.clone(),
process_options.accounts_db_caching_enabled,
process_options.limit_load_slot_count_from_snapshot,
process_options.shrink_ratio,
)
.expect("Load from snapshot failed");
if let Some(shrink_paths) = shrink_paths {
Expand Down
4 changes: 4 additions & 0 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use solana_measure::measure::Measure;
use solana_metrics::{datapoint_error, inc_new_counter_debug};
use solana_rayon_threadlimit::get_thread_count;
use solana_runtime::{
accounts_db::AccountShrinkThreshold,
accounts_index::AccountSecondaryIndexes,
bank::{
Bank, ExecuteTimings, InnerInstructionsList, RentDebits, TransactionBalancesSet,
Expand Down Expand Up @@ -373,6 +374,7 @@ pub struct ProcessOptions {
pub limit_load_slot_count_from_snapshot: Option<usize>,
pub allow_dead_slots: bool,
pub accounts_db_test_hash_calculation: bool,
pub shrink_ratio: AccountShrinkThreshold,
}

pub fn process_blockstore(
Expand Down Expand Up @@ -400,6 +402,7 @@ pub fn process_blockstore(
Some(&crate::builtins::get(opts.bpf_jit)),
opts.account_indexes.clone(),
opts.accounts_db_caching_enabled,
opts.shrink_ratio,
);
let bank0 = Arc::new(bank0);
info!("processing ledger for slot 0...");
Expand Down Expand Up @@ -3064,6 +3067,7 @@ pub mod tests {
None,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
*bank.epoch_schedule()
}
Expand Down
1 change: 1 addition & 0 deletions local-cluster/src/validator_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn safe_clone_config(config: &ValidatorConfig) -> ValidatorConfig {
validator_exit: Arc::new(RwLock::new(Exit::default())),
poh_hashes_per_batch: config.poh_hashes_per_batch,
no_wait_for_vote_to_start_leader: config.no_wait_for_vote_to_start_leader,
accounts_shrink_ratio: config.accounts_shrink_ratio,
}
}

Expand Down
10 changes: 10 additions & 0 deletions runtime/benches/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -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![];
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 22 additions & 2 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
accounts_db::{
AccountsDb, BankHashInfo, ErrorCounters, LoadHint, LoadedAccount, ScanStorageResult,
AccountShrinkThreshold, AccountsDb, BankHashInfo, ErrorCounters, LoadHint, LoadedAccount,
ScanStorageResult,
},
accounts_index::{AccountSecondaryIndexes, IndexKey},
ancestors::Ancestors,
Expand Down Expand Up @@ -117,12 +118,17 @@ pub enum AccountAddressFilter {
}

impl Accounts {
pub fn new(paths: Vec<PathBuf>, cluster_type: &ClusterType) -> Self {
pub fn new(
paths: Vec<PathBuf>,
cluster_type: &ClusterType,
shrink_ratio: AccountShrinkThreshold,
) -> Self {
Self::new_with_config(
paths,
cluster_type,
AccountSecondaryIndexes::default(),
false,
shrink_ratio,
)
}

Expand All @@ -131,13 +137,15 @@ impl Accounts {
cluster_type: &ClusterType,
account_indexes: AccountSecondaryIndexes,
caching_enabled: bool,
shrink_ratio: AccountShrinkThreshold,
) -> Self {
Self {
accounts_db: Arc::new(AccountsDb::new_with_config(
paths,
cluster_type,
account_indexes,
caching_enabled,
shrink_ratio,
)),
account_locks: Mutex::new(AccountLocks::default()),
}
Expand Down Expand Up @@ -1118,6 +1126,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
for ka in ka.iter() {
accounts.store_slow_uncached(0, &ka.0, &ka.1);
Expand Down Expand Up @@ -1655,6 +1664,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);

// Load accounts owned by various programs into AccountsDb
Expand Down Expand Up @@ -1683,6 +1693,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
let mut error_counters = ErrorCounters::default();
let ancestors = vec![(0, 0)].into_iter().collect();
Expand All @@ -1706,6 +1717,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
accounts.bank_hash_at(1);
}
Expand All @@ -1727,6 +1739,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
accounts.store_slow_uncached(0, &keypair0.pubkey(), &account0);
accounts.store_slow_uncached(0, &keypair1.pubkey(), &account1);
Expand Down Expand Up @@ -1853,6 +1866,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
accounts.store_slow_uncached(0, &keypair0.pubkey(), &account0);
accounts.store_slow_uncached(0, &keypair1.pubkey(), &account1);
Expand Down Expand Up @@ -2003,6 +2017,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
{
accounts
Expand Down Expand Up @@ -2055,6 +2070,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
let mut old_pubkey = Pubkey::default();
let zero_account = AccountSharedData::new(0, 0, AccountSharedData::default().owner());
Expand Down Expand Up @@ -2102,6 +2118,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);

let instructions_key = solana_sdk::sysvar::instructions::id();
Expand Down Expand Up @@ -2387,6 +2404,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
let collected_accounts = accounts.collect_accounts_to_store(
txs.iter(),
Expand Down Expand Up @@ -2506,6 +2524,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);
let collected_accounts = accounts.collect_accounts_to_store(
txs.iter(),
Expand Down Expand Up @@ -2540,6 +2559,7 @@ mod tests {
&ClusterType::Development,
AccountSecondaryIndexes::default(),
false,
AccountShrinkThreshold::default(),
);

let pubkey0 = Pubkey::new_unique();
Expand Down
Loading

0 comments on commit 269d995

Please sign in to comment.