From d415b171460d1d1a348c3e0b15b502441928c97a Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 26 Apr 2018 13:17:36 -0600 Subject: [PATCH] sleepless demo to complement sleepless nights 18 ktps on macbook pro, no gpu --- README.md | 3 +++ src/accountant_skel.rs | 10 ++++++++-- src/accountant_stub.rs | 11 +++++++++++ src/bin/client-demo.rs | 13 ++++--------- src/bin/genesis-demo.rs | 4 ++-- src/bin/mint-demo.rs | 4 ++-- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f476dbe5b..729d99ac7 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,9 @@ Now you can start the server: $ cat genesis.log | cargo run --release --bin solana-testnode > transactions0.log ``` +Wait a few seconds for the server to initialize. It will print "Ready." when it's safe +to start sending it transactions. + Then, in a separate shell, let's execute some transactions. Note we pass in the JSON configuration file here, not the genesis ledger. diff --git a/src/accountant_skel.rs b/src/accountant_skel.rs index 0178815e7..c3811b421 100644 --- a/src/accountant_skel.rs +++ b/src/accountant_skel.rs @@ -285,6 +285,7 @@ impl AccountantSkel { // Write new entries to the ledger and notify subscribers. obj.lock().unwrap().sync(); } + Ok(()) } @@ -328,8 +329,13 @@ impl AccountantSkel { &packet_recycler, &blob_recycler, ); - if e.is_err() && exit.load(Ordering::Relaxed) { - break; + if e.is_err() { + // Assume this was a timeout, so sync any empty entries. + skel.lock().unwrap().sync(); + + if exit.load(Ordering::Relaxed) { + break; + } } }); Ok(vec![t_receiver, t_responder, t_server, t_verifier]) diff --git a/src/accountant_stub.rs b/src/accountant_stub.rs index e23c1c385..2dd331da7 100644 --- a/src/accountant_stub.rs +++ b/src/accountant_stub.rs @@ -131,6 +131,17 @@ impl AccountantStub { /// Return the number of transactions the server processed since creating /// this stub instance. pub fn transaction_count(&mut self) -> u64 { + // Wait for at least one EntryInfo. + let mut done = false; + while !done { + let resp = self.recv_response().expect("recv response"); + if let &Response::EntryInfo(_) = &resp { + done = true; + } + self.process_response(resp); + } + + // Then take the rest. self.socket.set_nonblocking(true).expect("set nonblocking"); loop { match self.recv_response() { diff --git a/src/bin/client-demo.rs b/src/bin/client-demo.rs index 18a1a7f66..50f2e8a2e 100644 --- a/src/bin/client-demo.rs +++ b/src/bin/client-demo.rs @@ -18,8 +18,7 @@ use std::env; use std::io::{stdin, Read}; use std::net::UdpSocket; use std::process::exit; -use std::thread::sleep; -use std::time::{Duration, Instant}; +use std::time::Instant; use untrusted::Input; fn print_usage(program: &str, opts: Options) { @@ -129,17 +128,13 @@ fn main() { } }); + println!("Waiting for half the transactions to complete...",); let mut tx_count = acc.transaction_count(); - let mut prev_tx_count = tx_count + 1; - - println!("Waiting for the server to go idle...",); - while tx_count != prev_tx_count { - sleep(Duration::from_millis(20)); - prev_tx_count = tx_count; + while tx_count < transactions.len() as u64 / 2 { tx_count = acc.transaction_count(); } let txs = tx_count - initial_tx_count; - println!("Sent transactions {}", txs); + println!("Transactions processed {}", txs); let duration = now.elapsed(); let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos()); diff --git a/src/bin/genesis-demo.rs b/src/bin/genesis-demo.rs index 522a74aba..68c10b992 100644 --- a/src/bin/genesis-demo.rs +++ b/src/bin/genesis-demo.rs @@ -6,15 +6,15 @@ extern crate solana; extern crate untrusted; use isatty::stdin_isatty; +use rayon::prelude::*; +use solana::accountant::MAX_ENTRY_IDS; use solana::entry::{create_entry, next_tick}; use solana::event::Event; -use solana::accountant::MAX_ENTRY_IDS; use solana::mint::MintDemo; use solana::signature::{KeyPair, KeyPairUtil}; use solana::transaction::Transaction; use std::io::{stdin, Read}; use std::process::exit; -use rayon::prelude::*; use untrusted::Input; // Generate a ledger with lots and lots of accounts. diff --git a/src/bin/mint-demo.rs b/src/bin/mint-demo.rs index 1a2d9485a..1127ce19b 100644 --- a/src/bin/mint-demo.rs +++ b/src/bin/mint-demo.rs @@ -3,11 +3,11 @@ extern crate ring; extern crate serde_json; extern crate solana; +use rayon::prelude::*; +use ring::rand::SystemRandom; use solana::mint::{Mint, MintDemo}; use solana::signature::KeyPair; use std::io; -use rayon::prelude::*; -use ring::rand::SystemRandom; fn main() { let mut input_text = String::new();