-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(db_lookup_times): rework core logic of benchmark (#2159)
>[!NOTE] > This PR follows up #2142 with comments after merge ## Linked Issues/PRs <!-- List of related issues/PRs --> - #2142 - #2023 ## Description <!-- List of detailed changes --> - refactors the test database to use a custom set of columns that will not create any new tables/columns in `fuel-core` - refactors the functions to return `Result`s instead of unwrapping everywhere - automated cleaning up of benchmark databases - `KeyValueMutate` impl of `RocksDb` is now behind the `test-helpers` feature flag - moved the `db_lookup_times_utils` to the `src` directory in the benches crate so we can test our insertion/fetching logic ## Checklist - [x] Breaking changes are clearly marked as such in the PR description and changelog - [x] New behavior is reflected in tests - [x] [The specification](https://github.com/FuelLabs/fuel-specs/) matches the implemented behavior (link update PR if changes are needed) ### Before requesting review - [x] I have reviewed the code myself - [ ] I have created follow-up issues caused by this PR and linked them here ### After merging, notify other teams [Add or remove entries as needed] - [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/) - [ ] [Sway compiler](https://github.com/FuelLabs/sway/) - [ ] [Platform documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+) (for out-of-organization contributors, the person merging the PR will do this) - [ ] Someone else? --------- Co-authored-by: Green Baneling <[email protected]>
- Loading branch information
Showing
17 changed files
with
554 additions
and
365 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,114 @@ | ||
use crate::db_lookup_times_utils::{ | ||
matrix::matrix, | ||
utils::{ | ||
get_full_block, | ||
get_random_block_height, | ||
multi_get_block, | ||
open_db, | ||
open_raw_rocksdb, | ||
}, | ||
}; | ||
use criterion::{ | ||
criterion_group, | ||
criterion_main, | ||
Criterion, | ||
}; | ||
use db_lookup_times_utils::seed::{ | ||
seed_compressed_blocks_and_transactions_matrix, | ||
seed_full_block_matrix, | ||
use fuel_core_benches::db_lookup_times_utils::{ | ||
matrix::matrix, | ||
seed::{ | ||
seed_compressed_blocks_and_transactions_matrix, | ||
seed_full_block_matrix, | ||
}, | ||
utils::{ | ||
get_random_block_height, | ||
open_rocks_db, | ||
LookupMethod, | ||
Result as DbLookupBenchResult, | ||
}, | ||
}; | ||
use fuel_core_storage::transactional::AtomicView; | ||
use rand::thread_rng; | ||
|
||
mod db_lookup_times_utils; | ||
use fuel_core_benches::utils::ShallowTempDir; | ||
use rand::thread_rng; | ||
|
||
pub fn header_and_tx_lookup(c: &mut Criterion) { | ||
let method = "header_and_tx"; | ||
pub fn header_and_tx_lookup(c: &mut Criterion) -> DbLookupBenchResult<()> { | ||
let method = LookupMethod::HeaderAndTx; | ||
let mut rng = thread_rng(); | ||
|
||
seed_compressed_blocks_and_transactions_matrix(method); | ||
let mut group = c.benchmark_group(method); | ||
let mut group = c.benchmark_group(method.as_ref()); | ||
|
||
for (block_count, tx_count) in matrix() { | ||
let database = open_db(block_count, tx_count, method); | ||
let view = database.latest_view().unwrap(); | ||
let db_path = ShallowTempDir::new(); | ||
let mut database = open_rocks_db(db_path.path())?; | ||
seed_compressed_blocks_and_transactions_matrix( | ||
&mut database, | ||
block_count, | ||
tx_count, | ||
)?; | ||
|
||
group.bench_function(format!("{block_count}/{tx_count}"), |b| { | ||
b.iter(|| { | ||
let height = get_random_block_height(&mut rng, block_count); | ||
let block = view.get_full_block(&height); | ||
let block = method.get_block(&database, height); | ||
assert!(block.is_ok()); | ||
assert!(block.unwrap().is_some()); | ||
}); | ||
}); | ||
} | ||
|
||
group.finish(); | ||
Ok(()) | ||
} | ||
|
||
pub fn multi_get_lookup(c: &mut Criterion) { | ||
let method = "multi_get"; | ||
pub fn multi_get_lookup(c: &mut Criterion) -> DbLookupBenchResult<()> { | ||
let method = LookupMethod::MultiGet; | ||
let mut rng = thread_rng(); | ||
|
||
seed_compressed_blocks_and_transactions_matrix(method); | ||
let mut group = c.benchmark_group(method); | ||
let mut group = c.benchmark_group(method.as_ref()); | ||
|
||
for (block_count, tx_count) in matrix() { | ||
let database = open_raw_rocksdb(block_count, tx_count, method); | ||
let db_path = ShallowTempDir::new(); | ||
let mut database = open_rocks_db(db_path.path())?; | ||
seed_compressed_blocks_and_transactions_matrix( | ||
&mut database, | ||
block_count, | ||
tx_count, | ||
)?; | ||
|
||
group.bench_function(format!("{block_count}/{tx_count}"), |b| { | ||
b.iter(|| { | ||
let height = get_random_block_height(&mut rng, block_count); | ||
assert!(multi_get_block(&database, height).is_ok()); | ||
let block = method.get_block(&database, height); | ||
assert!(block.is_ok()); | ||
}); | ||
}); | ||
} | ||
|
||
group.finish(); | ||
Ok(()) | ||
} | ||
|
||
pub fn full_block_lookup(c: &mut Criterion) { | ||
let method = "full_block"; | ||
pub fn full_block_lookup(c: &mut Criterion) -> DbLookupBenchResult<()> { | ||
let method = LookupMethod::FullBlock; | ||
let mut rng = thread_rng(); | ||
|
||
seed_full_block_matrix(); | ||
let mut group = c.benchmark_group(method); | ||
let mut group = c.benchmark_group(method.as_ref()); | ||
|
||
for (block_count, tx_count) in matrix() { | ||
let database = open_db(block_count, tx_count, method); | ||
let view = database.latest_view().unwrap(); | ||
let db_path = ShallowTempDir::new(); | ||
let mut database = open_rocks_db(db_path.path())?; | ||
seed_full_block_matrix(&mut database, block_count, tx_count)?; | ||
|
||
group.bench_function(format!("{block_count}/{tx_count}"), |b| { | ||
b.iter(|| { | ||
let height = get_random_block_height(&mut rng, block_count); | ||
let full_block = get_full_block(&view, &height); | ||
let full_block = method.get_block(&database, height); | ||
assert!(full_block.is_ok()); | ||
assert!(full_block.unwrap().is_some()); | ||
}); | ||
}); | ||
} | ||
|
||
group.finish(); | ||
Ok(()) | ||
} | ||
|
||
fn construct_and_run_benchmarks(c: &mut Criterion) { | ||
header_and_tx_lookup(c).unwrap(); | ||
multi_get_lookup(c).unwrap(); | ||
full_block_lookup(c).unwrap(); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default().sample_size(100_000).measurement_time(std::time::Duration::from_secs(100)); | ||
targets = header_and_tx_lookup, multi_get_lookup, full_block_lookup | ||
config = Criterion::default().sample_size(10).measurement_time(std::time::Duration::from_secs(10)); | ||
targets = construct_and_run_benchmarks | ||
} | ||
criterion_main!(benches); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.