From 8d425e127bf5b752ffc5a124f7a05fb9495b6ce8 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Wed, 4 Apr 2018 17:29:22 -0600 Subject: [PATCH] Update benchmark to avoid write locks in sig duplicate detection --- src/accountant.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/accountant.rs b/src/accountant.rs index b4bbeb1e5b..1b1b281788 100644 --- a/src/accountant.rs +++ b/src/accountant.rs @@ -344,6 +344,8 @@ mod bench { use accountant::*; use rayon::prelude::*; use signature::KeyPairUtil; + use hash::hash; + use bincode::serialize; #[bench] fn process_verified_event_bench(bencher: &mut Bencher) { @@ -352,24 +354,27 @@ mod bench { // Create transactions between unrelated parties. let transactions: Vec<_> = (0..4096) .into_par_iter() - .map(|_| { + .map(|i| { // Seed the 'from' account. let rando0 = KeyPair::new(); let tr = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, mint.last_id()); acc.process_verified_transaction(&tr).unwrap(); - // Seed the 'to' account. + // Seed the 'to' account and a cell for its signature. + let last_id = hash(&serialize(&i).unwrap()); // Unique hash let rando1 = KeyPair::new(); - let tr = Transaction::new(&rando0, rando1.pubkey(), 1, mint.last_id()); + let tr = Transaction::new(&rando0, rando1.pubkey(), 1, last_id); acc.process_verified_transaction(&tr).unwrap(); // Finally, return a transaction that's unique - Transaction::new(&rando0, rando1.pubkey(), 1, mint.last_id()) + Transaction::new(&rando0, rando1.pubkey(), 1, last_id) }) .collect(); bencher.iter(|| { // Since benchmarker runs this multiple times, we need to clear the signatures. - acc.last_ids.write().unwrap().clear(); + for (_, sigs) in acc.last_ids.read().unwrap().iter() { + sigs.write().unwrap().clear(); + } transactions.par_iter().for_each(|tr| { acc.process_verified_transaction(tr).unwrap();