2019-03-13 20:54:30 -07:00
|
|
|
use clap::{crate_description, crate_name, crate_version, App, Arg, ArgMatches};
|
2018-12-11 19:47:32 -08:00
|
|
|
use solana_drone::drone::DRONE_PORT;
|
2019-06-18 14:44:53 -07:00
|
|
|
use solana_sdk::fee_calculator::FeeCalculator;
|
2019-10-10 16:01:03 -07:00
|
|
|
use solana_sdk::signature::{read_keypair_file, Keypair, KeypairUtil};
|
2019-10-04 01:16:07 -07:00
|
|
|
use std::{net::SocketAddr, process::exit, time::Duration};
|
2018-12-11 19:47:32 -08:00
|
|
|
|
2019-09-10 16:24:43 -07:00
|
|
|
const NUM_LAMPORTS_PER_ACCOUNT_DEFAULT: u64 = 64 * 1024;
|
|
|
|
|
2018-12-11 19:47:32 -08:00
|
|
|
/// Holds the configuration for a single run of the benchmark
|
|
|
|
pub struct Config {
|
2019-05-03 15:00:19 -07:00
|
|
|
pub entrypoint_addr: SocketAddr,
|
2018-12-11 19:47:32 -08:00
|
|
|
pub drone_addr: SocketAddr,
|
|
|
|
pub id: Keypair,
|
|
|
|
pub threads: usize,
|
|
|
|
pub num_nodes: usize,
|
|
|
|
pub duration: Duration,
|
|
|
|
pub tx_count: usize,
|
2019-01-03 14:16:06 -08:00
|
|
|
pub thread_batch_sleep_ms: usize,
|
2018-12-11 19:47:32 -08:00
|
|
|
pub sustained: bool,
|
2019-06-11 18:47:35 -07:00
|
|
|
pub client_ids_and_stake_file: String,
|
|
|
|
pub write_to_client_file: bool,
|
|
|
|
pub read_from_client_file: bool,
|
2019-06-18 14:44:53 -07:00
|
|
|
pub target_lamports_per_signature: u64,
|
2019-07-28 10:43:42 -07:00
|
|
|
pub use_move: bool,
|
2019-09-10 16:24:43 -07:00
|
|
|
pub num_lamports_per_account: u64,
|
2018-12-11 19:47:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Config {
|
|
|
|
fn default() -> Config {
|
|
|
|
Config {
|
2019-05-03 15:00:19 -07:00
|
|
|
entrypoint_addr: SocketAddr::from(([127, 0, 0, 1], 8001)),
|
2018-12-11 19:47:32 -08:00
|
|
|
drone_addr: SocketAddr::from(([127, 0, 0, 1], DRONE_PORT)),
|
|
|
|
id: Keypair::new(),
|
|
|
|
threads: 4,
|
|
|
|
num_nodes: 1,
|
|
|
|
duration: Duration::new(std::u64::MAX, 0),
|
2019-10-15 20:53:37 -07:00
|
|
|
tx_count: 50_000,
|
|
|
|
thread_batch_sleep_ms: 1000,
|
2018-12-11 19:47:32 -08:00
|
|
|
sustained: false,
|
2019-06-11 18:47:35 -07:00
|
|
|
client_ids_and_stake_file: String::new(),
|
|
|
|
write_to_client_file: false,
|
|
|
|
read_from_client_file: false,
|
2019-06-18 14:44:53 -07:00
|
|
|
target_lamports_per_signature: FeeCalculator::default().target_lamports_per_signature,
|
2019-07-28 10:43:42 -07:00
|
|
|
use_move: false,
|
2019-09-10 16:24:43 -07:00
|
|
|
num_lamports_per_account: NUM_LAMPORTS_PER_ACCOUNT_DEFAULT,
|
2018-12-11 19:47:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Defines and builds the CLI args for a run of the benchmark
|
|
|
|
pub fn build_args<'a, 'b>() -> App<'a, 'b> {
|
2019-03-13 20:54:30 -07:00
|
|
|
App::new(crate_name!()).about(crate_description!())
|
2018-12-11 19:47:32 -08:00
|
|
|
.version(crate_version!())
|
|
|
|
.arg(
|
2019-05-03 15:00:19 -07:00
|
|
|
Arg::with_name("entrypoint")
|
2018-12-11 19:47:32 -08:00
|
|
|
.short("n")
|
2019-05-03 15:00:19 -07:00
|
|
|
.long("entrypoint")
|
2018-12-11 19:47:32 -08:00
|
|
|
.value_name("HOST:PORT")
|
|
|
|
.takes_value(true)
|
2019-05-03 15:00:19 -07:00
|
|
|
.help("Rendezvous with the cluster at this entry point; defaults to 127.0.0.1:8001"),
|
2018-12-11 19:47:32 -08:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("drone")
|
|
|
|
.short("d")
|
|
|
|
.long("drone")
|
|
|
|
.value_name("HOST:PORT")
|
|
|
|
.takes_value(true)
|
2019-05-03 15:00:19 -07:00
|
|
|
.help("Location of the drone; defaults to entrypoint:DRONE_PORT"),
|
2018-12-11 19:47:32 -08:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("identity")
|
|
|
|
.short("i")
|
|
|
|
.long("identity")
|
|
|
|
.value_name("PATH")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("File containing a client identity (keypair)"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("num-nodes")
|
|
|
|
.short("N")
|
|
|
|
.long("num-nodes")
|
|
|
|
.value_name("NUM")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Wait for NUM nodes to converge"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("threads")
|
|
|
|
.short("t")
|
|
|
|
.long("threads")
|
|
|
|
.value_name("NUM")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Number of threads"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("duration")
|
|
|
|
.long("duration")
|
|
|
|
.value_name("SECS")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Seconds to run benchmark, then exit; default is forever"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("sustained")
|
|
|
|
.long("sustained")
|
|
|
|
.help("Use sustained performance mode vs. peak mode. This overlaps the tx generation with transfers."),
|
|
|
|
)
|
2019-07-28 10:43:42 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("use-move")
|
|
|
|
.long("use-move")
|
|
|
|
.help("Use Move language transactions to perform transfers."),
|
|
|
|
)
|
2018-12-11 19:47:32 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("tx_count")
|
|
|
|
.long("tx_count")
|
|
|
|
.value_name("NUM")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Number of transactions to send per batch")
|
|
|
|
)
|
2019-01-03 14:16:06 -08:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("thread-batch-sleep-ms")
|
|
|
|
.short("z")
|
|
|
|
.long("thread-batch-sleep-ms")
|
|
|
|
.value_name("NUM")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Per-thread-per-iteration sleep in ms"),
|
|
|
|
)
|
2019-06-11 18:47:35 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("write-client-keys")
|
|
|
|
.long("write-client-keys")
|
|
|
|
.value_name("FILENAME")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Generate client keys and stakes and write the list to YAML file"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("read-client-keys")
|
|
|
|
.long("read-client-keys")
|
|
|
|
.value_name("FILENAME")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Read client keys and stakes from the YAML file"),
|
|
|
|
)
|
2019-06-18 14:44:53 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("target_lamports_per_signature")
|
|
|
|
.long("target-lamports-per-signature")
|
|
|
|
.value_name("LAMPORTS")
|
|
|
|
.takes_value(true)
|
|
|
|
.help(
|
|
|
|
"The cost in lamports that the cluster will charge for signature \
|
|
|
|
verification when the cluster is operating at target-signatures-per-slot",
|
|
|
|
),
|
|
|
|
)
|
2019-09-10 16:24:43 -07:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("num_lamports_per_account")
|
|
|
|
.long("num-lamports-per-account")
|
|
|
|
.value_name("LAMPORTS")
|
|
|
|
.takes_value(true)
|
|
|
|
.help(
|
|
|
|
"Number of lamports per account.",
|
|
|
|
),
|
|
|
|
)
|
2018-12-11 19:47:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Parses a clap `ArgMatches` structure into a `Config`
|
|
|
|
/// # Arguments
|
|
|
|
/// * `matches` - command line arguments parsed by clap
|
|
|
|
/// # Panics
|
|
|
|
/// Panics if there is trouble parsing any of the arguments
|
|
|
|
pub fn extract_args<'a>(matches: &ArgMatches<'a>) -> Config {
|
|
|
|
let mut args = Config::default();
|
|
|
|
|
2019-05-03 15:00:19 -07:00
|
|
|
if let Some(addr) = matches.value_of("entrypoint") {
|
|
|
|
args.entrypoint_addr = solana_netutil::parse_host_port(addr).unwrap_or_else(|e| {
|
|
|
|
eprintln!("failed to parse entrypoint address: {}", e);
|
2018-12-11 19:47:32 -08:00
|
|
|
exit(1)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(addr) = matches.value_of("drone") {
|
2019-04-13 19:34:27 -07:00
|
|
|
args.drone_addr = solana_netutil::parse_host_port(addr).unwrap_or_else(|e| {
|
2018-12-11 19:47:32 -08:00
|
|
|
eprintln!("failed to parse drone address: {}", e);
|
|
|
|
exit(1)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if matches.is_present("identity") {
|
2019-10-10 16:01:03 -07:00
|
|
|
args.id = read_keypair_file(matches.value_of("identity").unwrap())
|
2018-12-11 19:47:32 -08:00
|
|
|
.expect("can't read client identity");
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(t) = matches.value_of("threads") {
|
|
|
|
args.threads = t.to_string().parse().expect("can't parse threads");
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(n) = matches.value_of("num-nodes") {
|
|
|
|
args.num_nodes = n.to_string().parse().expect("can't parse num-nodes");
|
|
|
|
}
|
|
|
|
|
2018-12-14 21:18:41 -08:00
|
|
|
if let Some(duration) = matches.value_of("duration") {
|
|
|
|
args.duration = Duration::new(
|
|
|
|
duration.to_string().parse().expect("can't parse duration"),
|
|
|
|
0,
|
|
|
|
);
|
2018-12-11 19:47:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(s) = matches.value_of("tx_count") {
|
|
|
|
args.tx_count = s.to_string().parse().expect("can't parse tx_account");
|
|
|
|
}
|
|
|
|
|
2019-01-03 14:16:06 -08:00
|
|
|
if let Some(t) = matches.value_of("thread-batch-sleep-ms") {
|
|
|
|
args.thread_batch_sleep_ms = t
|
|
|
|
.to_string()
|
|
|
|
.parse()
|
|
|
|
.expect("can't parse thread-batch-sleep-ms");
|
|
|
|
}
|
|
|
|
|
2018-12-11 19:47:32 -08:00
|
|
|
args.sustained = matches.is_present("sustained");
|
|
|
|
|
2019-06-11 18:47:35 -07:00
|
|
|
if let Some(s) = matches.value_of("write-client-keys") {
|
|
|
|
args.write_to_client_file = true;
|
|
|
|
args.client_ids_and_stake_file = s.to_string();
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(s) = matches.value_of("read-client-keys") {
|
|
|
|
assert!(!args.write_to_client_file);
|
|
|
|
args.read_from_client_file = true;
|
|
|
|
args.client_ids_and_stake_file = s.to_string();
|
|
|
|
}
|
|
|
|
|
2019-06-18 14:44:53 -07:00
|
|
|
if let Some(v) = matches.value_of("target_lamports_per_signature") {
|
|
|
|
args.target_lamports_per_signature = v.to_string().parse().expect("can't parse lamports");
|
|
|
|
}
|
|
|
|
|
2019-07-28 10:43:42 -07:00
|
|
|
args.use_move = matches.is_present("use-move");
|
|
|
|
|
2019-09-10 16:24:43 -07:00
|
|
|
if let Some(v) = matches.value_of("num_lamports_per_account") {
|
|
|
|
args.num_lamports_per_account = v.to_string().parse().expect("can't parse lamports");
|
|
|
|
}
|
|
|
|
|
2018-12-11 19:47:32 -08:00
|
|
|
args
|
|
|
|
}
|