Client fixes, poll for unique last id and cache clients

So we don't keep running up the port range
This commit is contained in:
Stephen Akridge
2018-06-24 10:12:08 -07:00
committed by Greg Fitzgerald
parent be5f2ef9b9
commit c22ef50cae

View File

@ -82,12 +82,12 @@ fn sample_tx_count(
fn generate_and_send_txs( fn generate_and_send_txs(
client: &mut ThinClient, client: &mut ThinClient,
tx_clients: &Vec<ThinClient>,
keypair_pairs: &Vec<&[KeyPair]>, keypair_pairs: &Vec<&[KeyPair]>,
leader: &ReplicatedData, leader: &ReplicatedData,
txs: i64, txs: i64,
last_id: &mut Hash, last_id: &mut Hash,
threads: usize, threads: usize,
client_addr: Arc<RwLock<SocketAddr>>,
) { ) {
println!( println!(
"Signing transactions... {} {}", "Signing transactions... {} {}",
@ -115,24 +115,33 @@ fn generate_and_send_txs(
let transfer_start = Instant::now(); let transfer_start = Instant::now();
let sz = transactions.len() / threads; let sz = transactions.len() / threads;
let chunks: Vec<_> = transactions.chunks(sz).collect(); let chunks: Vec<_> = transactions.chunks(sz).collect();
chunks.into_par_iter().for_each(|txs| { chunks
println!( .into_par_iter()
"Transferring 1 unit {} times... to {:?}", .zip(tx_clients)
txs.len(), .for_each(|(txs, client)| {
leader.transactions_addr println!(
); "Transferring 1 unit {} times... to {:?}",
let client = mk_client(&client_addr, &leader); txs.len(),
for tx in txs { leader.transactions_addr
client.transfer_signed(tx.clone()).unwrap(); );
} for tx in txs {
}); client.transfer_signed(tx.clone()).unwrap();
}
});
println!( println!(
"Transfer done. {:?} ms {} tps", "Transfer done. {:?} ms {} tps",
duration_as_ms(&transfer_start.elapsed()), duration_as_ms(&transfer_start.elapsed()),
txs as f32 / (duration_as_s(&transfer_start.elapsed())) txs as f32 / (duration_as_s(&transfer_start.elapsed()))
); );
*last_id = client.get_last_id(); loop {
let new_id = client.get_last_id();
if *last_id != new_id {
*last_id = new_id;
break;
}
sleep(Duration::from_millis(100));
}
} }
fn main() { fn main() {
@ -266,18 +275,22 @@ fn main() {
}) })
.collect(); .collect();
let clients = (0..threads)
.map(|_| mk_client(&client_addr, &leader))
.collect();
// generate and send transactions for the specified duration // generate and send transactions for the specified duration
let time = Duration::new(time_sec, 0); let time = Duration::new(time_sec, 0);
let now = Instant::now(); let now = Instant::now();
while now.elapsed() < time { while now.elapsed() < time {
generate_and_send_txs( generate_and_send_txs(
&mut client, &mut client,
&clients,
&keypair_pairs, &keypair_pairs,
&leader, &leader,
txs, txs,
&mut last_id, &mut last_id,
threads, threads,
client_addr.clone(),
); );
} }