Skip to content

Commit

Permalink
switch localcluster bench test to use tpuclient
Browse files Browse the repository at this point in the history
add back in command line args for thinclient. add thin-client deprecation README

refactor TpuClient connection
  • Loading branch information
gregcusack committed Mar 1, 2024
1 parent d1a5c6c commit c42cbf9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 140 deletions.
72 changes: 28 additions & 44 deletions bench-tps/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
},
solana_tpu_client::tpu_client::{DEFAULT_TPU_CONNECTION_POOL_SIZE, DEFAULT_TPU_USE_QUIC},
std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
net::{IpAddr, Ipv4Addr},
time::Duration,
},
};
Expand All @@ -24,9 +24,6 @@ const NUM_LAMPORTS_PER_ACCOUNT_DEFAULT: u64 = solana_sdk::native_token::LAMPORTS
pub enum ExternalClientType {
// Submits transactions to an Rpc node using an RpcClient
RpcClient,
// Submits transactions directly to leaders using a ThinClient, broadcasting to multiple
// leaders when num_nodes > 1
ThinClient,
// Submits transactions directly to leaders using a TpuClient, broadcasting to upcoming leaders
// via TpuClient default configuration
TpuClient,
Expand All @@ -53,12 +50,10 @@ pub enum ComputeUnitPrice {
/// Holds the configuration for a single run of the benchmark
#[derive(PartialEq, Debug)]
pub struct Config {
pub entrypoint_addr: SocketAddr,
pub json_rpc_url: String,
pub websocket_url: String,
pub id: Keypair,
pub threads: usize,
pub num_nodes: usize,
pub duration: Duration,
pub tx_count: usize,
pub keypair_multiplier: usize,
Expand All @@ -68,10 +63,8 @@ pub struct Config {
pub write_to_client_file: bool,
pub read_from_client_file: bool,
pub target_lamports_per_signature: u64,
pub multi_client: bool,
pub num_lamports_per_account: u64,
pub target_slots_per_epoch: u64,
pub target_node: Option<Pubkey>,
pub external_client_type: ExternalClientType,
pub use_quic: bool,
pub tpu_connection_pool_size: usize,
Expand All @@ -89,12 +82,10 @@ impl Eq for Config {}
impl Default for Config {
fn default() -> Config {
Config {
entrypoint_addr: SocketAddr::from((Ipv4Addr::LOCALHOST, 8001)),
json_rpc_url: ConfigInput::default().json_rpc_url,
websocket_url: ConfigInput::default().websocket_url,
id: Keypair::new(),
threads: 4,
num_nodes: 1,
duration: Duration::new(std::u64::MAX, 0),
tx_count: 50_000,
keypair_multiplier: 8,
Expand All @@ -104,10 +95,8 @@ impl Default for Config {
write_to_client_file: false,
read_from_client_file: false,
target_lamports_per_signature: FeeRateGovernor::default().target_lamports_per_signature,
multi_client: true,
num_lamports_per_account: NUM_LAMPORTS_PER_ACCOUNT_DEFAULT,
target_slots_per_epoch: 0,
target_node: None,
external_client_type: ExternalClientType::default(),
use_quic: DEFAULT_TPU_USE_QUIC,
tpu_connection_pool_size: DEFAULT_TPU_CONNECTION_POOL_SIZE,
Expand Down Expand Up @@ -169,8 +158,10 @@ pub fn build_args<'a>(version: &'_ str) -> App<'a, '_> {
.takes_value(true)
.conflicts_with("rpc_client")
.requires("tpu_addr")
.requires("thin_client")
.help("Specify custom rpc_addr to create thin_client"),
.hidden(hidden_unless_forced())
.help("Specify custom rpc_addr to create thin_client. \
Note: ThinClient is deprecated. Argument will not be used. \
Use tpc_client or rpc_client instead"),
)
.arg(
Arg::with_name("tpu_addr")
Expand All @@ -179,16 +170,21 @@ pub fn build_args<'a>(version: &'_ str) -> App<'a, '_> {
.conflicts_with("rpc_client")
.takes_value(true)
.requires("rpc_addr")
.requires("thin_client")
.help("Specify custom tpu_addr to create thin_client"),
.hidden(hidden_unless_forced())
.help("Specify custom tpu_addr to create thin_client. \
Note: ThinClient is deprecated. Argument will not be used. \
Use tpc_client or rpc_client instead"),
)
.arg(
Arg::with_name("entrypoint")
.short("n")
.long("entrypoint")
.value_name("HOST:PORT")
.takes_value(true)
.help("Rendezvous with the cluster at this entry point; defaults to 127.0.0.1:8001"),
.hidden(hidden_unless_forced())
.help("Rendezvous with the cluster at this entry point; defaults to 127.0.0.1:8001. \
Note: ThinClient is deprecated. Argument will not be used. \
Use tpc_client or rpc_client instead"),
)
.arg(
Arg::with_name("faucet")
Expand All @@ -213,7 +209,10 @@ pub fn build_args<'a>(version: &'_ str) -> App<'a, '_> {
.long("num-nodes")
.value_name("NUM")
.takes_value(true)
.help("Wait for NUM nodes to converge"),
.hidden(hidden_unless_forced())
.help("Wait for NUM nodes to converge. \
Note: ThinClient is deprecated. Argument will not be used. \
Use tpc_client or rpc_client instead"),
)
.arg(
Arg::with_name("threads")
Expand All @@ -238,15 +237,21 @@ pub fn build_args<'a>(version: &'_ str) -> App<'a, '_> {
.arg(
Arg::with_name("no-multi-client")
.long("no-multi-client")
.help("Disable multi-client support, only transact with the entrypoint."),
.hidden(hidden_unless_forced())
.help("Disable multi-client support, only transact with the entrypoint. \
Note: ThinClient is deprecated. Flag will not be used. \
Use tpc_client or rpc_client instead"),
)
.arg(
Arg::with_name("target_node")
.long("target-node")
.requires("no-multi-client")
.takes_value(true)
.value_name("PUBKEY")
.help("Specify an exact node to send transactions to."),
.hidden(hidden_unless_forced())
.help("Specify an exact node to send transactions to. \
Note: ThinClient is deprecated. Argument will not be used. \
Use tpc_client or rpc_client instead"),
)
.arg(
Arg::with_name("tx_count")
Expand Down Expand Up @@ -343,15 +348,13 @@ pub fn build_args<'a>(version: &'_ str) -> App<'a, '_> {
Arg::with_name("tpu_disable_quic")
.long("tpu-disable-quic")
.takes_value(false)
.help("Do not submit transactions via QUIC; only affects ThinClient \
or TpuClient (default) sends"),
.help("Do not submit transactions via QUIC; only affects TpuClient (default) sends"),
)
.arg(
Arg::with_name("tpu_connection_pool_size")
.long("tpu-connection-pool-size")
.takes_value(true)
.help("Controls the connection pool size per remote address; only affects ThinClient \
or TpuClient (default) sends"),
.help("Controls the connection pool size per remote address; only affects TpuClient (default) sends"),
)
.arg(
Arg::with_name("compute_unit_price")
Expand Down Expand Up @@ -471,19 +474,10 @@ pub fn parse_args(matches: &ArgMatches) -> Result<Config, &'static str> {
.map_err(|_| "can't parse tpu-connection-pool-size")?;
}

if let Some(addr) = matches.value_of("entrypoint") {
args.entrypoint_addr = solana_net_utils::parse_host_port(addr)
.map_err(|_| "failed to parse entrypoint address")?;
}

if let Some(t) = matches.value_of("threads") {
args.threads = t.to_string().parse().map_err(|_| "can't parse threads")?;
}

if let Some(n) = matches.value_of("num-nodes") {
args.num_nodes = n.to_string().parse().map_err(|_| "can't parse num-nodes")?;
}

if let Some(duration) = matches.value_of("duration") {
let seconds = duration
.to_string()
Expand Down Expand Up @@ -533,13 +527,6 @@ pub fn parse_args(matches: &ArgMatches) -> Result<Config, &'static str> {
.map_err(|_| "can't parse target-lamports-per-signature")?;
}

args.multi_client = !matches.is_present("no-multi-client");
args.target_node = matches
.value_of("target_node")
.map(|target_str| target_str.parse::<Pubkey>())
.transpose()
.map_err(|_| "Failed to parse target-node")?;

if let Some(v) = matches.value_of("num_lamports_per_account") {
args.num_lamports_per_account = v
.to_string()
Expand Down Expand Up @@ -611,7 +598,7 @@ mod tests {
super::*,
solana_sdk::signature::{read_keypair_file, write_keypair_file, Keypair, Signer},
std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
net::{IpAddr, Ipv4Addr},
time::Duration,
},
tempfile::{tempdir, TempDir},
Expand Down Expand Up @@ -671,8 +658,6 @@ mod tests {
"4",
"--read-client-keys",
"./client-accounts.yml",
"--entrypoint",
"192.1.2.3:8001",
]);
let actual = parse_args(&matches).unwrap();
assert_eq!(
Expand All @@ -686,7 +671,6 @@ mod tests {
threads: 4,
read_from_client_file: true,
client_ids_and_stake_file: "./client-accounts.yml".to_string(),
entrypoint_addr: SocketAddr::from((Ipv4Addr::new(192, 1, 2, 3), 8001)),
..Config::default()
}
);
Expand Down
87 changes: 2 additions & 85 deletions bench-tps/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(clippy::arithmetic_side_effects)]
use {
clap::value_t,
log::*,
solana_bench_tps::{
bench::{do_bench_tps, max_lamports_for_prioritization},
Expand All @@ -11,11 +10,9 @@ use {
},
solana_client::{
connection_cache::ConnectionCache,
thin_client::ThinClient,
tpu_client::{TpuClient, TpuClientConfig},
},
solana_genesis::Base64Account,
solana_gossip::gossip_service::{discover_cluster, get_client, get_multi_client},
solana_rpc_client::rpc_client::RpcClient,
solana_sdk::{
commitment_config::CommitmentConfig,
Expand All @@ -24,12 +21,12 @@ use {
signature::{Keypair, Signer},
system_program,
},
solana_streamer::{socket::SocketAddrSpace, streamer::StakedNodes},
solana_streamer::streamer::StakedNodes,
std::{
collections::HashMap,
fs::File,
io::prelude::*,
net::{IpAddr, SocketAddr},
net::IpAddr,
path::Path,
process::exit,
sync::{Arc, RwLock},
Expand Down Expand Up @@ -125,13 +122,8 @@ fn create_connection_cache(
#[allow(clippy::too_many_arguments)]
fn create_client(
external_client_type: &ExternalClientType,
entrypoint_addr: &SocketAddr,
json_rpc_url: &str,
websocket_url: &str,
multi_client: bool,
rpc_tpu_sockets: Option<(SocketAddr, SocketAddr)>,
num_nodes: usize,
target_node: Option<Pubkey>,
connection_cache: ConnectionCache,
commitment_config: CommitmentConfig,
) -> Arc<dyn BenchTpsClient + Send + Sync> {
Expand All @@ -140,53 +132,6 @@ fn create_client(
json_rpc_url.to_string(),
commitment_config,
)),
ExternalClientType::ThinClient => {
let connection_cache = Arc::new(connection_cache);
if let Some((rpc, tpu)) = rpc_tpu_sockets {
Arc::new(ThinClient::new(rpc, tpu, connection_cache))
} else {
let nodes =
discover_cluster(entrypoint_addr, num_nodes, SocketAddrSpace::Unspecified)
.unwrap_or_else(|err| {
eprintln!("Failed to discover {num_nodes} nodes: {err:?}");
exit(1);
});
if multi_client {
let (client, num_clients) =
get_multi_client(&nodes, &SocketAddrSpace::Unspecified, connection_cache);
if nodes.len() < num_clients {
eprintln!(
"Error: Insufficient nodes discovered. Expecting {num_nodes} or more"
);
exit(1);
}
Arc::new(client)
} else if let Some(target_node) = target_node {
info!("Searching for target_node: {:?}", target_node);
let mut target_client = None;
for node in nodes {
if node.pubkey() == &target_node {
target_client = Some(get_client(
&[node],
&SocketAddrSpace::Unspecified,
connection_cache,
));
break;
}
}
Arc::new(target_client.unwrap_or_else(|| {
eprintln!("Target node {target_node} not found");
exit(1);
}))
} else {
Arc::new(get_client(
&nodes,
&SocketAddrSpace::Unspecified,
connection_cache,
))
}
}
}
ExternalClientType::TpuClient => {
let rpc_client = Arc::new(RpcClient::new_with_commitment(
json_rpc_url.to_string(),
Expand Down Expand Up @@ -236,20 +181,16 @@ fn main() {
};

let cli::Config {
entrypoint_addr,
json_rpc_url,
websocket_url,
id,
num_nodes,
tx_count,
keypair_multiplier,
client_ids_and_stake_file,
write_to_client_file,
read_from_client_file,
target_lamports_per_signature,
multi_client,
num_lamports_per_account,
target_node,
external_client_type,
use_quic,
tpu_connection_pool_size,
Expand Down Expand Up @@ -295,25 +236,6 @@ fn main() {
return;
}

info!("Connecting to the cluster");
let rpc_tpu_sockets: Option<(SocketAddr, SocketAddr)> =
if let Ok(rpc_addr) = value_t!(matches, "rpc_addr", String) {
let rpc = rpc_addr.parse().unwrap_or_else(|e| {
eprintln!("RPC address should parse as socketaddr {e:?}");
exit(1);
});
let tpu = value_t!(matches, "tpu_addr", String)
.unwrap()
.parse()
.unwrap_or_else(|e| {
eprintln!("TPU address should parse to a socket: {e:?}");
exit(1);
});
Some((rpc, tpu))
} else {
None
};

let connection_cache = create_connection_cache(
json_rpc_url,
*tpu_connection_pool_size,
Expand All @@ -324,13 +246,8 @@ fn main() {
);
let client = create_client(
external_client_type,
entrypoint_addr,
json_rpc_url,
websocket_url,
*multi_client,
rpc_tpu_sockets,
*num_nodes,
*target_node,
connection_cache,
*commitment_config,
);
Expand Down
1 change: 0 additions & 1 deletion bench-tps/src/perf_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub fn sample_txs<T>(
let mut txs =
match client.get_transaction_count_with_commitment(CommitmentConfig::processed()) {
Err(e) => {
// ThinClient with multiple options should pick a better one now.
info!("Couldn't get transaction count {:?}", e);
sleep(Duration::from_secs(sample_period));
continue;
Expand Down
Loading

0 comments on commit c42cbf9

Please sign in to comment.