Skip to content

Commit

Permalink
Merge branch 'master' into first-available-block-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher authored Dec 7, 2024
2 parents 9c9de1e + 48e8cf5 commit 8632c9c
Show file tree
Hide file tree
Showing 33 changed files with 916 additions and 853 deletions.
48 changes: 43 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 76 additions & 23 deletions accounts-cluster-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ use {
hash::Hash,
instruction::{AccountMeta, Instruction},
message::Message,
program_pack::Pack,
pubkey::Pubkey,
signature::{read_keypair_file, Keypair, Signer},
system_instruction, system_program,
transaction::Transaction,
},
solana_streamer::socket::SocketAddrSpace,
spl_token::state::Account,
std::{
cmp::min,
process::exit,
Expand Down Expand Up @@ -139,7 +141,11 @@ fn make_create_message(
maybe_space: Option<u64>,
mint: Option<Pubkey>,
) -> Message {
let space = maybe_space.unwrap_or_else(|| thread_rng().gen_range(0..1000));
let space = if mint.is_some() {
Account::get_packed_len() as u64
} else {
maybe_space.unwrap_or_else(|| thread_rng().gen_range(0..1000))
};

let instructions: Vec<_> = (0..num_instructions)
.flat_map(|_| {
Expand Down Expand Up @@ -170,6 +176,17 @@ fn make_create_message(
)
.unwrap(),
);
instructions.push(
spl_token::instruction::approve(
&spl_token::id(),
&to_pubkey,
&base_keypair.pubkey(),
&base_keypair.pubkey(),
&[&base_keypair.pubkey()],
1,
)
.unwrap(),
);
}

instructions
Expand Down Expand Up @@ -238,6 +255,7 @@ pub enum RpcBench {
ProgramAccounts,
TokenAccountsByOwner,
FirstAvailableBlock,
TokenAccountsByDelegate,
}

#[derive(Debug)]
Expand All @@ -253,6 +271,7 @@ impl FromStr for RpcBench {
"first-available-block" => Ok(RpcBench::FirstAvailableBlock),
"slot" => Ok(RpcBench::Slot),
"multiple-accounts" => Ok(RpcBench::MultipleAccounts),
"token-accounts-by-delegate" => Ok(RpcBench::TokenAccountsByDelegate),
"token-accounts-by-owner" => Ok(RpcBench::TokenAccountsByOwner),
"version" => Ok(RpcBench::Version),
_ => Err(RpcParseError::InvalidOption),
Expand Down Expand Up @@ -337,8 +356,37 @@ fn run_rpc_bench_loop(
let mut iters = 0;
let mut last_error = Instant::now();
let mut last_print = Instant::now();
fn flush_stats(
iters: &i32,
last_print: &mut Instant,
rpc_bench: &RpcBench,
stats: &mut RpcBenchStats,
thread: &usize,
) {
info!(
"t({}) rpc({:?}) iters: {} success: {} errors: {}",
thread, rpc_bench, iters, stats.success, stats.errors
);
if stats.success > 0 {
info!(
" t({}) rpc({:?} average success_time: {} us",
thread,
rpc_bench,
stats.total_success_time_us / stats.success
);
}
if stats.errors > 0 {
info!(
" rpc average average errors time: {} us",
stats.total_errors_time_us / stats.errors
);
}
*last_print = Instant::now();
*stats = RpcBenchStats::default();
}
loop {
if exit.load(Ordering::Relaxed) {
flush_stats(&iters, &mut last_print, &rpc_bench, &mut stats, &thread);
break;
}
match rpc_bench {
Expand Down Expand Up @@ -413,10 +461,30 @@ fn run_rpc_bench_loop(
}
}
}
RpcBench::TokenAccountsByDelegate => {
let mut rpc_time = Measure::start("rpc-get-token-accounts-by-delegate");
let filter = TokenAccountsFilter::Mint(*mint.as_ref().unwrap());
match client.get_token_accounts_by_delegate(base_keypair_pubkey, filter) {
Ok(_accounts) => {
rpc_time.stop();
stats.success += 1;
stats.total_success_time_us += rpc_time.as_us();
}
Err(e) => {
rpc_time.stop();
stats.errors += 1;
stats.total_errors_time_us += rpc_time.as_us();
if last_error.elapsed().as_secs() > 2 {
info!("get-token-accounts-by-delegate error: {:?}", e);
last_error = Instant::now();
}
}
}
}
RpcBench::TokenAccountsByOwner => {
let mut rpc_time = Measure::start("rpc-get-token-accounts-by-owner");
let filter = TokenAccountsFilter::Mint(*mint.as_ref().unwrap());
match client.get_token_accounts_by_owner(program_id, filter) {
match client.get_token_accounts_by_owner(base_keypair_pubkey, filter) {
Ok(_accounts) => {
rpc_time.stop();
stats.success += 1;
Expand All @@ -427,7 +495,7 @@ fn run_rpc_bench_loop(
stats.errors += 1;
stats.total_errors_time_us += rpc_time.as_us();
if last_error.elapsed().as_secs() > 2 {
info!("get-token-accounts error: {:?}", e);
info!("get-token-accounts-by-owner error: {:?}", e);
last_error = Instant::now();
}
}
Expand All @@ -451,26 +519,7 @@ fn run_rpc_bench_loop(
}

if last_print.elapsed().as_secs() > 3 {
info!(
"t({}) rpc({:?}) iters: {} success: {} errors: {}",
thread, rpc_bench, iters, stats.success, stats.errors
);
if stats.success > 0 {
info!(
" t({}) rpc({:?} average success_time: {} us",
thread,
rpc_bench,
stats.total_success_time_us / stats.success
);
}
if stats.errors > 0 {
info!(
" rpc average average errors time: {} us",
stats.total_errors_time_us / stats.errors
);
}
last_print = Instant::now();
stats = RpcBenchStats::default();
flush_stats(&iters, &mut last_print, &rpc_bench, &mut stats, &thread);
}

iters += 1;
Expand Down Expand Up @@ -871,6 +920,7 @@ fn main() {
.long("space")
.takes_value(true)
.value_name("BYTES")
.conflicts_with("mint")
.help("Size of accounts to create"),
)
.arg(
Expand Down Expand Up @@ -960,6 +1010,9 @@ fn main() {
.takes_value(true)
.value_name("RPC_BENCH_TYPE(S)")
.multiple(true)
.requires_ifs(&[
("token-accounts-by-owner", "mint"),
])
.help("Spawn a thread which calls a specific RPC method in a loop to benchmark it"),
)
.get_matches();
Expand Down
18 changes: 10 additions & 8 deletions core/src/banking_stage/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use {
solana_svm_transaction::svm_message::SVMMessage,
solana_timings::ExecuteTimings,
std::{
num::Saturating,
sync::{atomic::Ordering, Arc},
time::Instant,
},
Expand Down Expand Up @@ -792,10 +793,11 @@ impl Consumer {
(0, 0),
|(units, times), program_timings| {
(
units
.saturating_add(program_timings.accumulated_units)
.saturating_add(program_timings.total_errored_units),
times.saturating_add(program_timings.accumulated_us),
(Saturating(units)
+ program_timings.accumulated_units
+ program_timings.total_errored_units)
.0,
(Saturating(times) + program_timings.accumulated_us).0,
)
},
)
Expand Down Expand Up @@ -2522,11 +2524,11 @@ mod tests {
execute_timings.details.per_program_timings.insert(
Pubkey::new_unique(),
ProgramTiming {
accumulated_us: n * 100,
accumulated_units: n * 1000,
count: n as u32,
accumulated_us: Saturating(n * 100),
accumulated_units: Saturating(n * 1000),
count: Saturating(n as u32),
errored_txs_compute_consumed: vec![],
total_errored_units: 0,
total_errored_units: Saturating(0),
},
);
expected_us += n * 100;
Expand Down
Loading

0 comments on commit 8632c9c

Please sign in to comment.