2018-08-06 20:51:12 -07:00
|
|
|
#[macro_use]
|
2018-07-02 21:43:44 -07:00
|
|
|
extern crate clap;
|
2018-12-08 21:44:20 -08:00
|
|
|
|
2018-03-27 15:24:05 -07:00
|
|
|
extern crate solana;
|
2018-12-12 11:27:21 -08:00
|
|
|
extern crate solana_sdk;
|
2018-12-08 21:44:20 -08:00
|
|
|
|
2018-12-12 11:27:21 -08:00
|
|
|
mod bench;
|
|
|
|
mod cli;
|
2018-11-16 08:45:59 -08:00
|
|
|
|
2018-07-31 22:07:53 -07:00
|
|
|
use solana::client::mk_client;
|
2018-10-08 19:55:54 -07:00
|
|
|
use solana::cluster_info::{ClusterInfo, NodeInfo};
|
2018-12-06 12:52:47 -08:00
|
|
|
use solana::gossip_service::GossipService;
|
2018-07-27 21:37:53 -07:00
|
|
|
use solana::logger;
|
2018-07-03 21:14:08 -07:00
|
|
|
use solana::service::Service;
|
2018-12-03 10:26:28 -08:00
|
|
|
use solana::signature::GenKeys;
|
2018-12-12 11:27:21 -08:00
|
|
|
use solana::thin_client::poll_gossip_for_leader;
|
|
|
|
use solana_metrics;
|
|
|
|
use solana_sdk::signature::KeypairUtil;
|
|
|
|
|
2018-07-23 14:26:16 -07:00
|
|
|
use std::collections::VecDeque;
|
2018-04-19 07:06:19 -07:00
|
|
|
use std::process::exit;
|
2018-09-05 11:58:41 -07:00
|
|
|
use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize, Ordering};
|
2018-05-25 15:54:03 -07:00
|
|
|
use std::sync::{Arc, RwLock};
|
2018-05-04 11:11:39 -07:00
|
|
|
use std::thread::sleep;
|
2018-06-14 16:42:27 -07:00
|
|
|
use std::thread::Builder;
|
2018-05-04 11:11:39 -07:00
|
|
|
use std::time::Duration;
|
2018-04-26 12:17:36 -07:00
|
|
|
use std::time::Instant;
|
2018-03-04 00:21:40 -08:00
|
|
|
|
2018-12-12 11:27:21 -08:00
|
|
|
use crate::bench::*;
|
2018-08-04 20:25:23 -07:00
|
|
|
|
2018-12-12 11:27:21 -08:00
|
|
|
/// Creates a cluster and waits for the network to converge, returning the peers, leader, and gossip service
|
|
|
|
/// # Arguments
|
|
|
|
/// `leader` - the input leader node
|
|
|
|
/// `exit_signal` - atomic bool used to signal early exit to cluster
|
|
|
|
/// `num_nodes` - the number of nodes
|
|
|
|
/// # Panics
|
|
|
|
/// Panics if the spy node `RwLock` somehow ends up unreadable
|
|
|
|
fn converge(
|
2018-10-10 17:23:06 -07:00
|
|
|
leader: &NodeInfo,
|
2018-07-25 09:00:55 -07:00
|
|
|
exit_signal: &Arc<AtomicBool>,
|
2018-12-12 11:27:21 -08:00
|
|
|
num_nodes: usize,
|
|
|
|
) -> (Vec<NodeInfo>, Option<NodeInfo>, GossipService) {
|
|
|
|
//lets spy on the network
|
|
|
|
let (node, gossip_socket) = ClusterInfo::spy_node();
|
|
|
|
let mut spy_cluster_info = ClusterInfo::new(node);
|
|
|
|
spy_cluster_info.insert_info(leader.clone());
|
|
|
|
spy_cluster_info.set_leader(leader.id);
|
|
|
|
let spy_ref = Arc::new(RwLock::new(spy_cluster_info));
|
2018-12-14 08:13:45 -08:00
|
|
|
let gossip_service = GossipService::new(&spy_ref, None, gossip_socket, exit_signal.clone());
|
2018-12-12 11:27:21 -08:00
|
|
|
let mut v: Vec<NodeInfo> = vec![];
|
|
|
|
// wait for the network to converge, 30 seconds should be plenty
|
|
|
|
for _ in 0..30 {
|
2018-07-25 09:00:55 -07:00
|
|
|
{
|
2018-12-12 11:27:21 -08:00
|
|
|
let spy_ref = spy_ref.read().unwrap();
|
2018-07-25 09:27:03 -07:00
|
|
|
|
2018-12-12 11:27:21 -08:00
|
|
|
println!("{}", spy_ref.node_info_trace());
|
2018-07-25 09:27:03 -07:00
|
|
|
|
2018-12-12 11:27:21 -08:00
|
|
|
if spy_ref.leader_data().is_some() {
|
|
|
|
v = spy_ref.rpc_peers();
|
|
|
|
if v.len() >= num_nodes {
|
|
|
|
println!("CONVERGED!");
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
println!(
|
|
|
|
"{} node(s) discovered (looking for {} or more)",
|
|
|
|
v.len(),
|
|
|
|
num_nodes
|
|
|
|
);
|
|
|
|
}
|
2018-11-14 18:57:34 -08:00
|
|
|
}
|
2018-07-25 09:27:03 -07:00
|
|
|
}
|
2018-12-12 11:27:21 -08:00
|
|
|
sleep(Duration::new(1, 0));
|
2018-07-25 09:27:03 -07:00
|
|
|
}
|
2018-12-12 11:27:21 -08:00
|
|
|
let leader = spy_ref.read().unwrap().leader_data().cloned();
|
|
|
|
(v, leader, gossip_service)
|
2018-09-06 14:20:01 -07:00
|
|
|
}
|
|
|
|
|
2018-02-28 09:07:54 -08:00
|
|
|
fn main() {
|
2018-07-27 21:37:53 -07:00
|
|
|
logger::setup();
|
2018-11-16 08:45:59 -08:00
|
|
|
solana_metrics::set_panic_hook("bench-tps");
|
2018-03-03 20:15:42 -08:00
|
|
|
|
2018-12-12 11:27:21 -08:00
|
|
|
let matches = cli::build_args().get_matches();
|
|
|
|
|
|
|
|
let cfg = cli::extract_args(&matches);
|
|
|
|
|
|
|
|
let cli::Config {
|
|
|
|
network_addr: network,
|
|
|
|
drone_addr,
|
|
|
|
id,
|
|
|
|
threads,
|
|
|
|
num_nodes,
|
|
|
|
duration,
|
|
|
|
tx_count,
|
|
|
|
sustained,
|
|
|
|
reject_extra_nodes,
|
|
|
|
converge_only,
|
|
|
|
} = cfg;
|
2018-07-25 09:00:55 -07:00
|
|
|
|
2018-09-07 21:01:15 -07:00
|
|
|
println!("Looking for leader at {:?}", network);
|
2018-08-31 00:10:39 -07:00
|
|
|
let leader = poll_gossip_for_leader(network, None).expect("unable to find leader on network");
|
|
|
|
|
2018-07-23 13:49:24 -07:00
|
|
|
let exit_signal = Arc::new(AtomicBool::new(false));
|
2018-12-06 12:52:47 -08:00
|
|
|
let (nodes, leader, gossip_service) = converge(&leader, &exit_signal, num_nodes);
|
2018-07-21 20:23:52 -07:00
|
|
|
|
2018-09-08 12:50:43 -07:00
|
|
|
if nodes.len() < num_nodes {
|
2018-07-21 20:23:52 -07:00
|
|
|
println!(
|
|
|
|
"Error: Insufficient nodes discovered. Expecting {} or more",
|
|
|
|
num_nodes
|
|
|
|
);
|
|
|
|
exit(1);
|
|
|
|
}
|
2018-12-12 11:27:21 -08:00
|
|
|
if reject_extra_nodes && nodes.len() > num_nodes {
|
2018-09-14 11:40:05 -07:00
|
|
|
println!(
|
|
|
|
"Error: Extra nodes discovered. Expecting exactly {}",
|
|
|
|
num_nodes
|
|
|
|
);
|
|
|
|
exit(1);
|
2018-09-11 20:00:49 -07:00
|
|
|
}
|
|
|
|
|
2018-08-26 22:14:50 -07:00
|
|
|
if leader.is_none() {
|
2018-08-26 22:23:23 -07:00
|
|
|
println!("no leader");
|
|
|
|
exit(1);
|
2018-08-26 22:14:50 -07:00
|
|
|
}
|
2018-05-11 15:35:53 -07:00
|
|
|
|
2018-12-12 11:27:21 -08:00
|
|
|
if converge_only {
|
2018-07-19 09:21:31 -07:00
|
|
|
return;
|
|
|
|
}
|
2018-08-31 00:10:39 -07:00
|
|
|
|
2018-08-26 22:14:50 -07:00
|
|
|
let leader = leader.unwrap();
|
2018-07-19 09:21:31 -07:00
|
|
|
|
2018-11-15 13:23:26 -08:00
|
|
|
println!("leader RPC is at {} {}", leader.rpc, leader.id);
|
2018-06-29 14:12:26 -07:00
|
|
|
let mut client = mk_client(&leader);
|
2018-08-04 20:25:23 -07:00
|
|
|
let mut barrier_client = mk_client(&leader);
|
2018-03-05 14:34:15 -08:00
|
|
|
|
2018-06-11 13:04:51 -07:00
|
|
|
let mut seed = [0u8; 32];
|
2018-11-12 22:34:43 -08:00
|
|
|
seed.copy_from_slice(&id.public_key_bytes()[..32]);
|
2018-07-31 15:49:58 -07:00
|
|
|
let mut rnd = GenKeys::new(seed);
|
2018-05-08 21:03:05 -07:00
|
|
|
|
2018-10-05 16:45:27 -07:00
|
|
|
println!("Creating {} keypairs...", tx_count * 2);
|
2018-10-10 17:23:06 -07:00
|
|
|
let mut total_keys = 0;
|
|
|
|
let mut target = tx_count * 2;
|
|
|
|
while target > 0 {
|
|
|
|
total_keys += target;
|
|
|
|
target /= MAX_SPENDS_PER_TX;
|
|
|
|
}
|
2018-11-05 08:36:22 -08:00
|
|
|
let gen_keypairs = rnd.gen_n_keypairs(total_keys as u64);
|
2018-08-04 20:25:23 -07:00
|
|
|
let barrier_id = rnd.gen_n_keypairs(1).pop().unwrap();
|
|
|
|
|
|
|
|
println!("Get tokens...");
|
2018-09-06 14:20:01 -07:00
|
|
|
let num_tokens_per_account = 20;
|
|
|
|
|
|
|
|
// Sample the first keypair, see if it has tokens, if so then resume
|
|
|
|
// to avoid token loss
|
2018-10-10 17:23:06 -07:00
|
|
|
let keypair0_balance = client
|
|
|
|
.poll_get_balance(&gen_keypairs.last().unwrap().pubkey())
|
|
|
|
.unwrap_or(0);
|
2018-09-06 14:20:01 -07:00
|
|
|
|
|
|
|
if num_tokens_per_account > keypair0_balance {
|
2018-10-10 17:23:06 -07:00
|
|
|
let extra = num_tokens_per_account - keypair0_balance;
|
2018-11-05 08:36:22 -08:00
|
|
|
let total = extra * (gen_keypairs.len() as u64);
|
2018-11-16 19:56:26 -08:00
|
|
|
airdrop_tokens(&mut client, &drone_addr, &id, total);
|
2018-10-10 17:23:06 -07:00
|
|
|
println!("adding more tokens {}", extra);
|
|
|
|
fund_keys(&mut client, &id, &gen_keypairs, extra);
|
2018-09-06 14:20:01 -07:00
|
|
|
}
|
2018-10-10 17:23:06 -07:00
|
|
|
let start = gen_keypairs.len() - (tx_count * 2) as usize;
|
|
|
|
let keypairs = &gen_keypairs[start..];
|
2018-11-16 19:56:26 -08:00
|
|
|
airdrop_tokens(&mut barrier_client, &drone_addr, &barrier_id, 1);
|
2018-08-04 20:25:23 -07:00
|
|
|
|
|
|
|
println!("Get last ID...");
|
|
|
|
let mut last_id = client.get_last_id();
|
|
|
|
println!("Got last ID {:?}", last_id);
|
2018-03-05 14:34:15 -08:00
|
|
|
|
2018-07-22 16:20:07 -07:00
|
|
|
let first_tx_count = client.transaction_count();
|
|
|
|
println!("Initial transaction count {}", first_tx_count);
|
2018-04-17 15:41:58 -07:00
|
|
|
|
2018-06-15 10:12:38 -07:00
|
|
|
// Setup a thread per validator to sample every period
|
|
|
|
// collect the max transaction rate and total tx count seen
|
2018-06-14 16:42:27 -07:00
|
|
|
let maxes = Arc::new(RwLock::new(Vec::new()));
|
2018-06-02 09:59:39 -07:00
|
|
|
let sample_period = 1; // in seconds
|
2018-07-23 14:11:40 -07:00
|
|
|
println!("Sampling TPS every {} second...", sample_period);
|
2018-09-08 12:50:43 -07:00
|
|
|
let v_threads: Vec<_> = nodes
|
2018-06-14 16:42:27 -07:00
|
|
|
.into_iter()
|
|
|
|
.map(|v| {
|
2018-07-23 13:49:24 -07:00
|
|
|
let exit_signal = exit_signal.clone();
|
2018-06-14 16:42:27 -07:00
|
|
|
let maxes = maxes.clone();
|
|
|
|
Builder::new()
|
|
|
|
.name("solana-client-sample".to_string())
|
|
|
|
.spawn(move || {
|
2018-07-22 16:20:07 -07:00
|
|
|
sample_tx_count(&exit_signal, &maxes, first_tx_count, &v, sample_period);
|
2018-12-07 19:01:28 -08:00
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
})
|
|
|
|
.collect();
|
2018-06-14 16:42:27 -07:00
|
|
|
|
2018-10-10 17:23:06 -07:00
|
|
|
let shared_txs: SharedTransactions = Arc::new(RwLock::new(VecDeque::new()));
|
2018-07-23 14:26:16 -07:00
|
|
|
|
2018-07-25 09:00:55 -07:00
|
|
|
let shared_tx_active_thread_count = Arc::new(AtomicIsize::new(0));
|
2018-09-05 11:58:41 -07:00
|
|
|
let total_tx_sent_count = Arc::new(AtomicUsize::new(0));
|
2018-07-25 09:00:55 -07:00
|
|
|
|
2018-07-23 14:26:16 -07:00
|
|
|
let s_threads: Vec<_> = (0..threads)
|
|
|
|
.map(|_| {
|
|
|
|
let exit_signal = exit_signal.clone();
|
|
|
|
let shared_txs = shared_txs.clone();
|
|
|
|
let leader = leader.clone();
|
2018-07-25 09:00:55 -07:00
|
|
|
let shared_tx_active_thread_count = shared_tx_active_thread_count.clone();
|
2018-09-05 11:58:41 -07:00
|
|
|
let total_tx_sent_count = total_tx_sent_count.clone();
|
2018-07-23 14:26:16 -07:00
|
|
|
Builder::new()
|
|
|
|
.name("solana-client-sender".to_string())
|
|
|
|
.spawn(move || {
|
2018-07-25 09:00:55 -07:00
|
|
|
do_tx_transfers(
|
|
|
|
&exit_signal,
|
|
|
|
&shared_txs,
|
|
|
|
&leader,
|
|
|
|
&shared_tx_active_thread_count,
|
2018-09-05 11:58:41 -07:00
|
|
|
&total_tx_sent_count,
|
2018-07-25 09:00:55 -07:00
|
|
|
);
|
2018-12-07 19:01:28 -08:00
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
})
|
|
|
|
.collect();
|
2018-06-24 10:12:08 -07:00
|
|
|
|
2018-06-15 10:12:38 -07:00
|
|
|
// generate and send transactions for the specified duration
|
2018-09-11 14:13:10 -07:00
|
|
|
let start = Instant::now();
|
2018-07-20 11:47:57 -07:00
|
|
|
let mut reclaim_tokens_back_to_source_account = false;
|
2018-09-06 14:20:01 -07:00
|
|
|
let mut i = keypair0_balance;
|
2018-09-11 14:13:10 -07:00
|
|
|
while start.elapsed() < duration {
|
2018-11-05 08:36:22 -08:00
|
|
|
let balance = client.poll_get_balance(&id.pubkey()).unwrap_or(0);
|
2018-07-25 18:46:18 -07:00
|
|
|
metrics_submit_token_balance(balance);
|
2018-07-24 22:19:47 -07:00
|
|
|
|
2018-07-20 11:47:57 -07:00
|
|
|
// ping-pong between source and destination accounts for each loop iteration
|
2018-07-24 15:45:21 -07:00
|
|
|
// this seems to be faster than trying to determine the balance of individual
|
2018-07-20 11:47:57 -07:00
|
|
|
// accounts
|
2018-10-05 16:45:27 -07:00
|
|
|
let len = tx_count as usize;
|
2018-07-23 14:26:16 -07:00
|
|
|
generate_txs(
|
|
|
|
&shared_txs,
|
2018-10-05 16:45:27 -07:00
|
|
|
&keypairs[..len],
|
|
|
|
&keypairs[len..],
|
2018-07-11 22:21:51 -07:00
|
|
|
threads,
|
2018-07-20 11:47:57 -07:00
|
|
|
reclaim_tokens_back_to_source_account,
|
2018-10-10 17:23:06 -07:00
|
|
|
&leader,
|
2018-06-14 16:42:27 -07:00
|
|
|
);
|
2018-07-25 09:00:55 -07:00
|
|
|
// In sustained mode overlap the transfers with generation
|
|
|
|
// this has higher average performance but lower peak performance
|
|
|
|
// in tested environments.
|
|
|
|
if !sustained {
|
|
|
|
while shared_tx_active_thread_count.load(Ordering::Relaxed) > 0 {
|
|
|
|
sleep(Duration::from_millis(100));
|
|
|
|
}
|
|
|
|
}
|
2018-08-04 20:25:23 -07:00
|
|
|
// It's not feasible (would take too much time) to confirm each of the `tx_count / 2`
|
|
|
|
// transactions sent by `generate_txs()` so instead send and confirm a single transaction
|
|
|
|
// to validate the network is still functional.
|
|
|
|
send_barrier_transaction(&mut barrier_client, &mut last_id, &barrier_id);
|
2018-09-06 14:20:01 -07:00
|
|
|
|
|
|
|
i += 1;
|
|
|
|
if should_switch_directions(num_tokens_per_account, i) {
|
|
|
|
reclaim_tokens_back_to_source_account = !reclaim_tokens_back_to_source_account;
|
|
|
|
}
|
2018-06-14 16:42:27 -07:00
|
|
|
}
|
|
|
|
|
2018-06-15 10:12:38 -07:00
|
|
|
// Stop the sampling threads so it will collect the stats
|
2018-07-23 13:49:24 -07:00
|
|
|
exit_signal.store(true, Ordering::Relaxed);
|
2018-07-28 16:28:55 -07:00
|
|
|
|
|
|
|
println!("Waiting for validator threads...");
|
2018-06-14 16:42:27 -07:00
|
|
|
for t in v_threads {
|
2018-07-28 16:28:55 -07:00
|
|
|
if let Err(err) = t.join() {
|
|
|
|
println!(" join() failed with: {:?}", err);
|
|
|
|
}
|
2018-06-14 16:42:27 -07:00
|
|
|
}
|
|
|
|
|
2018-07-23 14:26:16 -07:00
|
|
|
// join the tx send threads
|
2018-07-28 16:28:55 -07:00
|
|
|
println!("Waiting for transmit threads...");
|
2018-07-23 14:26:16 -07:00
|
|
|
for t in s_threads {
|
2018-07-28 16:28:55 -07:00
|
|
|
if let Err(err) = t.join() {
|
|
|
|
println!(" join() failed with: {:?}", err);
|
|
|
|
}
|
2018-07-23 14:26:16 -07:00
|
|
|
}
|
|
|
|
|
2018-11-05 08:36:22 -08:00
|
|
|
let balance = client.poll_get_balance(&id.pubkey()).unwrap_or(0);
|
2018-07-25 18:46:18 -07:00
|
|
|
metrics_submit_token_balance(balance);
|
2018-07-24 22:19:47 -07:00
|
|
|
|
2018-09-05 11:58:41 -07:00
|
|
|
compute_and_report_stats(
|
|
|
|
&maxes,
|
|
|
|
sample_period,
|
2018-09-11 14:13:10 -07:00
|
|
|
&start.elapsed(),
|
2018-09-05 11:58:41 -07:00
|
|
|
total_tx_sent_count.load(Ordering::Relaxed),
|
|
|
|
);
|
2018-06-14 16:42:27 -07:00
|
|
|
|
2018-10-08 19:55:54 -07:00
|
|
|
// join the cluster_info client threads
|
2018-12-06 12:52:47 -08:00
|
|
|
gossip_service.join().unwrap();
|
2018-05-25 15:54:03 -07:00
|
|
|
}
|
|
|
|
|
2018-09-06 14:20:01 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
#[test]
|
|
|
|
fn test_switch_directions() {
|
|
|
|
assert_eq!(should_switch_directions(20, 0), false);
|
|
|
|
assert_eq!(should_switch_directions(20, 1), false);
|
|
|
|
assert_eq!(should_switch_directions(20, 14), false);
|
|
|
|
assert_eq!(should_switch_directions(20, 15), true);
|
|
|
|
assert_eq!(should_switch_directions(20, 16), false);
|
|
|
|
assert_eq!(should_switch_directions(20, 19), false);
|
|
|
|
assert_eq!(should_switch_directions(20, 20), true);
|
|
|
|
assert_eq!(should_switch_directions(20, 21), false);
|
|
|
|
assert_eq!(should_switch_directions(20, 99), false);
|
|
|
|
assert_eq!(should_switch_directions(20, 100), true);
|
|
|
|
assert_eq!(should_switch_directions(20, 101), false);
|
|
|
|
}
|
|
|
|
}
|