Skip to content

Commit

Permalink
feat: pong internal rtt metric
Browse files Browse the repository at this point in the history
  • Loading branch information
niklaslong committed May 9, 2022
1 parent 79901d6 commit fe2833f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion metrics/src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with the snarkOS library. If not, see <https://www.gnu.org/licenses/>.

pub const GAUGE_NAMES: [&str; 4] = [blocks::HEIGHT, peers::CONNECTED, peers::CANDIDATE, peers::RESTRICTED];
pub const HISTOGRAM_NAMES: [&str; 1] = [internal_rtt::PING];
pub const HISTOGRAM_NAMES: [&str; 2] = [internal_rtt::PING, internal_rtt::PONG];

pub mod blocks {
pub const HEIGHT: &str = "snarkos_blocks_height_total";
Expand All @@ -29,4 +29,5 @@ pub mod peers {

pub mod internal_rtt {
pub const PING: &str = "snarkos_internal_rtt_ping";
pub const PONG: &str = "snarkos_internal_rtt_pong";
}
11 changes: 9 additions & 2 deletions network/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub enum LedgerRequest<N: Network> {
/// Heartbeat := (prover_router)
Heartbeat(ProverRouter<N>),
/// Pong := (peer_ip, node_type, status, is_fork, block_locators)
Pong(SocketAddr, NodeType, State, Option<bool>, BlockLocators<N>),
Pong(SocketAddr, NodeType, State, Option<bool>, BlockLocators<N>, Option<Instant>),
/// UnconfirmedBlock := (peer_ip, block, prover_router)
UnconfirmedBlock(SocketAddr, Block<N>, ProverRouter<N>),
}
Expand Down Expand Up @@ -251,11 +251,18 @@ impl<N: Network, E: Environment> Ledger<N, E> {
connected_peers,
);
}
LedgerRequest::Pong(peer_ip, node_type, status, is_fork, block_locators) => {
LedgerRequest::Pong(peer_ip, node_type, status, is_fork, block_locators, _rtt_start) => {
// Ensure the peer has been initialized in the ledger.
self.initialize_peer(peer_ip).await;
// Process the pong.
self.update_peer(peer_ip, node_type, status, is_fork, block_locators).await;

// Stop the clock on internal RTT.
#[cfg(any(feature = "test", feature = "prometheus"))]
metrics::histogram!(
metrics::internal_rtt::PONG,
_rtt_start.expect("rtt should be present with metrics enabled").elapsed()
);
}
LedgerRequest::UnconfirmedBlock(peer_ip, block, prover_router) => {
// Ensure the node is not peering.
Expand Down
10 changes: 9 additions & 1 deletion network/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,17 @@ impl<N: Network, E: Environment> Peer<N, E> {
}
},
Message::Pong(is_fork, block_locators) => {
// Unfortunately can't be feature-flagged because of the enum
// it's passed around in.
let _rtt_start_instant: Option<Instant> = None;

#[cfg(any(feature = "test", feature = "prometheus"))]
let _rtt_start_instant = Some(rtt_start);

// Perform the deferred non-blocking deserialization of block locators.
let request = match block_locators.deserialize().await {
// Route the `Pong` to the ledger.
Ok(block_locators) => LedgerRequest::Pong(peer_ip, peer.node_type, peer.status.get(), is_fork, block_locators),
Ok(block_locators) => LedgerRequest::Pong(peer_ip, peer.node_type, peer.status.get(), is_fork, block_locators, _rtt_start_instant),
// Route the `Failure` to the ledger.
Err(error) => LedgerRequest::Failure(peer_ip, format!("{}", error)),
};
Expand Down Expand Up @@ -640,6 +647,7 @@ impl<N: Network, E: Environment> Peer<N, E> {
warn!("[Ping] {}", error);
}


E::resources().deregister(ping_resource_id);
}));
}
Expand Down

0 comments on commit fe2833f

Please sign in to comment.