Skip to content
Snippets Groups Projects
Commit a6cee971 authored by Benjamin Gallois's avatar Benjamin Gallois Committed by Hugo Trentesaux
Browse files

Storage benchmark (!167)

* Add extrinsic_weights benchmark

* Fix block_weights benchmark
parent af021cba
No related branches found
No related tags found
1 merge request!167Storage benchmark
Pipeline #31967 failed
......@@ -909,6 +909,7 @@ dependencies = [
"sp-runtime",
"sp-staking",
"sp-std",
"sp-weights",
]
[[package]]
......
......@@ -24,16 +24,16 @@ cargo test -p <pallet> --features runtime-benchmarks
```
3. If the benchmark tests compiles and pass, compile the binary with benchmarks on your local
machine:
machine:
```
cargo build --release --features runtime-benchmarks
```
4. Run the benchmarks on your local machine (to test if it work with a real runtime). See 0d1232cd0d8b5809e1586b48376f8952cebc0d27 for a complete real example. The command is:
4. Run the benchmarks on your local machine (to test if it work with a real runtime). See 0d1232cd0d8b5809e1586b48376f8952cebc0d27 for a complete real example. The command is:
```
duniter benchmark pallet --chain=CHAINSPEC --steps=50 --repeat=20 --pallet=<pallet> --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/common/src/weights/
duniter benchmark pallet --chain=CHAINSPEC --steps=50 --repeat=20 --pallet=<pallet> --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/common/src/weights/
```
5. Use the generated file content to create the `WeightInfo` trait and the `()` dummy implementation in `pallets/<pallet>/src/weights.rs`. Then use the `WeightInfo` trait in the real code of the pallet. See 62dcc17f2c0b922e883fbc6337a9e7da97fc3218 for a complete real example.
......@@ -42,7 +42,7 @@ duniter benchmark pallet --chain=CHAINSPEC --steps=50 --repeat=20 --pallet=<pall
7. Use the `runtime/common/src/weights/pallet_<pallet>.rs` generated on the reference machine in the runtimes configuration. See af62a3b9cfc42d6653b3a957836f58540c18e65a for a complete real example.
Note 1: Use relevant chainspec for the benchmarks in place of `CHAINSPEC`. For example `--chain=gdev-benchmark` has already created identities that can be confirmed by pallet identity
Note 1: Use relevant chainspec for the benchmarks in place of `CHAINSPEC`. For example `--chain=gdev-benchmark` has already created identities that can be confirmed by pallet identity
Note 2: If the reference machine does not support wasmtime, you should replace `--wasm-execution=compiled`
by `--wasm-execution=interpreted-i-know-what-i-do`.
......@@ -53,11 +53,10 @@ by `--wasm-execution=interpreted-i-know-what-i-do`.
2. Run base block benchmarks command:
```
duniter benchmark overhead --chain=gdev --execution=wasm --wasm-execution=interpreted-i-know-what-i-do --weight-path=. --warmup=10 --repeat=100
duniter benchmark overhead --chain=gdev-benchmark --execution=wasm --wasm-execution=compiled --weight-path=./runtime/common/src/weights/ --warmup=10 --repeat=100
```
3. Copy the generated file `block_weights.rs` in the codebase in folder `runtime/common/src/weights/`.
4. Commit changes and open an MR.
3. Commit changes and open an MR.
## Generate storage benchmarking
......
......@@ -58,6 +58,7 @@ std = [
'sp-membership/std',
'sp-runtime/std',
'sp-std/std',
'sp-weights/std',
]
try-runtime = [
"frame-support/try-runtime",
......@@ -110,6 +111,7 @@ sp-consensus-babe = { git = 'https://github.com/duniter/substrate', branch = 'du
sp-core = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-runtime = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-std = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
sp-weights = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.32', default-features = false }
# substrate benchmarks
......
......@@ -69,7 +69,7 @@ pub fn block_weights(
expected_block_weight: Weight,
normal_ratio: sp_arithmetic::Perbill,
) -> frame_system::limits::BlockWeights {
let base_weight = DbWeight::get().reads(1) + DbWeight::get().writes(1);
let base_weight = crate::weights::extrinsic_weights::ExtrinsicBaseWeight::get();
let normal_weight = normal_ratio * expected_block_weight;
frame_system::limits::BlockWeights::builder()
.base_block(crate::weights::block_weights::BlockExecutionWeight::get())
......
......@@ -177,7 +177,10 @@ macro_rules! pallets_config {
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = OneshotAccount;
type OperationalFeeMultiplier = frame_support::traits::ConstU8<5>;
#[cfg(not(feature = "runtime-benchmarks"))]
type WeightToFee = common_runtime::fees::WeightToFeeImpl<Balance>;
#[cfg(feature = "runtime-benchmarks")]
type WeightToFee = frame_support::weights::ConstantMultiplier::<u64, sp_core::ConstU64<0u64>>;
type LengthToFee = common_runtime::fees::LengthToFeeImpl<Balance>;
type FeeMultiplierUpdate = ();
type RuntimeEvent = RuntimeEvent;
......
......@@ -20,6 +20,7 @@
#![allow(clippy::unnecessary_cast)]
pub mod block_weights;
pub mod extrinsic_weights;
pub mod frame_system;
pub mod pallet_babe;
pub mod pallet_balances;
......
// Copyright 2021 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-11-18 (Y/M/D)
//! HOSTNAME: `raspberrypi`, CPU: `ARMv7 Processor rev 3 (v7l)`
//! DATE: 2023-05-19 (Y/M/D)
//! HOSTNAME: `benjamin-xps139380`, CPU: `Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz`
//!
//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Ğdev`
//! SHORT-NAME: `block`, LONG-NAME: `BlockExecution`, RUNTIME: `Development`
//! WARMUPS: `10`, REPEAT: `100`
//! WEIGHT-PATH: `.`
//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1`, WEIGHT-ADD: `0`
//! WEIGHT-PATH: `runtime/common/src/weights/`
//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1.0`, WEIGHT-ADD: `0`
// Executed Command:
// ./duniter
// target/release/duniter
// benchmark
// overhead
// --chain=gdev
// --chain=gdev-benchmark
// --execution=wasm
// --wasm-execution=interpreted-i-know-what-i-do
// --weight-path=.
// --wasm-execution=compiled
// --weight-path=runtime/common/src/weights/
// --warmup=10
// --repeat=100
use frame_support::{
parameter_types,
weights::{constants::WEIGHT_PER_NANOS, Weight},
};
use sp_core::parameter_types;
use sp_weights::{constants::WEIGHT_PER_NANOS, Weight};
parameter_types! {
/// Time to execute an empty block.
/// Calculated by multiplying the *Average* with `1` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 23_866_638, 90_077_105
/// Average: 24_871_527
/// Median: 23_915_377
/// Std-Dev: 6645558.32
///
/// Percentiles nanoseconds:
/// 99th: 30_529_787
/// 95th: 27_134_555
/// 75th: 23_951_395
pub const BlockExecutionWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(24_871_527);
/// Time to execute an empty block.
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 698_202, 838_988
/// Average: 709_232
/// Median: 704_251
/// Std-Dev: 15664.54
///
/// Percentiles nanoseconds:
/// 99th: 738_574
/// 95th: 729_596
/// 75th: 709_823
pub const BlockExecutionWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(709_232);
}
#[cfg(test)]
mod test_weights {
use frame_support::weights::constants;
use sp_weights::constants;
/// Checks that the weight exists and is sane.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
let w = super::BlockExecutionWeight::get();
/// Checks that the weight exists and is sane.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
let w = super::BlockExecutionWeight::get();
// At least 100 µs.
assert!(
w.ref_time() >= 100u64 * constants::WEIGHT_PER_MICROS.ref_time(),
"Weight should be at least 100 µs."
);
// At most 50 ms.
assert!(
w.ref_time() <= 50u64 * constants::WEIGHT_PER_MILLIS.ref_time(),
"Weight should be at most 50 ms."
);
}
// At least 100 µs.
assert!(
w.ref_time() >= 100u64 * constants::WEIGHT_PER_MICROS.ref_time(),
"Weight should be at least 100 µs."
);
// At most 50 ms.
assert!(
w.ref_time() <= 50u64 * constants::WEIGHT_PER_MILLIS.ref_time(),
"Weight should be at most 50 ms."
);
}
}
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-05-19 (Y/M/D)
//! HOSTNAME: `benjamin-xps139380`, CPU: `Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz`
//!
//! SHORT-NAME: `extrinsic`, LONG-NAME: `ExtrinsicBase`, RUNTIME: `Development`
//! WARMUPS: `10`, REPEAT: `100`
//! WEIGHT-PATH: `runtime/common/src/weights/`
//! WEIGHT-METRIC: `Average`, WEIGHT-MUL: `1.0`, WEIGHT-ADD: `0`
// Executed Command:
// target/release/duniter
// benchmark
// overhead
// --chain=gdev-benchmark
// --execution=wasm
// --wasm-execution=compiled
// --weight-path=runtime/common/src/weights/
// --warmup=10
use sp_core::parameter_types;
use sp_weights::{constants::WEIGHT_PER_NANOS, Weight};
parameter_types! {
/// Time to execute a NO-OP extrinsic, for example `System::remark`.
/// Calculated by multiplying the *Average* with `1.0` and adding `0`.
///
/// Stats nanoseconds:
/// Min, Max: 203_855, 206_882
/// Average: 204_580
/// Median: 204_521
/// Std-Dev: 405.03
///
/// Percentiles nanoseconds:
/// 99th: 205_581
/// 95th: 205_130
/// 75th: 204_772
pub const ExtrinsicBaseWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(204_580);
}
#[cfg(test)]
mod test_weights {
use sp_weights::constants;
/// Checks that the weight exists and is sane.
// NOTE: If this test fails but you are sure that the generated values are fine,
// you can delete it.
#[test]
fn sane() {
let w = super::ExtrinsicBaseWeight::get();
// At least 10 µs.
assert!(
w.ref_time() >= 10u64 * constants::WEIGHT_PER_MICROS.ref_time(),
"Weight should be at least 10 µs."
);
// At most 1 ms.
assert!(
w.ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
"Weight should be at most 1 ms."
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment