WIP: New demo that makes better use of the parallelized accountant
This commit is contained in:
@ -4,21 +4,23 @@ extern crate isatty;
|
|||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
extern crate solana;
|
extern crate solana;
|
||||||
|
extern crate untrusted;
|
||||||
|
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use getopts::Options;
|
use getopts::Options;
|
||||||
use isatty::stdin_isatty;
|
use isatty::stdin_isatty;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use solana::accountant_stub::AccountantStub;
|
use solana::accountant_stub::AccountantStub;
|
||||||
use solana::mint::Mint;
|
use solana::mint::MintDemo;
|
||||||
use solana::signature::{KeyPair, KeyPairUtil};
|
use solana::signature::{KeyPair, KeyPairUtil};
|
||||||
use solana::transaction::Transaction;
|
use solana::transaction::Transaction;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::{stdin, Read};
|
use std::io::{stdin, Read};
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::thread::sleep;
|
use std::time::Instant;
|
||||||
use std::time::{Duration, Instant};
|
use untrusted::Input;
|
||||||
|
//use std::sync::mpsc::sync_channel;
|
||||||
|
|
||||||
fn print_usage(program: &str, opts: Options) {
|
fn print_usage(program: &str, opts: Options) {
|
||||||
let mut brief = format!("Usage: cat <mint.json> | {} [options]\n\n", program);
|
let mut brief = format!("Usage: cat <mint.json> | {} [options]\n\n", program);
|
||||||
@ -75,37 +77,33 @@ fn main() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mint: Mint = serde_json::from_str(&buffer).unwrap_or_else(|e| {
|
let demo: MintDemo = serde_json::from_reader(stdin()).unwrap_or_else(|e| {
|
||||||
eprintln!("failed to parse json: {}", e);
|
eprintln!("failed to parse json: {}", e);
|
||||||
exit(1);
|
exit(1);
|
||||||
});
|
});
|
||||||
let mint_keypair = mint.keypair();
|
|
||||||
let mint_pubkey = mint.pubkey();
|
|
||||||
|
|
||||||
let socket = UdpSocket::bind(&send_addr).unwrap();
|
let socket = UdpSocket::bind(&send_addr).unwrap();
|
||||||
println!("Stub new");
|
|
||||||
let acc = AccountantStub::new(&addr, socket);
|
let acc = AccountantStub::new(&addr, socket);
|
||||||
println!("Get last id");
|
println!("Get last id");
|
||||||
let last_id = acc.get_last_id().wait().unwrap();
|
let last_id = acc.get_last_id().wait().unwrap();
|
||||||
|
|
||||||
println!("Get Balance");
|
let txs = demo.users.len() / 2;
|
||||||
let mint_balance = acc.get_balance(&mint_pubkey).wait().unwrap();
|
let keypairs: Vec<_> = demo.users
|
||||||
println!("Mint's Initial Balance {}", mint_balance);
|
.into_par_iter()
|
||||||
|
.map(|(pkcs8, _)| KeyPair::from_pkcs8(Input::from(&pkcs8)).unwrap())
|
||||||
|
.collect();
|
||||||
|
let keypair_pairs: Vec<_> = keypairs.chunks(2).collect();
|
||||||
|
|
||||||
println!("Signing transactions...");
|
println!("Signing transactions...");
|
||||||
let txs = 1_000_000;
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let transactions: Vec<_> = (0..txs)
|
let transactions: Vec<_> = keypair_pairs
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|_| {
|
.map(|chunk| Transaction::new(&chunk[0], chunk[1].pubkey(), 1, last_id))
|
||||||
let rando_pubkey = KeyPair::new().pubkey();
|
|
||||||
Transaction::new(&mint_keypair, rando_pubkey, 1, last_id)
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
let duration = now.elapsed();
|
let duration = now.elapsed();
|
||||||
let ns = duration.as_secs() * 2_000_000_000 + u64::from(duration.subsec_nanos());
|
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
||||||
let bsps = f64::from(txs) / ns as f64;
|
let bsps = txs as f64 / ns as f64;
|
||||||
let nsps = ns as f64 / f64::from(txs);
|
let nsps = ns as f64 / txs as f64;
|
||||||
println!(
|
println!(
|
||||||
"Done. {} thousand signatures per second, {}us per signature",
|
"Done. {} thousand signatures per second, {}us per signature",
|
||||||
bsps * 1_000_000_f64,
|
bsps * 1_000_000_f64,
|
||||||
@ -116,33 +114,25 @@ fn main() {
|
|||||||
let now = Instant::now();
|
let now = 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();
|
||||||
let _: Vec<_> = chunks
|
chunks.into_par_iter().for_each(|trs| {
|
||||||
.into_par_iter()
|
println!("Transferring 1 unit {} times...", trs.len());
|
||||||
.map(|trs| {
|
let send_addr = "0.0.0.0:0";
|
||||||
println!("Transferring 1 unit {} times...", trs.len());
|
let socket = UdpSocket::bind(send_addr).unwrap();
|
||||||
let send_addr = "0.0.0.0:0";
|
//let (entry_info_sender, receiver) = sync_channel(1000);
|
||||||
let socket = UdpSocket::bind(send_addr).unwrap();
|
//let acc = AccountantStub::new_thin_client(&addr, socket, entry_info_sender);
|
||||||
let acc = AccountantStub::new(&addr, socket);
|
let acc = AccountantStub::new(&addr, socket);
|
||||||
for tr in trs {
|
for tr in trs {
|
||||||
acc.transfer_signed(tr.clone()).unwrap();
|
acc.transfer_signed(tr.clone()).unwrap();
|
||||||
}
|
}
|
||||||
()
|
|
||||||
})
|
println!("Waiting for the server to go idle...",);
|
||||||
.collect();
|
//while receiver.recv().unwrap().num_events > 0 {}
|
||||||
println!("Waiting for last transaction to be confirmed...",);
|
});
|
||||||
let mut val = mint_balance;
|
|
||||||
let mut prev = 0;
|
println!("Sent transactions {}", txs);
|
||||||
while val != prev {
|
|
||||||
sleep(Duration::from_millis(20));
|
|
||||||
prev = val;
|
|
||||||
val = acc.get_balance(&mint_pubkey).wait().unwrap();
|
|
||||||
}
|
|
||||||
println!("Mint's Final Balance {}", val);
|
|
||||||
let txs = mint_balance - val;
|
|
||||||
println!("Successful transactions {}", txs);
|
|
||||||
|
|
||||||
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. If no packets dropped, {} tps", tps);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user