From 914fc785debf080093822de768b423a1f86ce42c Mon Sep 17 00:00:00 2001 From: boqiu <82121246@qq.com> Date: Tue, 20 Aug 2024 17:32:03 +0800 Subject: [PATCH] Add metrics for completed file sync --- node/sync/src/controllers/metrics.rs | 8 ++++++++ node/sync/src/controllers/mod.rs | 1 + node/sync/src/controllers/serial.rs | 11 ++++++----- node/sync/src/lib.rs | 8 ++++---- 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 node/sync/src/controllers/metrics.rs diff --git a/node/sync/src/controllers/metrics.rs b/node/sync/src/controllers/metrics.rs new file mode 100644 index 0000000..85e231f --- /dev/null +++ b/node/sync/src/controllers/metrics.rs @@ -0,0 +1,8 @@ +use std::sync::Arc; + +use metrics::{register_timer, Timer}; + +lazy_static::lazy_static! { + pub static ref SERIAL_SYNC_FILE_COMPLETED: Arc = register_timer("sync_controllers_serial_sync_file_completed"); + pub static ref SERIAL_SYNC_CHUNKS_COMPLETED: Arc = register_timer("sync_controllers_serial_sync_chunks_completed"); +} diff --git a/node/sync/src/controllers/mod.rs b/node/sync/src/controllers/mod.rs index ad2374f..0ade410 100644 --- a/node/sync/src/controllers/mod.rs +++ b/node/sync/src/controllers/mod.rs @@ -1,3 +1,4 @@ +mod metrics; mod peers; mod serial; diff --git a/node/sync/src/controllers/serial.rs b/node/sync/src/controllers/serial.rs index 91937ed..cb4f46f 100644 --- a/node/sync/src/controllers/serial.rs +++ b/node/sync/src/controllers/serial.rs @@ -1,6 +1,6 @@ use crate::context::SyncNetworkContext; use crate::controllers::peers::{PeerState, SyncPeers}; -use crate::controllers::{FileSyncGoal, FileSyncInfo}; +use crate::controllers::{metrics, FileSyncGoal, FileSyncInfo}; use crate::{Config, InstantWrapper}; use file_location_cache::FileLocationCache; use libp2p::swarm::DialError; @@ -311,15 +311,15 @@ impl SerialSyncController { .peers .add_new_peer_with_config(peer_id, addr.clone(), shard_config) { - info!(%self.tx_seq, %peer_id, %addr, "Found new peer"); + debug!(%self.tx_seq, %peer_id, %addr, "Found new peer"); true } else { // e.g. multiple `AnnounceFile` messages propagated - debug!(%self.tx_seq, %peer_id, %addr, "Found an existing peer"); + trace!(%self.tx_seq, %peer_id, %addr, "Found an existing peer"); false } } else { - debug!(%self.tx_seq, %peer_id, %addr, "Found peer without shard config"); + info!(%self.tx_seq, %peer_id, %addr, "Found peer without shard config"); false } } @@ -406,7 +406,6 @@ impl SerialSyncController { } pub async fn on_response(&mut self, from_peer_id: PeerId, response: ChunkArrayWithProof) { - debug!(%self.tx_seq, %from_peer_id, "Received RPC response"); if self.handle_on_response_mismatch(from_peer_id) { return; } @@ -511,6 +510,7 @@ impl SerialSyncController { // completed to download chunks if !self.goal.is_all_chunks() { self.state = SyncState::Completed; + metrics::SERIAL_SYNC_CHUNKS_COMPLETED.update_since(self.since.0); return; } @@ -523,6 +523,7 @@ impl SerialSyncController { Ok(true) => { info!(%self.tx_seq, "Succeeded to finalize file"); self.state = SyncState::Completed; + metrics::SERIAL_SYNC_FILE_COMPLETED.update_since(self.since.0); } Ok(false) => { warn!(?self.tx_id, %self.tx_seq, "Transaction reverted during finalize_tx"); diff --git a/node/sync/src/lib.rs b/node/sync/src/lib.rs index 3d53a1d..f2250ca 100644 --- a/node/sync/src/lib.rs +++ b/node/sync/src/lib.rs @@ -68,10 +68,10 @@ impl Default for Config { // serial sync config max_chunks_to_request: 2 * 1024, max_request_failures: 5, - peer_connect_timeout: Duration::from_secs(5), - peer_disconnect_timeout: Duration::from_secs(5), - peer_find_timeout: Duration::from_secs(5), - peer_chunks_download_timeout: Duration::from_secs(5), + peer_connect_timeout: Duration::from_secs(15), + peer_disconnect_timeout: Duration::from_secs(15), + peer_find_timeout: Duration::from_secs(30), + peer_chunks_download_timeout: Duration::from_secs(15), peer_wait_outgoing_connection_timeout: Duration::from_secs(10), peer_next_chunks_request_wait_timeout: Duration::from_secs(3),