From: Matt Corallo Date: Tue, 21 May 2019 15:07:53 +0000 (-0400) Subject: Never run the scan loop more than once every 15 seconds X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=b2521170a57b654f8df69aacf8ccdfdb744d5172;p=dnsseed-rust Never run the scan loop more than once every 15 seconds --- diff --git a/src/datastore.rs b/src/datastore.rs index 6255cd4..18aa0e6 100644 --- a/src/datastore.rs +++ b/src/datastore.rs @@ -487,9 +487,9 @@ impl Store { let cur_time = Instant::now(); let mut nodes = self.nodes.write().unwrap(); - for (state, state_nodes) in nodes.state_next_scan.iter_mut() { + for (idx, (state, state_nodes)) in nodes.state_next_scan.iter_mut().enumerate() { let cmp_time = cur_time - Duration::from_secs(self.get_u64(U64Setting::RescanInterval(*state))); - let split_point = cmp::min(cmp::min(results - res.len(), per_bucket_results), + let split_point = cmp::min(cmp::min(results - res.len(), results - (per_bucket_results * (AddressState::get_count() as usize - idx))), state_nodes.binary_search_by(|a| a.0.cmp(&cmp_time)).unwrap_or_else(|idx| idx)); let mut new_nodes = state_nodes.split_off(split_point); mem::swap(&mut new_nodes, state_nodes); diff --git a/src/main.rs b/src/main.rs index 2c4acee..e040b95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ mod peer; mod timeout_stream; mod datastore; -use std::env; +use std::{cmp, env}; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::sync::atomic::{Ordering, AtomicBool}; @@ -194,13 +194,14 @@ fn scan_net() { let store = unsafe { DATA_STORE.as_ref().unwrap() }; let mut scan_nodes = store.get_next_scan_nodes(); let per_iter_time = Duration::from_millis(1000 / store.get_u64(U64Setting::ConnsPerSec)); - let mut iter_time = Instant::now(); + let start_time = Instant::now(); + let mut iter_time = start_time; for node in scan_nodes.drain(..) { scan_node(iter_time, node); iter_time += per_iter_time; } - Delay::new(iter_time).then(|_| { + Delay::new(cmp::max(iter_time, start_time + Duration::from_secs(15))).then(|_| { let store = unsafe { DATA_STORE.as_ref().unwrap() }; store.save_data().then(|_| { if !START_SHUTDOWN.load(Ordering::Relaxed) {