diff options
Diffstat (limited to 'benches/benchmark.rs')
| -rw-r--r-- | benches/benchmark.rs | 110 |
1 files changed, 100 insertions, 10 deletions
diff --git a/benches/benchmark.rs b/benches/benchmark.rs index b9ecbb3..c999811 100644 --- a/benches/benchmark.rs +++ b/benches/benchmark.rs @@ -12,8 +12,8 @@ enum Field { Data, } -pub fn upsert_benchmark(c: &mut Criterion) { - let mut group = c.benchmark_group("db.upsert"); +pub fn upsert_various_initial_sizes(c: &mut Criterion) { + let mut group = c.benchmark_group("upsert_various_initial_sizes"); for size in [0, 10, 100, 1000, 10000] { let data_dir_obj = tempfile::tempdir().expect("Failed to get tmpdir"); @@ -31,21 +31,55 @@ pub fn upsert_benchmark(c: &mut Criterion) { .primary_key(Field::Id) .initialize() .expect("Failed to initialize DB"); - prefill_db_with_n_records(&mut db, size).expect("Failed to prefill DB"); + prefill_db(&mut db, size).expect("Failed to prefill DB"); group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &_size| { b.iter(|| { - let record = random_record(); + let record = random_record(0, size as i64); let _ = db.upsert(black_box(&record)); }); }); } } -pub fn get_benchmark(c: &mut Criterion) { - let mut group = c.benchmark_group("db.get"); +pub fn upsert_write_durability(c: &mut Criterion) { + let mut group = c.benchmark_group("upsert_write_durability"); - for size in [0, 10, 100, 1000, 10000] { + for mode in [ + WriteDurability::Async, + WriteDurability::Flush, + WriteDurability::FlushSync, + ] { + group.bench_with_input(BenchmarkId::from_parameter(&mode), &mode, |b, _mode| { + let data_dir_obj = tempfile::tempdir().expect("Failed to get tmpdir"); + let data_dir = &data_dir_obj + .path() + .to_str() + .expect("Failed to convert tmpdir path to str"); + let mut db = DB::configure() + .data_dir(&data_dir) + .fields(&vec![ + (Field::Id, RecordFieldType::Int), + (Field::Name, RecordFieldType::String), + (Field::Data, RecordFieldType::Bytes), + ]) + .write_durability(mode.clone()) + .primary_key(Field::Id) + .initialize() + .expect("Failed to initialize DB"); + + b.iter(|| { + let record = random_record(0, 1000); + let _ = db.upsert(black_box(&record)); + }); + }); + } +} + +pub fn get_from_disk_various_initial_sizes(c: &mut Criterion) { + let mut group = c.benchmark_group("get_from_disk_various_initial_sizes"); + + for size in [0, 10, 100, 1000, 3300, 6700, 10000, 50000, 100_000] { let data_dir_obj = tempfile::tempdir().expect("Failed to get tmpdir"); let data_dir = &data_dir_obj .path() @@ -53,6 +87,7 @@ pub fn get_benchmark(c: &mut Criterion) { .expect("Failed to convert tmpdir path to str"); let mut db = DB::configure() .data_dir(&data_dir) + .memtable_capacity(0) .fields(&vec![ (Field::Id, RecordFieldType::Int), (Field::Name, RecordFieldType::String), @@ -61,11 +96,60 @@ pub fn get_benchmark(c: &mut Criterion) { .primary_key(Field::Id) .initialize() .expect("Failed to initialize DB"); - prefill_db_with_n_records(&mut db, size).expect("Failed to prefill DB"); + prefill_db(&mut db, size).expect("Failed to prefill DB"); group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &_size| { b.iter(|| { - let id = random_int(); + let id = random_int(0, size as i64 + 1); + let _ = db.get(black_box(&RecordValue::Int(id))); + }); + }); + } +} + +pub fn get_various_memtable_capacities(c: &mut Criterion) { + let mut group = c.benchmark_group("get_various_memtable_capacities"); + + const PREFILL_N: usize = 10000; + let data_dir_obj = tempfile::tempdir().expect("Failed to get tmpdir"); + let data_dir = &data_dir_obj + .path() + .to_str() + .expect("Failed to convert tmpdir path to str"); + + // Create a db instance for prefilling + let mut db = DB::configure() + .data_dir(&data_dir) + .fields(&vec![ + (Field::Id, RecordFieldType::Int), + (Field::Name, RecordFieldType::String), + (Field::Data, RecordFieldType::Bytes), + ]) + .primary_key(Field::Id) + .initialize() + .expect("Failed to initialize DB"); + + prefill_db(&mut db, PREFILL_N).expect("Failed to prefill DB"); + drop(db); + + // prefill_db generates IDs between 0..1000, so having memtable_capacity = 1000 + // effectively indexes the whole DB + for size in (0..).map(|x| x * 100).take_while(|&x| x <= 1000) { + group.bench_with_input(BenchmarkId::from_parameter(size), &size, |b, &_size| { + let mut db = DB::configure() + .data_dir(&data_dir) + .fields(&vec![ + (Field::Id, RecordFieldType::Int), + (Field::Name, RecordFieldType::String), + (Field::Data, RecordFieldType::Bytes), + ]) + .memtable_capacity(size) + .primary_key(Field::Id) + .initialize() + .expect("Failed to initialize DB"); + + b.iter(|| { + let id = random_int(0, 1000 + 1); let _ = db.get(black_box(&RecordValue::Int(id))); }); }); @@ -73,5 +157,11 @@ pub fn get_benchmark(c: &mut Criterion) { } // Register the benchmark group -criterion_group!(benches, upsert_benchmark, get_benchmark); +criterion_group!( + benches, + upsert_various_initial_sizes, + upsert_write_durability, + get_from_disk_various_initial_sizes, + get_various_memtable_capacities, +); criterion_main!(benches); |
