Skip to content

Commit

Permalink
use ahash
Browse files Browse the repository at this point in the history
  • Loading branch information
aeyakovenko committed Jan 21, 2022
1 parent 8ce3d95 commit 0ce08ac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2018"
[dependencies]
bincode = "1.3.1"
curve25519-dalek = { version = "2" }
ahash = "0.7.6"
dlopen = "0.1.8"
dlopen_derive = "0.1.4"
lazy_static = "1.4.0"
Expand Down
18 changes: 10 additions & 8 deletions perf/src/sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use {
perf_libs,
recycler::Recycler,
},
ahash::AHasher,
rand::{thread_rng, Rng},
rayon::ThreadPool,
solana_metrics::inc_new_counter_debug,
solana_rayon_threadlimit::get_thread_count,
solana_sdk::{
hash::Hash, message::MESSAGE_HEADER_LENGTH, pubkey::Pubkey, short_vec::decode_shortu16_len,
signature::Signature,
},
std::collections::hash_map::RandomState,
std::hash::BuildHasher,
std::hash::Hasher,
std::sync::atomic::{AtomicBool, AtomicU64, Ordering},
std::time::{Duration, Instant},
Expand Down Expand Up @@ -395,17 +395,17 @@ pub fn generate_offsets(

pub struct Deduper {
filter: Vec<AtomicU64>,
seed: RandomState,
seed: (u128, u128),
age: Instant,
max_age: Duration,
saturated: AtomicBool,
pub saturated: AtomicBool,
}

impl Deduper {
pub fn new(size: u32, max_age_ms: u64) -> Self {
let mut filter: Vec<AtomicU64> = Vec::with_capacity(size as usize);
filter.resize_with(size as usize, Default::default);
let seed = RandomState::new();
let seed = thread_rng().gen();
Self {
filter,
seed,
Expand All @@ -424,7 +424,7 @@ impl Deduper {
for i in &self.filter {
i.store(0, Ordering::Relaxed);
}
self.seed = RandomState::new();
self.seed = thread_rng().gen();
self.age = now;
self.saturated.store(false, Ordering::Relaxed);
}
Expand All @@ -435,7 +435,7 @@ impl Deduper {
if packet.meta.discard {
return;
}
let mut hasher = self.seed.build_hasher();
let mut hasher = AHasher::new_with_keys(self.seed.0, self.seed.1);
hasher.write(&packet.data[0..packet.meta.size]);
let hash = hasher.finish();
let len = self.filter.len();
Expand Down Expand Up @@ -1333,6 +1333,7 @@ mod tests {
}
assert!(filter.saturated.load(Ordering::Relaxed));
}

#[test]
fn test_dedup_false_positive() {
let filter = Deduper::new(1_000_000, 0);
Expand All @@ -1343,6 +1344,7 @@ mod tests {
discard += filter.dedup_packets(&mut batches) as usize;
println!("false positive rate: {}/{}", discard, i * 1024);
}
assert!(discard < 1);
//allow for 1 false positive even if extremely unlikely
assert!(discard < 2);
}
}

0 comments on commit 0ce08ac

Please sign in to comment.