hypersolana/gossip/benches/crds_gossip_pull.rs
behzad nouri c699bc9cab
down samples outgoing gossip pull requests (#33719)
Push message propagation has improved in recent versions of the gossip
code and we don't rely on pull requests as much as before. Handling pull
requests is also inefficient and expensive.
The commit reduces number of outgoing pull requests by down sampling.
2023-10-18 13:41:42 +00:00

58 lines
1.4 KiB
Rust

#![feature(test)]
extern crate test;
use {
rand::{thread_rng, Rng},
rayon::ThreadPoolBuilder,
solana_gossip::{
cluster_info::MAX_BLOOM_SIZE,
crds::{Crds, GossipRoute},
crds_gossip_pull::{CrdsFilter, CrdsGossipPull},
crds_value::CrdsValue,
},
solana_sdk::hash::Hash,
std::sync::RwLock,
test::Bencher,
};
#[bench]
fn bench_hash_as_u64(bencher: &mut Bencher) {
let hashes: Vec<_> = std::iter::repeat_with(Hash::new_unique)
.take(1000)
.collect();
bencher.iter(|| {
hashes
.iter()
.map(CrdsFilter::hash_as_u64)
.collect::<Vec<_>>()
});
}
#[bench]
fn bench_build_crds_filters(bencher: &mut Bencher) {
let thread_pool = ThreadPoolBuilder::new().build().unwrap();
let mut rng = thread_rng();
let crds_gossip_pull = CrdsGossipPull::default();
let mut crds = Crds::default();
let mut num_inserts = 0;
for _ in 0..90_000 {
if crds
.insert(
CrdsValue::new_rand(&mut rng, None),
rng.gen(),
GossipRoute::LocalMessage,
)
.is_ok()
{
num_inserts += 1;
}
}
assert_eq!(num_inserts, 90_000);
let crds = RwLock::new(crds);
bencher.iter(|| {
let filters = crds_gossip_pull.build_crds_filters(&thread_pool, &crds, MAX_BLOOM_SIZE);
assert_eq!(filters.len(), 16);
});
}