From 2b1fc459c7bb646ba7a0688660a4d067207ad695 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 16 Jul 2018 20:59:10 +0200 Subject: [PATCH] Adaptive heap size (#328) * heap-size is a CLI arg, make it 512 by default * Fix tests * Adaptive heap size. * Allow storage_exists --- polkadot/api/src/full.rs | 2 +- polkadot/cli/src/cli.yml | 20 ++++++++++++++++++++ polkadot/cli/src/lib.rs | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/polkadot/api/src/full.rs b/polkadot/api/src/full.rs index 7a5aeb31e7..caf9a89072 100644 --- a/polkadot/api/src/full.rs +++ b/polkadot/api/src/full.rs @@ -200,7 +200,7 @@ mod tests { timestamp: Some(Default::default()), }; - ::client::new_in_mem(LocalDispatch::with_heap_pages(8), genesis_config).unwrap() + ::client::new_in_mem(LocalDispatch::with_heap_pages(8, 8), genesis_config).unwrap() } #[test] diff --git a/polkadot/cli/src/cli.yml b/polkadot/cli/src/cli.yml index bb6f1defbf..ad4eb51ab6 100644 --- a/polkadot/cli/src/cli.yml +++ b/polkadot/cli/src/cli.yml @@ -99,6 +99,14 @@ args: long: execution value_name: STRATEGY help: The means of execution used when calling into the runtime. Can be either wasm, native or both. + - min-heap-pages: + long: min-heap-pages + value_name: COUNT + help: The number of 64KB pages to allocate for Wasm execution initially. + - max-heap-pages: + long: max-heap-pages + value_name: COUNT + help: The maximum number of 64KB pages to ever allocate for Wasm execution. Don't alter this unless you know what you're doing. subcommands: - build-spec: about: Build a spec.json file, outputing to stdout @@ -162,3 +170,15 @@ subcommands: value_name: PATH help: Specify custom base path. takes_value: true + - execution: + long: execution + value_name: STRATEGY + help: The means of execution used when calling into the runtime. Can be either wasm, native or both. + - min-heap-pages: + long: min-heap-pages + value_name: COUNT + help: The number of 64KB pages to allocate for Wasm execution initially. + - max-heap-pages: + long: max-heap-pages + value_name: COUNT + help: The maximum number of 64KB pages to ever allocate for Wasm execution. Don't alter this unless you know what you're doing. diff --git a/polkadot/cli/src/lib.rs b/polkadot/cli/src/lib.rs index 791010b128..9cc7e3020d 100644 --- a/polkadot/cli/src/lib.rs +++ b/polkadot/cli/src/lib.rs @@ -237,6 +237,13 @@ pub fn run(args: I, worker: W) -> error::Result<()> where service::Roles::FULL }; + if let Some(v) = matches.value_of("min-heap-pages") { + config.min_heap_pages = v.parse().map_err(|_| "Invalid --min-heap-pages argument")?; + } + if let Some(v) = matches.value_of("max-heap-pages") { + config.max_heap_pages = v.parse().map_err(|_| "Invalid --max-heap-pages argument")?; + } + if let Some(s) = matches.value_of("execution") { config.execution_strategy = match s { "both" => service::ExecutionStrategy::Both, @@ -393,6 +400,23 @@ fn import_blocks(matches: &clap::ArgMatches, exit: E) -> error::Result<()> let base_path = base_path(matches); let mut config = service::Configuration::default_with_spec(spec); config.database_path = db_path(&base_path, config.chain_spec.id()).to_string_lossy().into(); + + if let Some(v) = matches.value_of("min-heap-pages") { + config.min_heap_pages = v.parse().map_err(|_| "Invalid --min-heap-pages argument")?; + } + if let Some(v) = matches.value_of("max-heap-pages") { + config.max_heap_pages = v.parse().map_err(|_| "Invalid --max-heap-pages argument")?; + } + + if let Some(s) = matches.value_of("execution") { + config.execution_strategy = match s { + "both" => service::ExecutionStrategy::Both, + "native" => service::ExecutionStrategy::NativeWhenPossible, + "wasm" => service::ExecutionStrategy::AlwaysWasm, + _ => return Err(error::ErrorKind::Input("Invalid execution mode specified".to_owned()).into()), + }; + } + let client = service::new_client(config)?; let (exit_send, exit_recv) = std::sync::mpsc::channel();