Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
7b33492
Starting
shawntabrizi Jan 16, 2020
3b12740
closer
shawntabrizi Jan 21, 2020
55cf8b6
Compiles!
shawntabrizi Jan 21, 2020
9da52bb
comments
shawntabrizi Jan 21, 2020
27127c0
Create seperate mock
shawntabrizi Jan 21, 2020
ae84e9f
Remove changes to test env
shawntabrizi Jan 21, 2020
06d1173
Fix step calculation
shawntabrizi Jan 21, 2020
9f25cf5
Add host function
shawntabrizi Jan 22, 2020
621cc0d
Merge remote-tracking branch 'upstream/master' into shawntabrizi-iden…
shawntabrizi Jan 22, 2020
ddff026
Add runtime api
shawntabrizi Jan 22, 2020
b32c805
Merge remote-tracking branch 'upstream/master' into shawntabrizi-iden…
shawntabrizi Jan 22, 2020
890ad0d
compiles
shawntabrizi Jan 22, 2020
0a1bcfc
Update to use offchain timestamp
shawntabrizi Jan 23, 2020
931702b
Gives a result
shawntabrizi Jan 27, 2020
e8c4992
added some CLI wip
shawntabrizi Jan 28, 2020
334d1e6
Merge branch 'master' of github.com:paritytech/substrate into shawnta…
arkpar Jan 28, 2020
e5657e9
make generic
shawntabrizi Jan 28, 2020
32e9e07
Update instance
shawntabrizi Jan 28, 2020
1e2630c
Remove CLI stuff
shawntabrizi Jan 28, 2020
bafbac0
Remove last cli stuff
shawntabrizi Jan 28, 2020
86b32ef
undo more changes
shawntabrizi Jan 28, 2020
dd87c93
Update benchmarks
shawntabrizi Jan 29, 2020
6814c1a
Merge remote-tracking branch 'upstream/master' into shawntabrizi-iden…
shawntabrizi Jan 29, 2020
7c089f7
Update Cargo.lock
shawntabrizi Jan 29, 2020
7bd0ae1
remove test
shawntabrizi Jan 29, 2020
862dc67
Move loop out of runtime
shawntabrizi Jan 30, 2020
6d0c8b4
Benchmarking externalities
arkpar Feb 3, 2020
1575aae
Merge branch 'shawntabrizi-identity-bench' of github.com:paritytech/s…
arkpar Feb 3, 2020
3c5dcf7
Benchmarking state
arkpar Feb 3, 2020
d7c0ae8
Implemented commit
arkpar Feb 3, 2020
38602b8
Make CLI work, move loop back into runtime
shawntabrizi Feb 4, 2020
9614ea7
Merge branch 'master' of github.com:paritytech/substrate into shawnta…
arkpar Feb 4, 2020
e6eeab8
Merge branch 'shawntabrizi-identity-bench' of github.com:paritytech/s…
arkpar Feb 4, 2020
5ee888f
Wipe resets to genesis
arkpar Feb 4, 2020
e0b48d2
Merge branch 'master' of github.com:paritytech/substrate into shawnta…
arkpar Feb 5, 2020
d73ca25
Speedup benchmarks
arkpar Feb 5, 2020
879826c
Use enum to select extrinsic within pallet
shawntabrizi Feb 5, 2020
e041347
CLI controls which module and extrinsic to call
shawntabrizi Feb 5, 2020
115290b
Select a pallet with cli
shawntabrizi Feb 5, 2020
283860c
Add steps and repeats to cli
shawntabrizi Feb 5, 2020
978a1b4
Merge branch 'shawntabrizi-identity-bench' of https://github.com/pari…
shawntabrizi Feb 6, 2020
ca890f6
Output as CSV format
shawntabrizi Feb 6, 2020
1cb8529
Introduce benchmark pallet
shawntabrizi Feb 6, 2020
1c97bd9
Append bench
shawntabrizi Feb 7, 2020
ea5c3e1
Use Results
shawntabrizi Feb 7, 2020
94bff4b
Merge remote-tracking branch 'upstream/master' into shawntabrizi-iden…
shawntabrizi Feb 7, 2020
55a2e85
fix merge
shawntabrizi Feb 7, 2020
6787808
Clear Identity benchmark
shawntabrizi Feb 7, 2020
4c2b218
Bench request judgment and cancel request
shawntabrizi Feb 8, 2020
833c377
Add final benchmarks
shawntabrizi Feb 8, 2020
3e27b42
Fix CSV output
shawntabrizi Feb 8, 2020
34838f6
Start cleaning up for PR
shawntabrizi Feb 8, 2020
93422d4
Bump numbers in `wasmtime` integration tests.
shawntabrizi Feb 8, 2020
6bcf639
Merge remote-tracking branch 'upstream/master' into shawntabrizi-iden…
shawntabrizi Feb 8, 2020
f73ca4a
More docs
shawntabrizi Feb 8, 2020
eecaac0
Add rockdb feature to bench
shawntabrizi Feb 8, 2020
6243911
Fix formatting issues
shawntabrizi Feb 8, 2020
09804e1
Add test feature to bench
shawntabrizi Feb 9, 2020
00809ad
Add test feature to bench
shawntabrizi Feb 9, 2020
8d509d0
Add rocksdb feature flag
shawntabrizi Feb 9, 2020
fe2d0a2
Update bench.rs
gavofyork Feb 9, 2020
91827e5
Merge branch 'master' into shawntabrizi-identity-bench
gavofyork Feb 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Benchmarking externalities
  • Loading branch information
arkpar committed Feb 3, 2020
commit 6d0c8b4b073b0d3fbc49b8072a2b73d5f41f42b7
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bin/node-template/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use sc_cli::{display_role, informant, parse_and_prepare, ParseAndPrepare, NoCust
use sc_service::{AbstractService, Roles as ServiceRoles, Configuration};
use sp_consensus_aura::sr25519::{AuthorityPair as AuraPair};
use crate::chain_spec;
use node_template_runtime::opaque::Block;
use log::info;

/// Parse command line arguments into service configuration.
Expand Down Expand Up @@ -51,7 +52,7 @@ pub fn run<I, T, E>(args: I, exit: E, version: VersionInfo) -> error::Result<()>
ParseAndPrepare::CheckBlock(cmd) => cmd.run_with_builder(|config: Config<_>|
Ok(new_full_start!(config).0), load_spec, exit),
ParseAndPrepare::PurgeChain(cmd) => cmd.run(load_spec),
ParseAndPrepare::Benchmark(cmd) => cmd.run(load_spec),
ParseAndPrepare::Benchmark(cmd) => cmd.run::<Block, service::Executor, _, _, _>(load_spec),
ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder(|config: Config<_>|
Ok(new_full_start!(config).0), load_spec),
ParseAndPrepare::CustomCommand(_) => Ok(())
Expand Down
3 changes: 2 additions & 1 deletion bin/node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use sc_cli::{display_role, parse_and_prepare, GetSharedParams, ParseAndPrepare};
use crate::{service, ChainSpec, load_spec};
use crate::factory_impl::FactoryState;
use node_transaction_factory::RuntimeAdapter;
use node_runtime::Block;
use futures::{channel::oneshot, future::{select, Either}};

/// Custom subcommands.
Expand Down Expand Up @@ -136,7 +137,7 @@ pub fn run<I, T, E>(args: I, exit: E, version: sc_cli::VersionInfo) -> error::Re
ParseAndPrepare::CheckBlock(cmd) => cmd.run_with_builder(|config: Config<_, _>|
Ok(new_full_start!(config).0), load_spec, exit),
ParseAndPrepare::PurgeChain(cmd) => cmd.run(load_spec),
ParseAndPrepare::Benchmark(cmd) => cmd.run(load_spec),
ParseAndPrepare::Benchmark(cmd) => cmd.run::<Block, node_executor::Executor, _, _, _>(load_spec),
ParseAndPrepare::RevertChain(cmd) => cmd.run_with_builder(|config: Config<_, _>|
Ok(new_full_start!(config).0), load_spec),
ParseAndPrepare::CustomCommand(CustomSubcommands::Factory(cli_args)) => {
Expand Down
56 changes: 20 additions & 36 deletions client/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ where
ParseAndPreparePurge { params, version }
),
params::CoreParams::Benchmark(params) => ParseAndPrepare::Benchmark(
ParseAndPrepareBenchmark { params, version }
ParseAndPrepareBenchmark { params }
),
params::CoreParams::Revert(params) => ParseAndPrepare::RevertChain(
ParseAndPrepareRevert { params, version }
Expand Down Expand Up @@ -283,7 +283,7 @@ pub enum ParseAndPrepare<'a, CC, RP> {
/// Command ready to purge the chain.
PurgeChain(ParseAndPreparePurge<'a>),
/// Command ready to benchmark the chain.
Benchmark(ParseAndPrepareBenchmark<'a>),
Benchmark(ParseAndPrepareBenchmark),
/// Command ready to revert the chain.
RevertChain(ParseAndPrepareRevert<'a>),
/// An additional custom command passed to `parse_and_prepare`.
Expand All @@ -300,7 +300,7 @@ impl<'a, CC, RP> ParseAndPrepare<'a, CC, RP> where CC: GetSharedParams {
ParseAndPrepare::ImportBlocks(c) => Some(&c.params.shared_params),
ParseAndPrepare::CheckBlock(c) => Some(&c.params.shared_params),
ParseAndPrepare::PurgeChain(c) => Some(&c.params.shared_params),
ParseAndPrepare::Benchmark(c) => Some(&c.params.shared_params),
ParseAndPrepare::Benchmark(_) => None,
ParseAndPrepare::RevertChain(c) => Some(&c.params.shared_params),
ParseAndPrepare::CustomCommand(c) => c.shared_params(),
}
Expand Down Expand Up @@ -367,13 +367,8 @@ impl<'a, CC, RP> ParseAndPrepare<'a, CC, RP> {
c.version,
default_base_path,
)).transpose(),
ParseAndPrepare::Benchmark(c) =>
Some(create_config_with_db_path(
spec_factory,
&c.params.shared_params,
c.version,
default_base_path,
)).transpose(),
ParseAndPrepare::Benchmark(_) =>
Ok(None),
ParseAndPrepare::RevertChain(c) =>
Some(create_config_with_db_path(
spec_factory,
Expand Down Expand Up @@ -729,44 +724,33 @@ impl<'a> ParseAndPreparePurge<'a> {
}

/// Command ready to benchmark the runtime.
pub struct ParseAndPrepareBenchmark<'a> {
pub struct ParseAndPrepareBenchmark {
params: BenchmarkCmd,
version: &'a VersionInfo,
}

impl<'a> ParseAndPrepareBenchmark<'a> {
impl ParseAndPrepareBenchmark {
/// Runs the command and benchmarks the chain.
pub fn run<G, E, S>(
pub fn run<B, D, G, E, S>(
self,
spec_factory: S
) -> error::Result<()> where
B: BlockT,
D: sc_service::NativeExecutionDispatch + 'static,
S: FnOnce(&str) -> Result<Option<ChainSpec<G, E>>, String>,
G: RuntimeGenesis,
E: ChainSpecExtension,
{
let mut config = create_config_with_db_path::<(), _, _, _>(
spec_factory,
&self.params.shared_params,
self.version,
None,
)?;
fill_config_keystore_in_memory(&mut config)?;
let db_path = match config.database {
DatabaseConfig::Path { path, .. } => path,
_ => {
eprintln!("Cannot purge custom database implementation");
return Ok(());
}
let shared_params = SharedParams {
chain: self.params.chain,
dev: false,
base_path: None,
log: self.params.log
};

if self.params.pallet.is_some() {
print!("Input contains: {:?}", self.params.pallet.unwrap())
} else {
print!("Input is Empty");
}

pallet_identity::run_benchmarks();

init_logger(shared_params.log.as_ref().map(|v| v.as_ref()).unwrap_or(""));
let spec = load_spec(&shared_params, spec_factory)?;
let execution_strategy = self.params.execution.unwrap_or(ExecutionStrategy::Native).into();
let wasm_method = self.params.wasm_method.into();
sc_service::chain_ops::benchmark_runtime::<B, D>(execution_strategy, wasm_method)?;
Ok(())
}
}
Expand Down
29 changes: 26 additions & 3 deletions client/cli/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,32 @@ pub struct BenchmarkCmd {
#[structopt(short, long)]
pub pallet: Option<String>,

#[allow(missing_docs)]
#[structopt(flatten)]
pub shared_params: SharedParams,
/// The execution strategy that should be used for benchmarks
#[structopt(
long = "execution",
value_name = "STRATEGY",
possible_values = &ExecutionStrategy::variants(),
case_insensitive = true,
)]
pub execution: Option<ExecutionStrategy>,

/// Method for executing Wasm runtime code.
#[structopt(
long = "wasm-execution",
value_name = "METHOD",
possible_values = &WasmExecutionMethod::enabled_variants(),
case_insensitive = true,
default_value = "Interpreted"
)]
pub wasm_method: WasmExecutionMethod,

/// Specify the chain specification (one of dev, local or staging).
#[structopt(long = "chain", value_name = "CHAIN_SPEC")]
pub chain: Option<String>,

/// Sets a custom logging filter.
#[structopt(short = "l", long = "log", value_name = "LOG_PATTERN")]
pub log: Option<String>,
}

/// All core commands that are provided by default.
Expand Down
1 change: 1 addition & 0 deletions client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
parking_lot = "0.9.0"
log = "0.4.8"
rand = "0.7"
kvdb = "0.3.0"
kvdb-rocksdb = { version = "0.4", optional = true }
kvdb-memorydb = "0.3.0"
Expand Down
3 changes: 3 additions & 0 deletions client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

pub mod light;
pub mod offchain;
pub mod bench;

mod children;
mod cache;
Expand Down Expand Up @@ -79,6 +80,7 @@ use crate::storage_cache::{CachingState, SharedCache, new_shared_cache};
use crate::stats::StateUsageStats;
use log::{trace, debug, warn};
pub use sc_state_db::PruningMode;
pub use bench::BenchmarkingState;

#[cfg(feature = "test-helpers")]
use sc_client::in_mem::Backend as InMemoryBackend;
Expand All @@ -104,6 +106,7 @@ pub use kvdb;
pub struct RefTrackingState<Block: BlockT> {
state: DbState<Block>,
storage: Arc<StorageDb<Block>>,

parent_hash: Option<Block::Hash>,
}

Expand Down
28 changes: 27 additions & 1 deletion client/service/src/chain_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ use sp_runtime::traits::{
};
use sp_runtime::generic::{BlockId, SignedBlock};
use codec::{Decode, Encode, IoReader};
use sc_client::Client;
use sc_client::{Client, ExecutionStrategy, StateMachine};
use sc_client_db::BenchmarkingState;
use sp_consensus::import_queue::{IncomingBlock, Link, BlockImportError, BlockImportResult, ImportQueue};
use sp_consensus::BlockOrigin;
use sc_executor::{NativeExecutor, NativeExecutionDispatch, WasmExecutionMethod};

use std::{io::{Read, Write, Seek}, pin::Pin};

Expand All @@ -43,6 +45,30 @@ pub fn build_spec<G, E>(spec: ChainSpec<G, E>, raw: bool) -> error::Result<Strin
Ok(spec.to_json(raw)?)
}

pub fn benchmark_runtime<TBl: BlockT, TExecDisp: NativeExecutionDispatch + 'static>(
strategy: ExecutionStrategy,
wasm_method: WasmExecutionMethod,
) -> error::Result<()> {
let mut changes = Default::default();
let state = BenchmarkingState::<TBl>::new()?;
let executor = NativeExecutor::<TExecDisp>::new(
wasm_method,
None, // heap pages
);
let _ = StateMachine::<_, _, NumberFor<TBl>, _>::new(
&state,
None,
&mut changes,
&executor,
"run_benchmark",
&[],
Default::default(),
).execute(strategy).map_err(|e| format!("Error executing runtime benchmark: {:?}", e))?;
info!("Done.");
Ok(())
}


impl<
TBl, TRtApi, TCfg, TGen, TCSExt, TBackend,
TExec, TFchr, TSc, TImpQu, TFprb, TFpp, TNetP,
Expand Down
1 change: 1 addition & 0 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub use sp_transaction_pool::{TransactionPool, InPoolTransaction, error::IntoPoo
pub use sc_transaction_pool::txpool::Options as TransactionPoolOptions;
pub use sc_client::FinalityNotifications;
pub use sc_rpc::Metadata as RpcMetadata;
pub use sc_executor::NativeExecutionDispatch;
#[doc(hidden)]
pub use std::{ops::Deref, result::Result, sync::Arc};
#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ pub use crate::{
},
leaves::LeafSet,
};
pub use sp_state_machine::{ExecutionStrategy, StorageProof};
pub use sp_state_machine::{ExecutionStrategy, StorageProof, StateMachine};
9 changes: 9 additions & 0 deletions primitives/externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ pub trait Externalities: ExtensionStore {
///
/// Returns the SCALE encoded hash.
fn storage_changes_root(&mut self, parent: &[u8]) -> Result<Option<Vec<u8>>, ()>;


fn wipe(&mut self) {
unimplemented!()
}

fn commit(&mut self) {
unimplemented!()
}
}

/// Extension for the [`Externalities`] trait.
Expand Down
10 changes: 10 additions & 0 deletions primitives/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,16 @@ pub trait Benchmarking {
.expect("Unix time doesn't go backwards; qed")
.as_nanos()
}

/// Reset state to empty.
fn wipe_db(&mut self) {
self.wipe()
}

/// Commit pending storage changes to the trie database.
fn commit_db(&mut self) {
self.commit()
}
}

/// Wasm-only interface that provides functions for interacting with the sandbox.
Expand Down
10 changes: 10 additions & 0 deletions primitives/state-machine/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ pub trait Backend<H: Hasher>: std::fmt::Debug {
fn usage_info(&self) -> UsageInfo {
UsageInfo::empty()
}

/// Wipe the state database.
fn wipe(&mut self) -> Result<(), Self::Error> {
unimplemented!()
}

/// Commit given transaction to storage.
fn commit(&mut self, _storage_root: H::Out, _transaction: Self::Transaction) -> Result<(), Self::Error> {
unimplemented!()
}
}

impl<'a, T: Backend<H>, H: Hasher> Backend<H> for &'a T {
Expand Down
18 changes: 18 additions & 0 deletions primitives/state-machine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,24 @@ where

root.map(|r| r.map(|o| o.encode()))
}

fn wipe(&mut self) {
self.overlay.drain_storage_changes(&self.backend, None, Default::default(), self.storage_transaction_cache)
.expect(EXT_NOT_ALLOWED_TO_FAIL);
self.storage_transaction_cache.reset();
self.backend.wipe().expect(EXT_NOT_ALLOWED_TO_FAIL)
}

fn commit(&mut self) {
self.overlay.commit_prospective();
self.overlay.drain_storage_changes(&self.backend, None, Default::default(), self.storage_transaction_cache)
.expect(EXT_NOT_ALLOWED_TO_FAIL);
self.backend.commit(
self.storage_transaction_cache.transaction_storage_root.take().expect(EXT_NOT_ALLOWED_TO_FAIL),
self.storage_transaction_cache.transaction.take().expect(EXT_NOT_ALLOWED_TO_FAIL),
).expect(EXT_NOT_ALLOWED_TO_FAIL);
self.storage_transaction_cache.reset();
}
}

impl<'a, H, B, N> sp_externalities::ExtensionStore for Ext<'a, H, N, B>
Expand Down
Loading