mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-21 14:58:31 +00:00
Add builder for benches
Also adds a "sane" case for block processing
This commit is contained in:
@@ -1,23 +1,107 @@
|
||||
use block_benching_builder::BlockBenchingBuilder;
|
||||
use criterion::Criterion;
|
||||
use criterion::{criterion_group, criterion_main};
|
||||
use env_logger::{Builder, Env};
|
||||
use log::info;
|
||||
use types::*;
|
||||
|
||||
mod bench_block_processing;
|
||||
mod bench_epoch_processing;
|
||||
mod block_benching_builder;
|
||||
|
||||
pub const VALIDATOR_COUNT: usize = 16_384;
|
||||
|
||||
// `LOG_LEVEL == "debug"` gives logs, but they're very noisy and slow down benching.
|
||||
pub const LOG_LEVEL: &str = "";
|
||||
pub const LOG_LEVEL: &str = "info";
|
||||
|
||||
pub fn state_processing(c: &mut Criterion) {
|
||||
/// Build a worst-case block and benchmark processing it.
|
||||
pub fn block_processing_worst_case(c: &mut Criterion) {
|
||||
if LOG_LEVEL != "" {
|
||||
Builder::from_env(Env::default().default_filter_or(LOG_LEVEL)).init();
|
||||
}
|
||||
info!(
|
||||
"Building worst case block bench with {} validators",
|
||||
VALIDATOR_COUNT
|
||||
);
|
||||
|
||||
bench_epoch_processing::bench_epoch_processing_n_validators(c, VALIDATOR_COUNT);
|
||||
bench_block_processing::bench_block_processing_n_validators(c, VALIDATOR_COUNT);
|
||||
// Use the specifications from the Eth2.0 spec.
|
||||
let spec = ChainSpec::foundation();
|
||||
|
||||
// Create a builder for configuring the block and state for benching.
|
||||
let mut bench_builder = BlockBenchingBuilder::new(VALIDATOR_COUNT, &spec);
|
||||
|
||||
// Set the number of included operations to be maximum (e.g., `MAX_ATTESTATIONS`, etc.)
|
||||
bench_builder.maximize_block_operations(&spec);
|
||||
|
||||
// Set the state and block to be in the last slot of the 4th epoch.
|
||||
let last_slot_of_epoch = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
||||
bench_builder.set_slot(last_slot_of_epoch, &spec);
|
||||
|
||||
// Build all the state caches so the build times aren't included in the benches.
|
||||
bench_builder.build_caches(&spec);
|
||||
|
||||
// Generate the block and state.
|
||||
let (block, state) = bench_builder.build(&spec);
|
||||
|
||||
// Run the benches.
|
||||
bench_block_processing::bench_block_processing(
|
||||
c,
|
||||
&block,
|
||||
&state,
|
||||
&spec,
|
||||
&format!("{}_validators/worst_case", VALIDATOR_COUNT),
|
||||
);
|
||||
}
|
||||
|
||||
criterion_group!(benches, state_processing);
|
||||
/// Build a reasonable-case block and benchmark processing it.
|
||||
pub fn block_processing_reasonable_case(c: &mut Criterion) {
|
||||
info!(
|
||||
"Building reasonable case block bench with {} validators",
|
||||
VALIDATOR_COUNT
|
||||
);
|
||||
|
||||
// Use the specifications from the Eth2.0 spec.
|
||||
let spec = ChainSpec::foundation();
|
||||
|
||||
// Create a builder for configuring the block and state for benching.
|
||||
let mut bench_builder = BlockBenchingBuilder::new(VALIDATOR_COUNT, &spec);
|
||||
|
||||
// Set the number of included operations to what we might expect normally.
|
||||
bench_builder.num_proposer_slashings = 0;
|
||||
bench_builder.num_attester_slashings = 0;
|
||||
bench_builder.num_attestations = (spec.shard_count / spec.slots_per_epoch) as usize;
|
||||
bench_builder.num_deposits = 2;
|
||||
bench_builder.num_exits = 2;
|
||||
bench_builder.num_transfers = 2;
|
||||
|
||||
// Set the state and block to be in the last slot of the 4th epoch.
|
||||
let last_slot_of_epoch = (spec.genesis_epoch + 4).end_slot(spec.slots_per_epoch);
|
||||
bench_builder.set_slot(last_slot_of_epoch, &spec);
|
||||
|
||||
// Build all the state caches so the build times aren't included in the benches.
|
||||
bench_builder.build_caches(&spec);
|
||||
|
||||
// Generate the block and state.
|
||||
let (block, state) = bench_builder.build(&spec);
|
||||
|
||||
// Run the benches.
|
||||
bench_block_processing::bench_block_processing(
|
||||
c,
|
||||
&block,
|
||||
&state,
|
||||
&spec,
|
||||
&format!("{}_validators/reasonable_case", VALIDATOR_COUNT),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn state_processing(c: &mut Criterion) {
|
||||
bench_epoch_processing::bench_epoch_processing_n_validators(c, VALIDATOR_COUNT);
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
block_processing_reasonable_case,
|
||||
block_processing_worst_case,
|
||||
state_processing
|
||||
);
|
||||
criterion_main!(benches);
|
||||
|
||||
Reference in New Issue
Block a user