Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit b2152be

Browse files
introduce bucket map (#19848)
* introduce bucket map * rename BucketMap bits to num_buckets_pow2 * use u64::BITS * Store the number of buckets in BucketMapConfig as a regular number * remove redundant type aliases * use Slot from sdk * use Arc::clone() instead * fixup erase drives * rename num_buckets to max_buckets * add doc to BucketMapConfig::new() * add more documentation * rename to DEFAULT_CAPACITY_POW2 * doc * add more traits while we can * rename capacity to capacity_pow2 * fix a naming for max_buckets_pow2 * remove unused/incorrect DataBucket::bytes * rework benches a bit * fixup bench docs * rename create_bucket_capacity_pow2 to bucket_capacity_when_created_pow2 * rename BucketMapKeyValue to BucketItem * rename to items_in_range * remove values() * remove addref and unref * remove more addref and unref * resurect addref and unref since tests use 'em for now * rename to BucketStorage * move stats in bucket_stats * remove specializations (i don't think they are needed) * move MaxSearch and RefCount into lib.rs * move BucketItem to bucket_item.rs * add doc * keys no longer returns an option * Revert "remove specializations (i don't think they are needed)" This reverts commit b22f78e. Co-authored-by: Brooks Prumo <brooks@solana.com>
1 parent cddb9da commit b2152be

File tree

14 files changed

+1552
-3
lines changed

14 files changed

+1552
-3
lines changed

Cargo.lock

Lines changed: 28 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"banks-client",
99
"banks-interface",
1010
"banks-server",
11+
"bucket_map",
1112
"clap-utils",
1213
"cli-config",
1314
"cli-output",

bucket_map/Cargo.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
name = "solana-bucket-map"
3+
version = "1.8.0"
4+
description = "solana-bucket-map"
5+
homepage = "https://solana.com/"
6+
documentation = "https://docs.rs/solana-bucket-map"
7+
readme = "../README.md"
8+
repository = "https://github.com/solana-labs/solana"
9+
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
10+
license = "Apache-2.0"
11+
edition = "2018"
12+
13+
[dependencies]
14+
rayon = "1.5.0"
15+
solana-logger = { path = "../logger", version = "=1.8.0" }
16+
solana-sdk = { path = "../sdk", version = "=1.8.0" }
17+
memmap2 = "0.2.3"
18+
log = { version = "0.4.11" }
19+
solana-measure = { path = "../measure", version = "=1.8.0" }
20+
rand = "0.7.0"
21+
fs_extra = "1.2.0"
22+
tempfile = "3.2.0"
23+
24+
[lib]
25+
crate-type = ["lib"]
26+
name = "solana_bucket_map"
27+
28+
[[bench]]
29+
name = "bucket_map"

bucket_map/benches/bucket_map.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#![feature(test)]
2+
3+
macro_rules! DEFINE_NxM_BENCH {
4+
($i:ident, $n:literal, $m:literal) => {
5+
mod $i {
6+
use super::*;
7+
8+
#[bench]
9+
fn bench_insert_baseline_hashmap(bencher: &mut Bencher) {
10+
do_bench_insert_baseline_hashmap(bencher, $n, $m);
11+
}
12+
13+
#[bench]
14+
fn bench_insert_bucket_map(bencher: &mut Bencher) {
15+
do_bench_insert_bucket_map(bencher, $n, $m);
16+
}
17+
}
18+
};
19+
}
20+
21+
extern crate test;
22+
use rayon::prelude::*;
23+
use solana_bucket_map::bucket_map::{BucketMap, BucketMapConfig};
24+
use solana_sdk::pubkey::Pubkey;
25+
use std::collections::hash_map::HashMap;
26+
use std::sync::RwLock;
27+
use test::Bencher;
28+
29+
type IndexValue = u64;
30+
31+
DEFINE_NxM_BENCH!(dim_01x02, 1, 2);
32+
DEFINE_NxM_BENCH!(dim_02x04, 2, 4);
33+
DEFINE_NxM_BENCH!(dim_04x08, 4, 8);
34+
DEFINE_NxM_BENCH!(dim_08x16, 8, 16);
35+
DEFINE_NxM_BENCH!(dim_16x32, 16, 32);
36+
DEFINE_NxM_BENCH!(dim_32x64, 32, 64);
37+
38+
/// Benchmark insert with Hashmap as baseline for N threads inserting M keys each
39+
fn do_bench_insert_baseline_hashmap(bencher: &mut Bencher, n: usize, m: usize) {
40+
let index = RwLock::new(HashMap::new());
41+
(0..n).into_iter().into_par_iter().for_each(|i| {
42+
let key = Pubkey::new_unique();
43+
index
44+
.write()
45+
.unwrap()
46+
.insert(key, vec![(i, IndexValue::default())]);
47+
});
48+
bencher.iter(|| {
49+
(0..n).into_iter().into_par_iter().for_each(|_| {
50+
for j in 0..m {
51+
let key = Pubkey::new_unique();
52+
index
53+
.write()
54+
.unwrap()
55+
.insert(key, vec![(j, IndexValue::default())]);
56+
}
57+
})
58+
});
59+
}
60+
61+
/// Benchmark insert with BucketMap with N buckets for N threads inserting M keys each
62+
fn do_bench_insert_bucket_map(bencher: &mut Bencher, n: usize, m: usize) {
63+
let index = BucketMap::new(BucketMapConfig::new(n));
64+
(0..n).into_iter().into_par_iter().for_each(|i| {
65+
let key = Pubkey::new_unique();
66+
index.update(&key, |_| Some((vec![(i, IndexValue::default())], 0)));
67+
});
68+
bencher.iter(|| {
69+
(0..n).into_iter().into_par_iter().for_each(|_| {
70+
for j in 0..m {
71+
let key = Pubkey::new_unique();
72+
index.update(&key, |_| Some((vec![(j, IndexValue::default())], 0)));
73+
}
74+
})
75+
});
76+
}

0 commit comments

Comments
 (0)