From a0eafa12e315ca3cfbb5fa7701c43dcf0cb8b4b4 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Mon, 2 Dec 2019 18:02:11 -0800 Subject: [PATCH] Update to hashes_per_tick computation, and tick duration datapoint (#7127) --- core/src/poh_service.rs | 14 ++++++++++++++ ledger/src/poh.rs | 31 +++++++------------------------ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/core/src/poh_service.rs b/core/src/poh_service.rs index aa82a1a1b..10136ef80 100644 --- a/core/src/poh_service.rs +++ b/core/src/poh_service.rs @@ -2,11 +2,13 @@ //! "ticks", a measure of time in the PoH stream use crate::poh_recorder::PohRecorder; use core_affinity; +use solana_sdk::clock::DEFAULT_TICKS_PER_SLOT; use solana_sdk::poh_config::PohConfig; use solana_sys_tuner; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; use std::thread::{self, sleep, Builder, JoinHandle}; +use std::time::Instant; pub struct PohService { tick_producer: JoinHandle<()>, @@ -87,10 +89,22 @@ impl PohService { fn tick_producer(poh_recorder: Arc>, poh_exit: &AtomicBool) { let poh = poh_recorder.lock().unwrap().poh.clone(); + let mut now = Instant::now(); + let mut num_ticks = 0; loop { if poh.lock().unwrap().hash(NUM_HASHES_PER_BATCH) { // Lock PohRecorder only for the final hash... poh_recorder.lock().unwrap().tick(); + num_ticks += 1; + if num_ticks >= DEFAULT_TICKS_PER_SLOT * 2 { + datapoint_debug!( + "poh-service", + ("ticks", num_ticks as i64, i64), + ("elapsed_ms", now.elapsed().as_millis() as i64, i64), + ); + num_ticks = 0; + now = Instant::now(); + } if poh_exit.load(Ordering::Relaxed) { break; } diff --git a/ledger/src/poh.rs b/ledger/src/poh.rs index bce402013..eaf075473 100644 --- a/ledger/src/poh.rs +++ b/ledger/src/poh.rs @@ -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> = (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::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)]