From ef5277e699252a31fc7f72ea1edfd17f610fcae6 Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Tue, 27 Aug 2024 20:25:17 -0700 Subject: [PATCH] Add compaction to lmdb_benchmark 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 --- benches/lmdb_benchmark.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/benches/lmdb_benchmark.rs b/benches/lmdb_benchmark.rs index f2197f78..b2c6e1d0 100644 --- a/benches/lmdb_benchmark.rs +++ b/benches/lmdb_benchmark.rs @@ -297,6 +297,7 @@ fn database_size(path: &Path) -> u64 { #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] enum ResultType { + NA, Duration(Duration), SizeInBytes(u64), } @@ -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); @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -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(),