Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[consensus] verify proposals in parallel, add counters #12209

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions consensus/consensus-types/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ 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()
.with_min_len(4)
.try_for_each(|proof| proof.verify(validator))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to chunk them instead of every single one, spawn task is non trivial as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, rayon spawn is very expensive - especially done on small item. Use a min size with the parallel item.

Ok(())
},
(true, Payload::InQuorumStoreWithLimit(proof_with_status)) => {
Expand Down
15 changes: 15 additions & 0 deletions consensus/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,21 @@ pub static WAIT_DURATION_S: Lazy<DurationHistogram> = 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<HistogramVec> = 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
///////////////////
Expand Down
16 changes: 16 additions & 0 deletions consensus/src/round_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,24 @@ impl UnverifiedEvent {
max_num_batches: usize,
max_batch_expiry_gap_usecs: u64,
) -> Result<VerifiedEvent, VerifyError> {
let start_time = Instant::now();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use monitor! macro instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we want to create a separate one for each event. Isn't it a bit cleaner to have a separate HistogramVec?

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)
},
Expand All @@ -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)
},
Expand All @@ -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)
},
Expand Down
Loading