Skip to content

Commit

Permalink
single threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
aeyakovenko committed Jan 21, 2022
1 parent 23c9b3a commit c18d823
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
15 changes: 7 additions & 8 deletions core/src/sigverify_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,18 @@ impl SigVerifyStage {
num_packets,
);

//50ns per packet with a single core
let mut dedup_time = Measure::start("sigverify_dedup_time");
let dedup_fail = deduper.dedup_packets(&mut batches) as usize;
dedup_time.stop();
let num_unique = num_packets.saturating_sub(dedup_fail);

let mut discard_time = Measure::start("sigverify_discard_time");
if num_packets > MAX_SIGVERIFY_BATCH {
if num_unique > MAX_SIGVERIFY_BATCH {
Self::discard_excess_packets(&mut batches, MAX_SIGVERIFY_BATCH)
};
let excess_fail = num_packets.saturating_sub(MAX_SIGVERIFY_BATCH);
let excess_fail = num_unique.saturating_sub(MAX_SIGVERIFY_BATCH);
discard_time.stop();

//100ns per packet with N cores
let mut dedup_time = Measure::start("sigverify_dedup_time");
let dedup_fail = deduper.dedup_packets(&mut batches) as usize;
dedup_time.stop();

let mut verify_batch_time = Measure::start("sigverify_batch_time");
let batches = verifier.verify_batches(batches);
sendr.send(batches)?;
Expand Down
25 changes: 21 additions & 4 deletions perf/benches/dedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use {
test::Bencher,
};

const NUM: usize = 4096;

fn test_packet_with_size(size: usize, rng: &mut ThreadRng) -> Vec<u8> {
// subtract 8 bytes because the length will get serialized as well
(0..size.checked_sub(8).unwrap())
Expand Down Expand Up @@ -39,7 +41,7 @@ fn bench_dedup_same_small_packets(bencher: &mut Bencher) {

let batches = to_packet_batches(
&std::iter::repeat(small_packet)
.take(4096)
.take(NUM)
.collect::<Vec<_>>(),
128,
);
Expand All @@ -54,7 +56,7 @@ fn bench_dedup_same_big_packets(bencher: &mut Bencher) {
let big_packet = test_packet_with_size(1024, &mut rng);

let batches = to_packet_batches(
&std::iter::repeat(big_packet).take(4096).collect::<Vec<_>>(),
&std::iter::repeat(big_packet).take(NUM).collect::<Vec<_>>(),
128,
);

Expand All @@ -67,7 +69,7 @@ fn bench_dedup_diff_small_packets(bencher: &mut Bencher) {
let mut rng = rand::thread_rng();

let batches = to_packet_batches(
&(0..4096)
&(0..NUM)
.map(|_| test_packet_with_size(128, &mut rng))
.collect::<Vec<_>>(),
128,
Expand All @@ -82,7 +84,7 @@ fn bench_dedup_diff_big_packets(bencher: &mut Bencher) {
let mut rng = rand::thread_rng();

let batches = to_packet_batches(
&(0..4096)
&(0..NUM)
.map(|_| test_packet_with_size(1024, &mut rng))
.collect::<Vec<_>>(),
128,
Expand All @@ -91,6 +93,21 @@ fn bench_dedup_diff_big_packets(bencher: &mut Bencher) {
do_bench_dedup_packets(bencher, batches);
}

#[bench]
#[ignore]
fn bench_dedup_baseline(bencher: &mut Bencher) {
let mut rng = rand::thread_rng();

let batches = to_packet_batches(
&(0..0)
.map(|_| test_packet_with_size(128, &mut rng))
.collect::<Vec<_>>(),
128,
);

do_bench_dedup_packets(bencher, batches);
}

#[bench]
#[ignore]
fn bench_dedup_reset(bencher: &mut Bencher) {
Expand Down
16 changes: 6 additions & 10 deletions perf/src/sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,16 +454,12 @@ impl Deduper {
}

pub fn dedup_packets(&self, batches: &mut [PacketBatch]) -> u64 {
use rayon::prelude::*;
// machine specific random offset to read the u64 from the packet signature
let count = AtomicU64::new(0);
PAR_THREAD_POOL.install(|| {
batches.into_par_iter().for_each(|batch| {
batch
.packets
.par_iter_mut()
.for_each(|p| self.dedup_packet(&count, p))
})
batches.iter_mut().for_each(|batch| {
batch
.packets
.iter_mut()
.for_each(|p| self.dedup_packet(&count, p))
});
count.load(Ordering::Relaxed)
}
Expand All @@ -479,7 +475,7 @@ pub fn ed25519_verify_cpu(batches: &mut [PacketBatch], reject_non_vote: bool) {
.packets
.par_iter_mut()
.for_each(|p| verify_packet(p, reject_non_vote))
})
});
});
inc_new_counter_debug!("ed25519_verify_cpu", packet_count);
}
Expand Down

0 comments on commit c18d823

Please sign in to comment.