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

[WIP] Use B+ tree for manifest structure. #113

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proto = { path = "proto" }
skiplist = { path = "skiplist" }
memmap = "0.7"
farmhash = "1.1"
prost = "0.7"
prost = "0.8"
enum_dispatch = "0.3"
crossbeam-channel = "0.5"
crc32fast = "1.2"
Expand Down Expand Up @@ -51,6 +51,10 @@ harness = false
name = "bench_iterator"
harness = false

[[bench]]
name = "bench_manifest"
harness = false

[profile.bench]
opt-level = 3
debug = false
Expand Down
65 changes: 65 additions & 0 deletions benches/bench_manifest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
mod common;

use agatedb::util::{BTree, ComparableRecord};
use rand::Rng;
use std::sync::Arc;

use bytes::Bytes;
use criterion::{criterion_group, criterion_main, Criterion};
use std::time::Instant;

struct FakeTableInner {
id: u64,
smallest: Bytes,
largest: Bytes,
}

#[derive(Clone)]
struct FakeTable {
inner: Arc<FakeTableInner>,
}

impl ComparableRecord for FakeTable {
fn smallest(&self) -> &Bytes {
&self.inner.smallest
}

fn largest(&self) -> &Bytes {
&self.inner.largest
}

fn id(&self) -> u64 {
self.inner.id
}
}

fn benche_manifest(c: &mut Criterion) {
const KEY_RANGE_COUNT: u64 = 10000; // about 64MB
const KEY_BASE: u64 = 1000_1000; // about 64MB

// let mut rng = rand::thread_rng();
// let mut tree = LevelTree::<FakeTable>::new(64, 128);

let mut test_count = 0;
println!("start bench");
c.bench_function("table builder", |b| {
b.iter(|| {
// let j = rng.gen_range(0, KEY_RANGE_COUNT - 1);
// let left = KEY_BASE + j as usize * 100;
// let left = left + 99;
// let smallest = Bytes::from(left.to_string());
// let largest = Bytes::from(right.to_string());
// TODO: check whether key existed and decide delete or insert.
test_count += 1;
});
});
println!("end bench, {}", test_count);
}

criterion_group! {
name = benches_manifest;
config = Criterion::default();
targets = benche_manifest
}

criterion_main!(benches_manifest);
4 changes: 2 additions & 2 deletions proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
bytes = "1.0"
prost = "0.7"
prost = "0.8"

[build-dependencies]
prost-build = { version = "0.6" }
prost-build = { version = "0.8" }
5 changes: 0 additions & 5 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,14 +626,11 @@ impl Core {
vlog.write(&mut requests)?;
}

let mut cnt = 0;

// writing to LSM
for req in requests {
if req.entries.is_empty() {
continue;
}
cnt += req.entries.len();

while let Err(_) = self.ensure_room_for_write() {
std::thread::sleep(std::time::Duration::from_millis(10));
Expand All @@ -643,8 +640,6 @@ impl Core {
self.write_to_lsm(req)?;
}

// eprintln!("{} entries written", cnt);

Ok(())
};

Expand Down
Loading