Skip to content

Commit

Permalink
change peer_manager not to recompute routing multiple times (#3891)
Browse files Browse the repository at this point in the history
We should fix peer_manager not to schedule multiple computations of routing table at the same time.
  • Loading branch information
pmnoxx authored Feb 3, 2021
1 parent 6b49b20 commit 6f5a164
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions chain/network/src/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub struct PeerManagerActor {
txns_since_last_block: Arc<AtomicUsize>,
pending_incoming_connections_counter: Arc<AtomicUsize>,
peer_counter: Arc<AtomicUsize>,
scheduled_routing_table_update: bool,
}

impl PeerManagerActor {
Expand Down Expand Up @@ -194,6 +195,7 @@ impl PeerManagerActor {
txns_since_last_block,
pending_incoming_connections_counter: Arc::new(AtomicUsize::new(0)),
peer_counter: Arc::new(AtomicUsize::new(0)),
scheduled_routing_table_update: false,
})
}

Expand Down Expand Up @@ -568,18 +570,22 @@ impl PeerManagerActor {
let ProcessEdgeResult { new_edge, schedule_computation } =
self.routing_table.process_edges(edges);

if let Some(duration) = schedule_computation {
near_performance_metrics::actix::run_later(
ctx,
file!(),
line!(),
duration,
|act, _ctx| {
act.routing_table.update();
#[cfg(feature = "metric_recorder")]
act.metric_recorder.set_graph(act.routing_table.get_raw_graph())
},
);
if !self.scheduled_routing_table_update {
if let Some(duration) = schedule_computation {
self.scheduled_routing_table_update = true;
near_performance_metrics::actix::run_later(
ctx,
file!(),
line!(),
duration,
|act, _ctx| {
act.scheduled_routing_table_update = false;
act.routing_table.update();
#[cfg(feature = "metric_recorder")]
act.metric_recorder.set_graph(act.routing_table.get_raw_graph())
},
);
}
}

new_edge
Expand Down

0 comments on commit 6f5a164

Please sign in to comment.