Seed debug outputs cleanup (#460)

* DRY up

* iterate 66% less

* clarify debug! outputs

* less verbose peer queuing

Rationale: debug outputs that happen _a lot_ is nice if they're short and distinct, making them easier to pattern match / willfully ignore while reading through logs

* update comment to mention last weeks' added usecases

* .push() less
This commit is contained in:
Simon B 2017-12-11 15:38:46 +01:00 committed by AntiochP
parent 18fc1384de
commit 8b81a2f806
2 changed files with 19 additions and 26 deletions

View file

@ -84,32 +84,28 @@ impl Seeder {
let mon_loop = Timer::default() let mon_loop = Timer::default()
.interval(time::Duration::from_secs(30)) .interval(time::Duration::from_secs(30))
.for_each(move |_| { .for_each(move |_| {
let total_count = p2p_server.all_peers().len();
debug!( debug!(
LOGGER, LOGGER,
"monitor_peers: {} / {} / {}", "monitor_peers: {} most_work_peers, {} connected, {} total known",
p2p_server.most_work_peers().len(), p2p_server.most_work_peers().len(),
p2p_server.connected_peers().len(), p2p_server.connected_peers().len(),
p2p_server.all_peers().len(), total_count,
); );
let all_peers = p2p_server.all_peers(); let mut healthy_count = 0;
let healthy_count = all_peers let mut banned_count = 0;
.iter() let mut defunct_count = 0;
.filter(|x| x.flags == p2p::State::Healthy) for x in p2p_server.all_peers() {
.count(); if x.flags == p2p::State::Healthy { healthy_count += 1 }
let banned_count = all_peers else if x.flags == p2p::State::Banned { banned_count += 1 }
.iter() else if x.flags == p2p::State::Defunct { defunct_count += 1 };
.filter(|x| x.flags == p2p::State::Banned) }
.count();
let defunct_count = all_peers
.iter()
.filter(|x| x.flags == p2p::State::Defunct)
.count();
debug!( debug!(
LOGGER, LOGGER,
"monitor_peers: all - {}, healthy - {}, banned - {}, defunct - {}", "monitor_peers: all {} = {} healthy + {} banned + {} defunct",
all_peers.len(), total_count,
healthy_count, healthy_count,
banned_count, banned_count,
defunct_count, defunct_count,
@ -150,7 +146,7 @@ impl Seeder {
for p in peers { for p in peers {
debug!( debug!(
LOGGER, LOGGER,
"monitor_peers: queueing up {} for connection (may be already connected)", "monitor_peers: queue to soon try {}",
p.addr, p.addr,
); );
tx.unbounded_send(p.addr).unwrap(); tx.unbounded_send(p.addr).unwrap();

View file

@ -122,15 +122,12 @@ impl PeerStore {
peers.iter().take(count).cloned().collect() peers.iter().take(count).cloned().collect()
} }
/// List all known peers (for the /v1/peers api endpoint) /// List all known peers
/// Used for /v1/peers, for seed / sync (debug & if too few peers connected)
pub fn all_peers(&self) -> Vec<PeerData> { pub fn all_peers(&self) -> Vec<PeerData> {
let peers_iter = self.db self.db
.iter::<PeerData>(&to_key(PEER_PREFIX, &mut "".to_string().into_bytes())); .iter::<PeerData>(&to_key(PEER_PREFIX, &mut "".to_string().into_bytes()))
let mut peers = vec![]; .collect::<Vec<_>>()
for p in peers_iter {
peers.push(p);
}
peers
} }
/// Convenience method to load a peer data, update its status and save it /// Convenience method to load a peer data, update its status and save it