Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit d5efbdb

Browse files
authored
Add timing measurement for gossip vote txn processing (#26163)
* add timing for gossip vote txn processing * fix build * fix too many arg error in clippy * atomic interval
1 parent 090e112 commit d5efbdb

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

core/src/cluster_info_vote_listener.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use {
4040
pubkey::Pubkey,
4141
signature::Signature,
4242
slot_hashes,
43+
timing::AtomicInterval,
4344
transaction::Transaction,
4445
},
4546
std::{
@@ -182,6 +183,47 @@ impl BankSendVotesStats {
182183
}
183184
}
184185

186+
#[derive(Default)]
187+
struct VoteProcessingTiming {
188+
gossip_txn_processing_time_us: u64,
189+
gossip_slot_confirming_time_us: u64,
190+
last_report: AtomicInterval,
191+
}
192+
193+
const VOTE_PROCESSING_REPORT_INTERVAL_MS: u64 = 1_000;
194+
195+
impl VoteProcessingTiming {
196+
fn reset(&mut self) {
197+
self.gossip_slot_confirming_time_us = 0;
198+
self.gossip_slot_confirming_time_us = 0;
199+
}
200+
201+
fn update(&mut self, vote_txn_processing_time_us: u64, vote_slot_confirming_time_us: u64) {
202+
self.gossip_txn_processing_time_us += vote_txn_processing_time_us;
203+
self.gossip_slot_confirming_time_us += vote_slot_confirming_time_us;
204+
205+
if self
206+
.last_report
207+
.should_update(VOTE_PROCESSING_REPORT_INTERVAL_MS)
208+
{
209+
datapoint_info!(
210+
"vote-processing-timing",
211+
(
212+
"vote_txn_processing_us",
213+
self.gossip_txn_processing_time_us as i64,
214+
i64
215+
),
216+
(
217+
"slot_confirming_time_us",
218+
self.gossip_slot_confirming_time_us as i64,
219+
i64
220+
),
221+
);
222+
self.reset();
223+
}
224+
}
225+
}
226+
185227
pub struct ClusterInfoVoteListener {
186228
thread_hdls: Vec<JoinHandle<()>>,
187229
}
@@ -450,6 +492,7 @@ impl ClusterInfoVoteListener {
450492
OptimisticConfirmationVerifier::new(bank_forks.read().unwrap().root());
451493
let mut last_process_root = Instant::now();
452494
let cluster_confirmed_slot_sender = Some(cluster_confirmed_slot_sender);
495+
let mut vote_processing_time = Some(VoteProcessingTiming::default());
453496
loop {
454497
if exit.load(Ordering::Relaxed) {
455498
return Ok(());
@@ -480,6 +523,7 @@ impl ClusterInfoVoteListener {
480523
&replay_votes_receiver,
481524
&bank_notification_sender,
482525
&cluster_confirmed_slot_sender,
526+
&mut vote_processing_time,
483527
);
484528
match confirmed_slots {
485529
Ok(confirmed_slots) => {
@@ -519,9 +563,11 @@ impl ClusterInfoVoteListener {
519563
replay_votes_receiver,
520564
&None,
521565
&None,
566+
&mut None,
522567
)
523568
}
524569

570+
#[allow(clippy::too_many_arguments)]
525571
fn listen_and_confirm_votes(
526572
gossip_vote_txs_receiver: &VerifiedVoteTransactionsReceiver,
527573
vote_tracker: &VoteTracker,
@@ -532,6 +578,7 @@ impl ClusterInfoVoteListener {
532578
replay_votes_receiver: &ReplayVoteReceiver,
533579
bank_notification_sender: &Option<BankNotificationSender>,
534580
cluster_confirmed_slot_sender: &Option<GossipDuplicateConfirmedSlotsSender>,
581+
vote_processing_time: &mut Option<VoteProcessingTiming>,
535582
) -> Result<ThresholdConfirmedSlots> {
536583
let mut sel = Select::new();
537584
sel.recv(gossip_vote_txs_receiver);
@@ -560,6 +607,7 @@ impl ClusterInfoVoteListener {
560607
verified_vote_sender,
561608
bank_notification_sender,
562609
cluster_confirmed_slot_sender,
610+
vote_processing_time,
563611
));
564612
}
565613
remaining_wait_time = remaining_wait_time.saturating_sub(start.elapsed());
@@ -682,6 +730,7 @@ impl ClusterInfoVoteListener {
682730
}
683731
}
684732

733+
#[allow(clippy::too_many_arguments)]
685734
fn filter_and_confirm_with_new_votes(
686735
vote_tracker: &VoteTracker,
687736
gossip_vote_txs: Vec<Transaction>,
@@ -692,11 +741,13 @@ impl ClusterInfoVoteListener {
692741
verified_vote_sender: &VerifiedVoteSender,
693742
bank_notification_sender: &Option<BankNotificationSender>,
694743
cluster_confirmed_slot_sender: &Option<GossipDuplicateConfirmedSlotsSender>,
744+
vote_processing_time: &mut Option<VoteProcessingTiming>,
695745
) -> ThresholdConfirmedSlots {
696746
let mut diff: HashMap<Slot, HashMap<Pubkey, bool>> = HashMap::new();
697747
let mut new_optimistic_confirmed_slots = vec![];
698748

699749
// Process votes from gossip and ReplayStage
750+
let mut gossip_vote_txn_processing_time = Measure::start("gossip_vote_processing_time");
700751
let votes = gossip_vote_txs
701752
.iter()
702753
.filter_map(vote_parser::parse_vote_transaction)
@@ -719,8 +770,11 @@ impl ClusterInfoVoteListener {
719770
cluster_confirmed_slot_sender,
720771
);
721772
}
773+
gossip_vote_txn_processing_time.stop();
774+
let gossip_vote_txn_processing_time_us = gossip_vote_txn_processing_time.as_us();
722775

723776
// Process all the slots accumulated from replay and gossip.
777+
let mut gossip_vote_slot_confirming_time = Measure::start("gossip_vote_slot_confirm_time");
724778
for (slot, mut slot_diff) in diff {
725779
let slot_tracker = vote_tracker.get_or_insert_slot_tracker(slot);
726780
{
@@ -768,6 +822,16 @@ impl ClusterInfoVoteListener {
768822

769823
w_slot_tracker.gossip_only_stake += gossip_only_stake
770824
}
825+
gossip_vote_slot_confirming_time.stop();
826+
let gossip_vote_slot_confirming_time_us = gossip_vote_slot_confirming_time.as_us();
827+
828+
match vote_processing_time {
829+
Some(ref mut vote_processing_time) => vote_processing_time.update(
830+
gossip_vote_txn_processing_time_us,
831+
gossip_vote_slot_confirming_time_us,
832+
),
833+
None => {}
834+
}
771835
new_optimistic_confirmed_slots
772836
}
773837

@@ -949,6 +1013,7 @@ mod tests {
9491013
&replay_votes_receiver,
9501014
&None,
9511015
&None,
1016+
&mut None,
9521017
)
9531018
.unwrap();
9541019

@@ -980,6 +1045,7 @@ mod tests {
9801045
&replay_votes_receiver,
9811046
&None,
9821047
&None,
1048+
&mut None,
9831049
)
9841050
.unwrap();
9851051

@@ -1062,6 +1128,7 @@ mod tests {
10621128
&replay_votes_receiver,
10631129
&None,
10641130
&None,
1131+
&mut None,
10651132
)
10661133
.unwrap();
10671134

@@ -1219,6 +1286,7 @@ mod tests {
12191286
&replay_votes_receiver,
12201287
&None,
12211288
&None,
1289+
&mut None,
12221290
)
12231291
.unwrap();
12241292

@@ -1319,6 +1387,7 @@ mod tests {
13191387
&replay_votes_receiver,
13201388
&None,
13211389
&None,
1390+
&mut None,
13221391
);
13231392
}
13241393
let slot_vote_tracker = vote_tracker.get_slot_vote_tracker(vote_slot).unwrap();
@@ -1409,6 +1478,7 @@ mod tests {
14091478
&verified_vote_sender,
14101479
&None,
14111480
&None,
1481+
&mut None,
14121482
);
14131483

14141484
// Setup next epoch
@@ -1455,6 +1525,7 @@ mod tests {
14551525
&verified_vote_sender,
14561526
&None,
14571527
&None,
1528+
&mut None,
14581529
);
14591530
}
14601531

0 commit comments

Comments
 (0)