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

Rocksdb comparison benchmark improvements #927

Merged
merged 3 commits into from
Dec 30, 2024
Merged
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
25 changes: 16 additions & 9 deletions benches/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use redb::{AccessGuard, ReadableTableMetadata, TableDefinition};
use rocksdb::{Direction, IteratorMode, TransactionDB, TransactionOptions, WriteOptions};
use rocksdb::{
Direction, IteratorMode, OptimisticTransactionDB, OptimisticTransactionOptions, WriteOptions,
};
use sanakirja::btree::page_unsized;
use sanakirja::{Commit, RootDb};
use std::fs;
Expand Down Expand Up @@ -453,11 +455,11 @@ impl BenchIterator for HeedBenchIterator<'_> {
}

pub struct RocksdbBenchDatabase<'a> {
db: &'a TransactionDB,
db: &'a OptimisticTransactionDB,
}

impl<'a> RocksdbBenchDatabase<'a> {
pub fn new(db: &'a TransactionDB) -> Self {
pub fn new(db: &'a OptimisticTransactionDB) -> Self {
Self { db }
}
}
Expand All @@ -473,7 +475,7 @@ impl<'a> BenchDatabase for RocksdbBenchDatabase<'a> {
fn write_transaction(&self) -> Self::W<'_> {
let mut write_opt = WriteOptions::new();
write_opt.set_sync(true);
let mut txn_opt = TransactionOptions::new();
let mut txn_opt = OptimisticTransactionOptions::new();
txn_opt.set_snapshot(true);
let txn = self.db.transaction_opt(&write_opt, &txn_opt);
RocksdbBenchWriteTransaction { txn }
Expand All @@ -483,10 +485,15 @@ impl<'a> BenchDatabase for RocksdbBenchDatabase<'a> {
let snapshot = self.db.snapshot();
RocksdbBenchReadTransaction { snapshot }
}

fn compact(&mut self) -> bool {
self.db.compact_range::<&[u8], &[u8]>(None, None);
true
}
}

pub struct RocksdbBenchWriteTransaction<'a> {
txn: rocksdb::Transaction<'a, TransactionDB>,
txn: rocksdb::Transaction<'a, OptimisticTransactionDB>,
}

impl<'a> BenchWriteTransaction for RocksdbBenchWriteTransaction<'a> {
Expand All @@ -502,7 +509,7 @@ impl<'a> BenchWriteTransaction for RocksdbBenchWriteTransaction<'a> {
}

pub struct RocksdbBenchInserter<'a> {
txn: &'a rocksdb::Transaction<'a, TransactionDB>,
txn: &'a rocksdb::Transaction<'a, OptimisticTransactionDB>,
}

impl BenchInserter for RocksdbBenchInserter<'_> {
Expand All @@ -516,7 +523,7 @@ impl BenchInserter for RocksdbBenchInserter<'_> {
}

pub struct RocksdbBenchReadTransaction<'db> {
snapshot: rocksdb::SnapshotWithThreadMode<'db, TransactionDB>,
snapshot: rocksdb::SnapshotWithThreadMode<'db, OptimisticTransactionDB>,
}

impl<'db> BenchReadTransaction for RocksdbBenchReadTransaction<'db> {
Expand All @@ -530,7 +537,7 @@ impl<'db> BenchReadTransaction for RocksdbBenchReadTransaction<'db> {
}

pub struct RocksdbBenchReader<'db, 'txn> {
snapshot: &'txn rocksdb::SnapshotWithThreadMode<'db, TransactionDB>,
snapshot: &'txn rocksdb::SnapshotWithThreadMode<'db, OptimisticTransactionDB>,
}

impl<'db, 'txn> BenchReader for RocksdbBenchReader<'db, 'txn> {
Expand All @@ -555,7 +562,7 @@ impl<'db, 'txn> BenchReader for RocksdbBenchReader<'db, 'txn> {
}

pub struct RocksdbBenchIterator<'a> {
iter: rocksdb::DBIteratorWithThreadMode<'a, TransactionDB>,
iter: rocksdb::DBIteratorWithThreadMode<'a, OptimisticTransactionDB>,
}

impl BenchIterator for RocksdbBenchIterator<'_> {
Expand Down
2 changes: 1 addition & 1 deletion benches/int_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn main() {

let rocksdb_results = {
let tmpfile: TempDir = tempfile::tempdir_in(current_dir().unwrap()).unwrap();
let db = rocksdb::TransactionDB::open_default(tmpfile.path()).unwrap();
let db = rocksdb::OptimisticTransactionDB::open_default(tmpfile.path()).unwrap();
let table = RocksdbBenchDatabase::new(&db);
benchmark(table)
};
Expand Down
2 changes: 1 addition & 1 deletion benches/large_values_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn main() {

let rocksdb_results = {
let tmpfile: TempDir = tempfile::tempdir_in(current_dir().unwrap()).unwrap();
let db = rocksdb::TransactionDB::open_default(tmpfile.path()).unwrap();
let db = rocksdb::OptimisticTransactionDB::open_default(tmpfile.path()).unwrap();
let table = RocksdbBenchDatabase::new(&db);
benchmark(table)
};
Expand Down
4 changes: 2 additions & 2 deletions benches/lmdb_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ fn benchmark<T: BenchDatabase + Send + Sync>(db: T, path: &Path) -> Vec<(String,
}
let size = database_size(path);
println!(
"{}: Final file size {}ms",
"{}: Final file size {}",
T::db_type_name(),
ResultType::SizeInBytes(size)
);
Expand Down Expand Up @@ -394,7 +394,7 @@ fn main() {
opts.set_block_based_table_factory(&bb);
opts.create_if_missing(true);

let db = rocksdb::TransactionDB::open(&opts, &Default::default(), tmpfile.path()).unwrap();
let db = rocksdb::OptimisticTransactionDB::open(&opts, tmpfile.path()).unwrap();
let table = RocksdbBenchDatabase::new(&db);
benchmark(table, tmpfile.path())
};
Expand Down
Loading