For all code paths (gossip push, pull, purge, etc) that remove or override a crds value, it is necessary to record hash of values purged from crds table, in order to exclude them from subsequent pull-requests; otherwise the next pull request will likely return outdated values, wasting bandwidth: https://github.com/solana-labs/solana/blob/ed51cde37/core/src/crds_gossip_pull.rs#L486-L491 Currently this is done all over the place in multiple modules, and this has caused bugs in the past where purged values were not recorded. This commit encapsulated this bookkeeping into crds module, so that any code path which removes or overrides a crds value, also records the hash of purged value in-place.
74 lines
1.8 KiB
Rust
74 lines
1.8 KiB
Rust
#![feature(test)]
|
|
|
|
extern crate test;
|
|
|
|
use rand::{thread_rng, Rng};
|
|
use solana_core::{
|
|
crds::{Crds, VersionedCrdsValue},
|
|
crds_shards::CrdsShards,
|
|
crds_value::CrdsValue,
|
|
};
|
|
use solana_sdk::timing::timestamp;
|
|
use std::iter::repeat_with;
|
|
use test::Bencher;
|
|
|
|
const CRDS_SHARDS_BITS: u32 = 8;
|
|
|
|
fn new_test_crds_value<R: Rng>(rng: &mut R) -> VersionedCrdsValue {
|
|
let value = CrdsValue::new_rand(rng, None);
|
|
let label = value.label();
|
|
let mut crds = Crds::default();
|
|
crds.insert(value, timestamp()).unwrap();
|
|
crds.get(&label).cloned().unwrap()
|
|
}
|
|
|
|
fn bench_crds_shards_find(bencher: &mut Bencher, num_values: usize, mask_bits: u32) {
|
|
let mut rng = thread_rng();
|
|
let values: Vec<_> = repeat_with(|| new_test_crds_value(&mut rng))
|
|
.take(num_values)
|
|
.collect();
|
|
let mut shards = CrdsShards::new(CRDS_SHARDS_BITS);
|
|
for (index, value) in values.iter().enumerate() {
|
|
assert!(shards.insert(index, value));
|
|
}
|
|
bencher.iter(|| {
|
|
let mask = rng.gen();
|
|
let _hits = shards.find(mask, mask_bits).count();
|
|
});
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_crds_shards_find_0(bencher: &mut Bencher) {
|
|
bench_crds_shards_find(bencher, 100_000, 0);
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_crds_shards_find_1(bencher: &mut Bencher) {
|
|
bench_crds_shards_find(bencher, 100_000, 1);
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_crds_shards_find_3(bencher: &mut Bencher) {
|
|
bench_crds_shards_find(bencher, 100_000, 3);
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_crds_shards_find_5(bencher: &mut Bencher) {
|
|
bench_crds_shards_find(bencher, 100_000, 5);
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_crds_shards_find_7(bencher: &mut Bencher) {
|
|
bench_crds_shards_find(bencher, 100_000, 7);
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_crds_shards_find_8(bencher: &mut Bencher) {
|
|
bench_crds_shards_find(bencher, 100_000, 8);
|
|
}
|
|
|
|
#[bench]
|
|
fn bench_crds_shards_find_9(bencher: &mut Bencher) {
|
|
bench_crds_shards_find(bencher, 100_000, 9);
|
|
}
|