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

Use VecDeque instead of Vec in sigverify stage #22538

Merged
merged 1 commit into from Jan 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions core/benches/sigverify_stage.rs
@@ -1,4 +1,5 @@
#![feature(test)]
#![allow(clippy::integer_arithmetic)]

extern crate solana_core;
extern crate test;
Expand All @@ -19,8 +20,7 @@ use {
test::Bencher,
};

#[bench]
fn bench_packet_discard(bencher: &mut Bencher) {
fn run_bench_packet_discard(num_ips: usize, bencher: &mut Bencher) {
solana_logger::setup();
let len = 30 * 1000;
let chunk_size = 1024;
Expand All @@ -29,7 +29,7 @@ fn bench_packet_discard(bencher: &mut Bencher) {

let mut total = 0;

let ips: Vec<_> = (0..10_000)
let ips: Vec<_> = (0..num_ips)
.into_iter()
.map(|_| {
let mut addr = [0u16; 8];
Expand Down Expand Up @@ -57,6 +57,16 @@ fn bench_packet_discard(bencher: &mut Bencher) {
});
}

#[bench]
fn bench_packet_discard_many_senders(bencher: &mut Bencher) {
run_bench_packet_discard(1000, bencher);
}

#[bench]
fn bench_packet_discard_single_sender(bencher: &mut Bencher) {
run_bench_packet_discard(1, bencher);
}

#[bench]
fn bench_sigverify_stage(bencher: &mut Bencher) {
solana_logger::setup();
Expand Down
10 changes: 5 additions & 5 deletions core/src/sigverify_stage.rs
Expand Up @@ -13,7 +13,7 @@ use {
solana_sdk::timing,
solana_streamer::streamer::{self, PacketBatchReceiver, StreamerError},
std::{
collections::HashMap,
collections::{HashMap, VecDeque},
thread::{self, Builder, JoinHandle},
time::Instant,
},
Expand Down Expand Up @@ -144,17 +144,17 @@ impl SigVerifyStage {
for (packet_index, packets) in batch.packets.iter().enumerate() {
let e = received_ips
.entry(packets.meta.addr().ip())
.or_insert_with(Vec::new);
e.push((batch_index, packet_index));
.or_insert_with(VecDeque::new);
e.push_back((batch_index, packet_index));
}
}
let mut batch_len = 0;
while batch_len < max_packets {
for (_ip, indexes) in received_ips.iter_mut() {
if !indexes.is_empty() {
indexes.remove(0);
indexes.pop_front();
batch_len += 1;
if batch_len >= MAX_SIGVERIFY_BATCH {
if batch_len >= max_packets {
break;
}
}
Expand Down