mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
subsystem-bench: cache misses profiling (#2893)
## Why we need it To provide another level of understanding to why polkadot's subsystems may perform slower than expected. Cache misses occur when processing large amounts of data, such as during availability recovery. ## Why Cachegrind Cachegrind has many drawbacks: it is slow, it uses its own cache simulation, which is very basic. But unlike `perf`, which is a great tool, Cachegrind can run in a virtual machine. This means we can easily run it in remote installations and even use it in CI/CD to catch possible regressions. Why Cachegrind and not Callgrind, another part of Valgrind? It is simply empirically proven that profiling runs faster with Cachegrind. ## First results First results have been obtained while testing of the approach. Here is an example. ``` $ target/testnet/subsystem-bench --n-cores 10 --cache-misses data-availability-read $ cat cachegrind_report.txt I refs: 64,622,081,485 I1 misses: 3,018,168 LLi misses: 437,654 I1 miss rate: 0.00% LLi miss rate: 0.00% D refs: 12,161,833,115 (9,868,356,364 rd + 2,293,476,751 wr) D1 misses: 167,940,701 ( 71,060,073 rd + 96,880,628 wr) LLd misses: 33,550,018 ( 16,685,853 rd + 16,864,165 wr) D1 miss rate: 1.4% ( 0.7% + 4.2% ) LLd miss rate: 0.3% ( 0.2% + 0.7% ) LL refs: 170,958,869 ( 74,078,241 rd + 96,880,628 wr) LL misses: 33,987,672 ( 17,123,507 rd + 16,864,165 wr) LL miss rate: 0.0% ( 0.0% + 0.7% ) ``` The CLI output shows that 1.4% of the L1 data cache missed, which is not so bad, given that the last-level cache had that data most of the time missing only 0.3%. Instruction data of the L1 has 0.00% misses of the time. Looking at an output file with `cg_annotate` shows that most of the misses occur during reed-solomon, which is expected.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
//! A tool for running subsystem benchmark tests designed for development and
|
||||
//! CI regression testing.
|
||||
|
||||
use clap::Parser;
|
||||
use color_eyre::eyre;
|
||||
use pyroscope::PyroscopeAgent;
|
||||
@@ -27,6 +28,7 @@ use std::{path::Path, time::Duration};
|
||||
pub(crate) mod availability;
|
||||
pub(crate) mod cli;
|
||||
pub(crate) mod core;
|
||||
mod valgrind;
|
||||
|
||||
use availability::{prepare_test, NetworkEmulation, TestState};
|
||||
use cli::TestObjective;
|
||||
@@ -90,12 +92,21 @@ struct BenchCli {
|
||||
/// Pyroscope Sample Rate
|
||||
pub pyroscope_sample_rate: u32,
|
||||
|
||||
#[clap(long, default_value_t = false)]
|
||||
/// Enable Cache Misses Profiling with Valgrind. Linux only, Valgrind must be in the PATH
|
||||
pub cache_misses: bool,
|
||||
|
||||
#[command(subcommand)]
|
||||
pub objective: cli::TestObjective,
|
||||
}
|
||||
|
||||
impl BenchCli {
|
||||
fn launch(self) -> eyre::Result<()> {
|
||||
let is_valgrind_running = valgrind::is_valgrind_running();
|
||||
if !is_valgrind_running && self.cache_misses {
|
||||
return valgrind::relaunch_in_valgrind_mode()
|
||||
}
|
||||
|
||||
let agent_running = if self.profile {
|
||||
let agent = PyroscopeAgent::builder(self.pyroscope_url.as_str(), "subsystem-bench")
|
||||
.backend(pprof_backend(PprofConfig::new().sample_rate(self.pyroscope_sample_rate)))
|
||||
@@ -185,7 +196,7 @@ impl BenchCli {
|
||||
|
||||
let mut state = TestState::new(&test_config);
|
||||
let (mut env, _protocol_config) = prepare_test(test_config, &mut state);
|
||||
// test_config.write_to_disk();
|
||||
|
||||
env.runtime()
|
||||
.block_on(availability::benchmark_availability_read(&mut env, state));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user