Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ anyhow = "1.0.58"
btree-slab = "0.4.0"
dashmap = "5.3.4"
duckdb = { version = "0.4.0", features = ["bundled", "r2d2"] }
lmdb-rkv = "0.14.0"
num_cpus = "1.13.1"
parking_lot = "0.12.1"
persy = { version = "1.3.1", features = ["background_ops"] }
r2d2 = "0.8.10"
rand = "0.8.5"
rayon = "1.5.3"
rocksdb = { path = "./lib/rust-rocksdb", features = [
rocksdb = { features = [
"zstd"
], default-features = false }
rusty-leveldb = "1.0.2"
Expand Down
98 changes: 97 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(try_trait_v2)]

use anyhow::Result;
use lmdb::Transaction;
use parking_lot::Mutex;
use rand::Rng;
use rayon::prelude::*;
Expand All @@ -9,7 +10,7 @@ use std::sync::Arc;
use std::{
collections::{BTreeMap, HashMap},
env,
fs::{remove_dir_all, remove_file},
fs::{create_dir, remove_dir_all, remove_file},
mem::MaybeUninit,
time::Instant,
};
Expand Down Expand Up @@ -237,6 +238,50 @@ pub fn run<const N: usize>() -> Result<()> {
Ok(())
});
}

{
let filename = "rocksdb-transaction";
println!("\n# {filename}");
let dbpath = dir.join(filename);
let _ = remove_dir_all(&dbpath);

let db: Arc<rocksdb::TransactionDB> =
Arc::new(rocksdb::TransactionDB::open_default(dbpath)?);
// let db = Arc::new(rocksdb::DB::open(&opt, dbpath)?);

let mut write_opts = rocksdb::WriteOptions::new();
write_opts.set_sync(true);
let txn_opts = rocksdb::TransactionOptions::new();

elapsed!(insert, |kv| -> Result<()> {
let txn = db.transaction_opt(&write_opts, &txn_opts);
let [k, v] = kv;
txn.put(&k.to_be_bytes(), &v.to_le_bytes())?;
txn.commit()?;
Ok(())
});

let txn = db.transaction_opt(&write_opts, &txn_opts);
elapsed!(
insert_bulk,
|kv| -> Result<()> {
let [k, v] = kv;
txn.put(&k.to_be_bytes(), &v.to_le_bytes())?;
Ok(())
},
iter
);
txn.commit()?;

elapsed!(get, |kv| -> Result<()> {
let [k, _] = kv;
if let Some(i) = db.get_pinned(&k.to_be_bytes())? {
n_add!(i)
}
Ok(())
});
}

{
use persy::{Config, Persy, TransactionConfig, ValueMode};
let filename = "persy";
Expand Down Expand Up @@ -338,6 +383,57 @@ pub fn run<const N: usize>() -> Result<()> {
Ok(())
});
}

{
let filename = "lmdb";
println!("\n# {filename}");
let dbpath = dir.join(filename);
let _ = remove_dir_all(&dbpath);
let _ = create_dir(dbpath.clone());
let env = lmdb::Environment::new().open(&dbpath)?;
let db = env.open_db(None)?;

elapsed!(insert, |kv| -> Result<()> {
let [k, v] = kv;
let mut txn = env.begin_rw_txn()?;
txn.put(
db,
&k.to_be_bytes(),
&v.to_le_bytes(),
lmdb::WriteFlags::empty(),
)?;
txn.commit()?;
Ok(())
});

let mut txn = env.begin_rw_txn()?;
elapsed!(
insert_bulk,
|kv| -> Result<()> {
let [k, v] = kv;
txn.put(
db,
&k.to_be_bytes(),
&v.to_le_bytes(),
lmdb::WriteFlags::empty(),
)?;
Ok(())
},
iter
);
txn.commit()?;

elapsed!(get, |kv| -> Result<()> {
let [k, _] = kv;
let txn = env.begin_ro_txn()?;
{
let i = txn.get(db, &k.to_be_bytes())?;
n_add!(i);
}
txn.commit()?;
Ok(())
});
}
Ok(())
}

Expand Down