forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PVF: Add worker check during tests and benches (paritytech#1771)
- Loading branch information
Showing
19 changed files
with
285 additions
and
113 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
130 changes: 130 additions & 0 deletions
130
polkadot/node/core/pvf/benches/host_prepare_rococo_runtime.rs
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 |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot 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 General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Benchmarks for preparation through the host. We use a real PVF to get realistic results. | ||
|
||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion, SamplingMode}; | ||
use parity_scale_codec::Encode; | ||
use polkadot_node_core_pvf::{ | ||
start, testing, Config, Metrics, PrepareError, PrepareJobKind, PrepareStats, PvfPrepData, | ||
ValidationError, ValidationHost, | ||
}; | ||
use polkadot_parachain_primitives::primitives::{BlockData, ValidationParams, ValidationResult}; | ||
use polkadot_primitives::ExecutorParams; | ||
use rococo_runtime::WASM_BINARY; | ||
use std::time::Duration; | ||
use tokio::{runtime::Handle, sync::Mutex}; | ||
|
||
const TEST_EXECUTION_TIMEOUT: Duration = Duration::from_secs(3); | ||
const TEST_PREPARATION_TIMEOUT: Duration = Duration::from_secs(30); | ||
|
||
struct TestHost { | ||
host: Mutex<ValidationHost>, | ||
} | ||
|
||
impl TestHost { | ||
fn new_with_config<F>(handle: &Handle, f: F) -> Self | ||
where | ||
F: FnOnce(&mut Config), | ||
{ | ||
let (prepare_worker_path, execute_worker_path) = testing::get_and_check_worker_paths(); | ||
|
||
let cache_dir = tempfile::tempdir().unwrap(); | ||
let mut config = Config::new( | ||
cache_dir.path().to_owned(), | ||
None, | ||
prepare_worker_path, | ||
execute_worker_path, | ||
); | ||
f(&mut config); | ||
let (host, task) = start(config, Metrics::default()); | ||
let _ = handle.spawn(task); | ||
Self { host: Mutex::new(host) } | ||
} | ||
|
||
async fn precheck_pvf( | ||
&self, | ||
code: &[u8], | ||
executor_params: ExecutorParams, | ||
) -> Result<PrepareStats, PrepareError> { | ||
let (result_tx, result_rx) = futures::channel::oneshot::channel(); | ||
|
||
let code = sp_maybe_compressed_blob::decompress(code, 16 * 1024 * 1024) | ||
.expect("Compression works"); | ||
|
||
self.host | ||
.lock() | ||
.await | ||
.precheck_pvf( | ||
PvfPrepData::from_code( | ||
code.into(), | ||
executor_params, | ||
TEST_PREPARATION_TIMEOUT, | ||
PrepareJobKind::Prechecking, | ||
), | ||
result_tx, | ||
) | ||
.await | ||
.unwrap(); | ||
result_rx.await.unwrap() | ||
} | ||
} | ||
|
||
fn host_prepare_rococo_runtime(c: &mut Criterion) { | ||
polkadot_node_core_pvf_common::sp_tracing::try_init_simple(); | ||
|
||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
|
||
let blob = WASM_BINARY.expect("You need to build the WASM binaries to run the tests!"); | ||
let pvf = match sp_maybe_compressed_blob::decompress(&blob, 64 * 1024 * 1024) { | ||
Ok(code) => PvfPrepData::from_code( | ||
code.into_owned(), | ||
ExecutorParams::default(), | ||
Duration::from_secs(360), | ||
PrepareJobKind::Compilation, | ||
), | ||
Err(e) => { | ||
panic!("Cannot decompress blob: {:?}", e); | ||
}, | ||
}; | ||
|
||
let mut group = c.benchmark_group("prepare rococo"); | ||
group.sampling_mode(SamplingMode::Flat); | ||
group.sample_size(20); | ||
group.measurement_time(Duration::from_secs(240)); | ||
group.bench_function("host: prepare Rococo runtime", |b| { | ||
b.to_async(&rt).iter_batched( | ||
|| { | ||
( | ||
TestHost::new_with_config(rt.handle(), |cfg| { | ||
cfg.prepare_workers_hard_max_num = 1; | ||
}), | ||
pvf.clone().code(), | ||
) | ||
}, | ||
|(host, pvf_code)| async move { | ||
// `PvfPrepData` is designed to be cheap to clone, so cloning shouldn't affect the | ||
// benchmark accuracy. | ||
let _stats = host.precheck_pvf(&pvf_code, Default::default()).await.unwrap(); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(prepare, host_prepare_rococo_runtime); | ||
criterion_main!(prepare); |
This file was deleted.
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
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
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
Oops, something went wrong.