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
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
move to shared
  • Loading branch information
NikVolf committed Sep 30, 2020
commit d6bb5e185e915cf2dd76d2ffff25c5601bdbcfbb
25 changes: 0 additions & 25 deletions bin/node/bench/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,31 +179,6 @@ impl core::Benchmark for TrieReadBenchmark {
fn run(&mut self, mode: Mode) -> std::time::Duration {
let mut db = self.database.clone();

// We clear system cache after db clone but before warmup keys query
// This populates system cache with some data unrelated to actual
// keys we are quering under benchmark (like what would have happened
// in real system that queries random keys).
#[cfg(target_os = "linux")] {
log::trace!(target: "benchmark-logistics", "Clearing system cache...");
std::process::Command::new("echo")
.args(&["1", ">", "/proc/sys/vm/drop_caches"])
.status()
.expect("Failed to execute system cache clear");
log::trace!(target: "benchmark-logistics", "Clearing system cache done!");
}

#[cfg(target_os = "macos")] {
log::trace!(target: "benchmark-logistics", "Clearing system cache...");
std::process::Command::new("sync")
.status()
.expect("Failed to execute sync");
std::process::Command::new("sudo")
.arg("purge")
.status()
.expect("Failed to execute sudo purge");
log::trace!(target: "benchmark-logistics", "Clearing system cache done!");
}

let storage: Arc<dyn sp_state_machine::Storage<sp_core::Blake2Hasher>> =
Arc::new(Storage(db.open(self.database_type)));

Expand Down
34 changes: 34 additions & 0 deletions bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,33 @@ impl BenchPair {
}
}

/// Drop system cache.
///
/// Will panic if cache drop is impossbile.
pub fn drop_system_cache() {
#[cfg(target_os = "linux")] {
log::trace!(target: "bench-logistics", "Clearing system cache...");
std::process::Command::new("echo")
.args(&["1", ">", "/proc/sys/vm/drop_caches", "2>", "/dev/null"])
.output()
.expect("Failed to execute system cache clear");
log::trace!(target: "bench-logistics", "Clearing system cache done!");
}

#[cfg(target_os = "macos")] {
log::trace!(target: "bench-logistics", "Clearing system cache...");
std::process::Command::new("sync")
.output()
.expect("Failed to execute sync");
if let Err(err) = std::process::Command::new("purge").output() {
log::error!("purge error {:?}: ", err);
panic!("Could not clear system cache. Run under sudo?");
}
log::trace!(target: "bench-logistics", "Clearing system cache done!");
}

}

/// Pre-initialized benchmarking database.
///
/// This is prepared database with genesis and keyring
Expand Down Expand Up @@ -124,6 +151,13 @@ impl Clone for BenchDb {
&fs_extra::dir::CopyOptions::new(),
).expect("Copy of seed database is ok");

// We clear system cache after db clone but before any warmups.
// This populates system cache with some data unrelated to actual
// data we will be quering further under benchmark (like what
// would have happened in real system that queries random entries
// from database).
drop_system_cache();

BenchDb { keyring, directory_guard: Guard(dir), database_type }
}
}
Expand Down