Update to hashes_per_tick computation, and tick duration datapoint (#7127)

This commit is contained in:
Pankaj Garg
2019-12-02 18:02:11 -08:00
committed by GitHub
parent 757425a360
commit a0eafa12e3
2 changed files with 21 additions and 24 deletions

View File

@ -1,7 +1,6 @@
//! The `Poh` module provides an object for generating a Proof of History.
use log::*;
use solana_sdk::hash::{hash, hashv, Hash};
use std::thread::{Builder, JoinHandle};
use std::time::{Duration, Instant};
pub struct Poh {
@ -84,34 +83,18 @@ impl Poh {
}
pub fn compute_hashes_per_tick(duration: Duration, hashes_sample_size: u64) -> u64 {
let num_cpu = sys_info::cpu_num().unwrap();
// calculate hash rate with the system under maximum load
info!(
"Running {} hashes in parallel on all threads...",
hashes_sample_size
);
let threads: Vec<JoinHandle<u64>> = (0..num_cpu)
.map(|_| {
Builder::new()
.name("solana-poh".to_string())
.spawn(move || {
let mut v = Hash::default();
let start = Instant::now();
for _ in 0..hashes_sample_size {
v = hash(&v.as_ref());
}
start.elapsed().as_millis() as u64
})
.unwrap()
})
.collect();
let avg_elapsed = (threads
.into_iter()
.map(|elapsed| elapsed.join().unwrap())
.sum::<u64>())
/ u64::from(num_cpu);
duration.as_millis() as u64 * hashes_sample_size / avg_elapsed
let mut v = Hash::default();
let start = Instant::now();
for _ in 0..hashes_sample_size {
v = hash(&v.as_ref());
}
let elapsed = start.elapsed().as_millis() as u64;
duration.as_millis() as u64 * hashes_sample_size / elapsed
}
#[cfg(test)]