Skip to content

Commit

Permalink
A benchmark suite for the getTokenAccountsByDelgate RPC call (#3967)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher authored Dec 7, 2024
1 parent 6e4fd19 commit 48e8cf5
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion accounts-cluster-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,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 @@ -243,6 +254,7 @@ pub enum RpcBench {
MultipleAccounts,
ProgramAccounts,
TokenAccountsByOwner,
TokenAccountsByDelegate,
}

#[derive(Debug)]
Expand All @@ -257,6 +269,7 @@ impl FromStr for RpcBench {
match s {
"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 @@ -427,6 +440,26 @@ 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());
Expand All @@ -441,7 +474,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 Down

0 comments on commit 48e8cf5

Please sign in to comment.