Skip to content

Commit

Permalink
Add compaction to lmdb_benchmark
Browse files Browse the repository at this point in the history
Note: compact() is currently too slow to practically run with the
default 1M elements. It takes 43secs on my computer when set to 1000
elements
  • Loading branch information
cberner committed Aug 28, 2024
1 parent 4dbd9cd commit ef5277e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion benches/lmdb_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ fn database_size(path: &Path) -> u64 {

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
enum ResultType {
NA,
Duration(Duration),
SizeInBytes(u64),
}
Expand All @@ -306,6 +307,7 @@ impl std::fmt::Display for ResultType {
use byte_unit::{Byte, UnitType};

match self {
ResultType::NA => write!(f, "N/A"),
ResultType::Duration(d) => write!(f, "{d:.2?}"),
ResultType::SizeInBytes(s) => {
let b = Byte::from_u64(*s).get_appropriate_unit(UnitType::Binary);
Expand All @@ -328,12 +330,20 @@ fn main() {

let redb_latency_results = {
let tmpfile: NamedTempFile = NamedTempFile::new_in(&tmpdir).unwrap();
let db = redb::Database::builder()
let mut db = redb::Database::builder()
.set_cache_size(4 * 1024 * 1024 * 1024)
.create(tmpfile.path())
.unwrap();
let table = RedbBenchDatabase::new(&db);
let mut results = benchmark(table);

let start = Instant::now();
db.compact().unwrap();
let end = Instant::now();
let duration = end - start;
println!("redb: Compacted in {}ms", duration.as_millis());
results.push(("compaction".to_string(), ResultType::Duration(duration)));

let size = database_size(tmpfile.path());
results.push((
"size after bench".to_string(),
Expand All @@ -352,6 +362,7 @@ fn main() {
};
let table = HeedBenchDatabase::new(&env);
let mut results = benchmark(table);
results.push(("compaction".to_string(), ResultType::NA));
let size = database_size(tmpfile.path());
results.push((
"size after bench".to_string(),
Expand All @@ -373,6 +384,7 @@ fn main() {
let db = rocksdb::TransactionDB::open(&opts, &Default::default(), tmpfile.path()).unwrap();
let table = RocksdbBenchDatabase::new(&db);
let mut results = benchmark(table);
results.push(("compaction".to_string(), ResultType::NA));
let size = database_size(tmpfile.path());
results.push((
"size after bench".to_string(),
Expand All @@ -386,6 +398,7 @@ fn main() {
let db = sled::Config::new().path(tmpfile.path()).open().unwrap();
let table = SledBenchDatabase::new(&db, tmpfile.path());
let mut results = benchmark(table);
results.push(("compaction".to_string(), ResultType::NA));
let size = database_size(tmpfile.path());
results.push((
"size after bench".to_string(),
Expand All @@ -400,6 +413,7 @@ fn main() {
let db = sanakirja::Env::new(tmpfile.path(), 4096 * 1024 * 1024, 2).unwrap();
let table = SanakirjaBenchDatabase::new(&db);
let mut results = benchmark(table);
results.push(("compaction".to_string(), ResultType::NA));
let size = database_size(tmpfile.path());
results.push((
"size after bench".to_string(),
Expand Down

0 comments on commit ef5277e

Please sign in to comment.