From 028b43818e5fee616f33642e1b35653c63431b19 Mon Sep 17 00:00:00 2001 From: Brian Cho Date: Thu, 22 Feb 2024 22:49:18 -0800 Subject: [PATCH 1/3] Add verify time histogram --- consensus/src/counters.rs | 15 +++++++++++++++ consensus/src/round_manager.rs | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/consensus/src/counters.rs b/consensus/src/counters.rs index d621c4ee103e5..836f8da887887 100644 --- a/consensus/src/counters.rs +++ b/consensus/src/counters.rs @@ -636,6 +636,21 @@ pub static WAIT_DURATION_S: Lazy = Lazy::new(|| { CONSENSUS_WAIT_DURATION_BUCKETS.to_vec()).unwrap()) }); +const VERIFY_BUCKETS: &[f64] = &[ + 0.0001, 0.00025, 0.0005, 0.001, 0.0015, 0.002, 0.0025, 0.003, 0.0035, 0.004, 0.005, 0.006, + 0.007, 0.008, 0.009, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, +]; + +pub static VERIFY_MSG: Lazy = Lazy::new(|| { + register_histogram_vec!( + "aptos_consensus_verify_msg", + "Histogram of the time it takes to verify a message", + &["msg"], + VERIFY_BUCKETS.to_vec() + ) + .unwrap() +}); + /////////////////// // CHANNEL COUNTERS /////////////////// diff --git a/consensus/src/round_manager.rs b/consensus/src/round_manager.rs index f02f3178f4835..cac83438f8c95 100644 --- a/consensus/src/round_manager.rs +++ b/consensus/src/round_manager.rs @@ -85,17 +85,24 @@ impl UnverifiedEvent { max_num_batches: usize, max_batch_expiry_gap_usecs: u64, ) -> Result { + let start_time = Instant::now(); Ok(match self { //TODO: no need to sign and verify the proposal UnverifiedEvent::ProposalMsg(p) => { if !self_message { p.verify(validator, quorum_store_enabled)?; + counters::VERIFY_MSG + .with_label_values(&["proposal"]) + .observe(start_time.elapsed().as_secs_f64()); } VerifiedEvent::ProposalMsg(p) }, UnverifiedEvent::VoteMsg(v) => { if !self_message { v.verify(validator)?; + counters::VERIFY_MSG + .with_label_values(&["vote"]) + .observe(start_time.elapsed().as_secs_f64()); } VerifiedEvent::VoteMsg(v) }, @@ -104,6 +111,9 @@ impl UnverifiedEvent { UnverifiedEvent::BatchMsg(b) => { if !self_message { b.verify(peer_id, max_num_batches)?; + counters::VERIFY_MSG + .with_label_values(&["batch"]) + .observe(start_time.elapsed().as_secs_f64()); } VerifiedEvent::BatchMsg(b) }, @@ -115,12 +125,18 @@ impl UnverifiedEvent { max_batch_expiry_gap_usecs, validator, )?; + counters::VERIFY_MSG + .with_label_values(&["signed_batch"]) + .observe(start_time.elapsed().as_secs_f64()); } VerifiedEvent::SignedBatchInfo(sd) }, UnverifiedEvent::ProofOfStoreMsg(p) => { if !self_message { p.verify(max_num_batches, validator)?; + counters::VERIFY_MSG + .with_label_values(&["proof_of_store"]) + .observe(start_time.elapsed().as_secs_f64()); } VerifiedEvent::ProofOfStoreMsg(p) }, From f861565d24a8d3e578f1fb5c8a5cb59294e5c30e Mon Sep 17 00:00:00 2001 From: Brian Cho Date: Fri, 23 Feb 2024 12:46:51 -0800 Subject: [PATCH 2/3] use par_iter --- consensus/consensus-types/src/common.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/consensus/consensus-types/src/common.rs b/consensus/consensus-types/src/common.rs index 180edeb342b84..9fb8ed093ddb4 100644 --- a/consensus/consensus-types/src/common.rs +++ b/consensus/consensus-types/src/common.rs @@ -285,9 +285,10 @@ impl Payload { match (quorum_store_enabled, self) { (false, Payload::DirectMempool(_)) => Ok(()), (true, Payload::InQuorumStore(proof_with_status)) => { - for proof in proof_with_status.proofs.iter() { - proof.verify(validator)?; - } + proof_with_status + .proofs + .par_iter() + .try_for_each(|proof| proof.verify(validator))?; Ok(()) }, (true, Payload::InQuorumStoreWithLimit(proof_with_status)) => { From 5569cc43e269465e3217523d35756fdf482655bd Mon Sep 17 00:00:00 2001 From: Brian Cho Date: Fri, 23 Feb 2024 22:45:54 -0800 Subject: [PATCH 3/3] min_len 4 --- consensus/consensus-types/src/common.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/consensus/consensus-types/src/common.rs b/consensus/consensus-types/src/common.rs index 9fb8ed093ddb4..612fe3cfd40b3 100644 --- a/consensus/consensus-types/src/common.rs +++ b/consensus/consensus-types/src/common.rs @@ -288,6 +288,7 @@ impl Payload { proof_with_status .proofs .par_iter() + .with_min_len(4) .try_for_each(|proof| proof.verify(validator))?; Ok(()) },