1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use log::info;
use polkadot_node_core_pvf::sp_maybe_compressed_blob;
use polkadot_performance_test::{
measure_erasure_coding, measure_pvf_prepare, PerfCheckError, ERASURE_CODING_N_VALIDATORS,
ERASURE_CODING_TIME_LIMIT, PVF_PREPARE_TIME_LIMIT, VALIDATION_CODE_BOMB_LIMIT,
};
use std::time::Duration;
pub fn host_perf_check() -> Result<(), PerfCheckError> {
let pvf_prepare_time_limit = time_limit_from_baseline(PVF_PREPARE_TIME_LIMIT);
let erasure_coding_time_limit = time_limit_from_baseline(ERASURE_CODING_TIME_LIMIT);
let wasm_code =
polkadot_performance_test::WASM_BINARY.ok_or(PerfCheckError::WasmBinaryMissing)?;
let code = sp_maybe_compressed_blob::decompress(wasm_code, VALIDATION_CODE_BOMB_LIMIT)
.or(Err(PerfCheckError::CodeDecompressionFailed))?;
info!("Running the performance checks...");
perf_check("PVF-prepare", pvf_prepare_time_limit, || measure_pvf_prepare(code.as_ref()))?;
perf_check("Erasure-coding", erasure_coding_time_limit, || {
measure_erasure_coding(ERASURE_CODING_N_VALIDATORS, code.as_ref())
})?;
Ok(())
}
fn green_threshold(duration: Duration) -> Duration {
duration * 4 / 5
}
fn time_limit_from_baseline(duration: Duration) -> Duration {
duration * 3 / 2
}
fn perf_check(
test_name: &str,
time_limit: Duration,
test: impl Fn() -> Result<Duration, PerfCheckError>,
) -> Result<(), PerfCheckError> {
let elapsed = test()?;
if elapsed < green_threshold(time_limit) {
info!("🟢 {} performance check passed, elapsed: {:?}", test_name, elapsed);
Ok(())
} else if elapsed <= time_limit {
info!(
"🟡 {} performance check passed, {:?} limit almost exceeded, elapsed: {:?}",
test_name, time_limit, elapsed
);
Ok(())
} else {
Err(PerfCheckError::TimeOut { elapsed, limit: time_limit })
}
}