Merge pull request #87 from garious/tcp-client
tx confirmed/sec ---> tx processed/sec
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
extern crate rayon;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate solana;
|
extern crate solana;
|
||||||
|
|
||||||
@ -8,6 +9,7 @@ use solana::transaction::Transaction;
|
|||||||
use std::io::stdin;
|
use std::io::stdin;
|
||||||
use std::net::{TcpStream, UdpSocket};
|
use std::net::{TcpStream, UdpSocket};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let addr = "127.0.0.1:8000";
|
let addr = "127.0.0.1:8000";
|
||||||
@ -21,16 +23,17 @@ fn main() {
|
|||||||
let stream = TcpStream::connect(addr).unwrap();
|
let stream = TcpStream::connect(addr).unwrap();
|
||||||
stream.set_nonblocking(true).expect("nonblocking");
|
stream.set_nonblocking(true).expect("nonblocking");
|
||||||
|
|
||||||
let mut acc = AccountantStub::new(addr, socket, stream);
|
let acc = AccountantStub::new(addr, socket, stream);
|
||||||
let last_id = acc.get_last_id().unwrap();
|
let last_id = acc.get_last_id().unwrap();
|
||||||
|
|
||||||
let mint_balance = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
let mint_balance = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
||||||
println!("Mint's Initial Balance {}", mint_balance);
|
println!("Mint's Initial Balance {}", mint_balance);
|
||||||
|
|
||||||
println!("Signing transactions...");
|
println!("Signing transactions...");
|
||||||
let txs = mint_balance;
|
let txs = 10_000;
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let transactions: Vec<_> = (0..txs)
|
let transactions: Vec<_> = (0..txs)
|
||||||
|
.into_par_iter()
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let rando_pubkey = KeyPair::new().pubkey();
|
let rando_pubkey = KeyPair::new().pubkey();
|
||||||
Transaction::new(&mint_keypair, rando_pubkey, 1, last_id)
|
Transaction::new(&mint_keypair, rando_pubkey, 1, last_id)
|
||||||
@ -48,9 +51,7 @@ fn main() {
|
|||||||
|
|
||||||
println!("Verify signatures...");
|
println!("Verify signatures...");
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
for tr in &transactions {
|
transactions.par_iter().for_each(|tr| assert!(tr.verify()));
|
||||||
assert!(tr.verify());
|
|
||||||
}
|
|
||||||
let duration = now.elapsed();
|
let duration = now.elapsed();
|
||||||
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
||||||
let bsvps = txs as f64 / ns as f64;
|
let bsvps = txs as f64 / ns as f64;
|
||||||
@ -63,21 +64,27 @@ fn main() {
|
|||||||
|
|
||||||
println!("Transferring 1 unit {} times...", txs);
|
println!("Transferring 1 unit {} times...", txs);
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut sig = Default::default();
|
let mut _sig = Default::default();
|
||||||
for tr in transactions {
|
for tr in transactions {
|
||||||
sig = tr.sig;
|
_sig = tr.sig;
|
||||||
acc.transfer_signed(tr).unwrap();
|
acc.transfer_signed(tr).unwrap();
|
||||||
}
|
}
|
||||||
println!("Waiting for last transaction to be confirmed...",);
|
println!("Waiting for last transaction to be confirmed...",);
|
||||||
if txs > 0 {
|
let mut val = mint_balance;
|
||||||
acc.wait_on_signature(&sig, &last_id).unwrap();
|
while val > mint_balance - txs {
|
||||||
|
val = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
||||||
}
|
}
|
||||||
|
//if txs > 0 {
|
||||||
|
// acc.wait_on_signature(&sig, &last_id).unwrap();
|
||||||
|
//}
|
||||||
|
|
||||||
let duration = now.elapsed();
|
let duration = now.elapsed();
|
||||||
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
||||||
let tps = (txs * 1_000_000_000) as f64 / ns as f64;
|
let tps = (txs * 1_000_000_000) as f64 / ns as f64;
|
||||||
println!("Done. {} tps!", tps);
|
println!("Done. {} tps!", tps);
|
||||||
let val = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
|
||||||
println!("Mint's Final Balance {}", val);
|
println!("Mint's Final Balance {}", val);
|
||||||
assert_eq!(val, mint_balance - txs);
|
assert_eq!(val, mint_balance - txs);
|
||||||
|
|
||||||
|
// Force the ledger to print on the server.
|
||||||
|
acc.get_last_id().unwrap();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user