Switch to UDP from TCP

And remove all the sleep()'ing around.
This commit is contained in:
Greg Fitzgerald
2018-03-01 12:23:27 -07:00
parent 7111aa3b18
commit c9cc4b4369
5 changed files with 121 additions and 77 deletions

View File

@@ -2,37 +2,41 @@ extern crate silk;
fn main() {
use silk::accountant_stub::AccountantStub;
use std::thread::sleep;
use std::time::Duration;
use std::time::Instant;
use std::net::UdpSocket;
use silk::log::{generate_keypair, get_pubkey};
let addr = "127.0.0.1:8000";
let mut acc = AccountantStub::new(addr);
let send_addr = "127.0.0.1:8001";
let socket = UdpSocket::bind(send_addr).unwrap();
let mut acc = AccountantStub::new(addr, socket);
let alice_keypair = generate_keypair();
let bob_keypair = generate_keypair();
let txs = 10_000;
println!("Depositing {} units in Alice's account...", txs);
acc.deposit(txs, &alice_keypair).unwrap();
//acc.deposit(1_000, &bob_keypair).unwrap();
println!("Done.");
sleep(Duration::from_millis(30));
let alice_pubkey = get_pubkey(&alice_keypair);
let bob_pubkey = get_pubkey(&bob_keypair);
println!("Transferring 1 unit {} times...", txs);
for _ in 0..txs {
acc.transfer(1, &alice_keypair, bob_pubkey).unwrap();
}
let txs = 10_000;
println!("Depositing {} units in Alice's account...", txs);
let sig = acc.deposit(txs, &alice_keypair).unwrap();
acc.wait_on_signature(&sig).unwrap();
assert_eq!(acc.get_balance(&alice_pubkey).unwrap(), txs);
println!("Done.");
sleep(Duration::from_millis(20));
let mut alice_val = acc.get_balance(&alice_pubkey).unwrap();
while alice_val > 0 {
println!("Checking on Alice's Balance {}", alice_val);
sleep(Duration::from_millis(20));
alice_val = acc.get_balance(&alice_pubkey).unwrap();
println!("Transferring 1 unit {} times...", txs);
let now = Instant::now();
let mut sig = sig;
for i in 0..txs {
sig = acc.transfer(1, &alice_keypair, bob_pubkey).unwrap();
if i % 200 == 1 {
acc.wait_on_signature(&sig).unwrap();
}
}
println!("Done. Checking balances.");
println!("Waiting for last transaction to be confirmed...",);
acc.wait_on_signature(&sig).unwrap();
let duration = now.elapsed();
let ns = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;
let tps = (txs * 1_000_000_000) as f64 / ns as f64;
println!("Done. {} tps!", tps);
println!(
"Alice's Final Balance {}",
acc.get_balance(&alice_pubkey).unwrap()