Skip to content

Commit

Permalink
Switch to optimistic rocksdb transaction in benchmark
Browse files Browse the repository at this point in the history
This is faster on some benchmarks, and more similar in capabilities to
the other databases
  • Loading branch information
cberner committed Dec 30, 2024
1 parent ec48f3d commit 4aaf48b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
20 changes: 11 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 @@ -486,7 +488,7 @@ impl<'a> BenchDatabase for RocksdbBenchDatabase<'a> {
}

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

impl<'a> BenchWriteTransaction for RocksdbBenchWriteTransaction<'a> {
Expand All @@ -502,7 +504,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 +518,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 +532,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 +557,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
2 changes: 1 addition & 1 deletion benches/lmdb_benchmark.rs
Original file line number Diff line number Diff line change
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

0 comments on commit 4aaf48b

Please sign in to comment.