forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds bench for writing accounts to append vecs and hot storage (solan…
- Loading branch information
1 parent
8e37ad7
commit b2b159a
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#![allow(clippy::arithmetic_side_effects)] | ||
use { | ||
criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput}, | ||
solana_accounts_db::{ | ||
account_storage::meta::StorableAccountsWithHashesAndWriteVersions, | ||
accounts_hash::AccountHash, | ||
append_vec::{self, AppendVec}, | ||
tiered_storage::hot::HotStorageWriter, | ||
}, | ||
solana_sdk::{ | ||
account::Account, clock::Slot, hash::Hash, pubkey::Pubkey, | ||
rent_collector::RENT_EXEMPT_RENT_EPOCH, | ||
}, | ||
}; | ||
|
||
const ACCOUNTS_COUNTS: [usize; 4] = [ | ||
1, // the smallest count; will bench overhead | ||
100, // number of accounts written per slot on mnb (with *no* rent rewrites) | ||
1_000, // number of accounts written slot on mnb (with rent rewrites) | ||
10_000, // reasonable largest number of accounts written per slot | ||
]; | ||
|
||
fn bench_write_accounts_file(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("write_accounts_file"); | ||
|
||
// most accounts on mnb are 165-200 bytes, so use that here too | ||
let space = 200; | ||
let lamports = 2_282_880; // the rent-exempt amount for 200 bytes of data | ||
let temp_dir = tempfile::tempdir().unwrap(); | ||
|
||
for accounts_count in ACCOUNTS_COUNTS { | ||
group.throughput(Throughput::Elements(accounts_count as u64)); | ||
|
||
let accounts: Vec<_> = std::iter::repeat_with(|| { | ||
( | ||
Pubkey::new_unique(), | ||
Account::new_rent_epoch( | ||
lamports, | ||
space, | ||
&Pubkey::new_unique(), | ||
RENT_EXEMPT_RENT_EPOCH, | ||
), | ||
) | ||
}) | ||
.take(accounts_count) | ||
.collect(); | ||
let accounts_refs: Vec<_> = accounts.iter().collect(); | ||
let accounts_data = (Slot::MAX, accounts_refs.as_slice()); | ||
let storable_accounts = | ||
StorableAccountsWithHashesAndWriteVersions::new_with_hashes_and_write_versions( | ||
&accounts_data, | ||
vec![AccountHash(Hash::default()); accounts_count], | ||
vec![0; accounts_count], | ||
); | ||
|
||
group.bench_function(BenchmarkId::new("append_vec", accounts_count), |b| { | ||
b.iter_batched_ref( | ||
|| { | ||
let path = temp_dir.path().join(format!("append_vec_{accounts_count}")); | ||
let file_size = accounts.len() * (space + append_vec::STORE_META_OVERHEAD); | ||
AppendVec::new(&path, true, file_size) | ||
}, | ||
|append_vec| { | ||
let res = append_vec.append_accounts(&storable_accounts, 0).unwrap(); | ||
let accounts_written_count = res.len(); | ||
assert_eq!(accounts_written_count, accounts_count); | ||
}, | ||
BatchSize::SmallInput, | ||
); | ||
}); | ||
|
||
group.bench_function(BenchmarkId::new("hot_storage", accounts_count), |b| { | ||
b.iter_batched_ref( | ||
|| { | ||
let path = temp_dir | ||
.path() | ||
.join(format!("hot_storage_{accounts_count}")); | ||
_ = std::fs::remove_file(&path); | ||
HotStorageWriter::new(path).unwrap() | ||
}, | ||
|hot_storage| { | ||
let res = hot_storage.write_accounts(&storable_accounts, 0).unwrap(); | ||
let accounts_written_count = res.len(); | ||
assert_eq!(accounts_written_count, accounts_count); | ||
}, | ||
BatchSize::SmallInput, | ||
); | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, bench_write_accounts_file); | ||
criterion_main!(benches); |