diff --git a/Cargo.lock b/Cargo.lock index 7512b4c4f75..c0a1a08c709 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1889,18 +1889,6 @@ dependencies = [ "instant", ] -[[package]] -name = "filetime" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0408e2626025178a6a7f7ffc05a25bc47103229f19c113755de7bf63816290c" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall 0.2.13", - "winapi", -] - [[package]] name = "firestorm" version = "0.5.0" @@ -2964,11 +2952,8 @@ version = "0.0.0" dependencies = [ "actix", "actix-rt", - "actix-web", "anyhow", "clap 3.1.18", - "criterion", - "flate2", "futures", "near-actix-test-utils", "near-async", @@ -2990,7 +2975,6 @@ dependencies = [ "rayon", "serde", "serde_json", - "tar", "tempfile", "tokio", "tracing", @@ -6073,17 +6057,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "tar" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" -dependencies = [ - "filetime", - "libc", - "xattr", -] - [[package]] name = "target-lexicon" version = "0.10.0" @@ -7425,15 +7398,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "xattr" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" -dependencies = [ - "libc", -] - [[package]] name = "xml-rs" version = "0.8.4" diff --git a/tools/mock-node/Cargo.toml b/tools/mock-node/Cargo.toml index ee13d377205..e088be38094 100644 --- a/tools/mock-node/Cargo.toml +++ b/tools/mock-node/Cargo.toml @@ -7,17 +7,14 @@ edition.workspace = true [dependencies] actix-rt.workspace = true -actix-web.workspace = true actix.workspace = true anyhow.workspace = true clap.workspace = true -flate2.workspace = true futures.workspace = true rand.workspace = true rayon.workspace = true serde.workspace = true serde_json.workspace = true -tar.workspace = true tempfile.workspace = true tokio.workspace = true tracing.workspace = true @@ -39,13 +36,6 @@ near-performance-metrics = { path = "../../utils/near-performance-metrics" } near-primitives = { path = "../../core/primitives" } nearcore = { path = "../../nearcore" } -[dev-dependencies] -criterion.workspace = true - -[[bench]] -name = "sync" -harness = false - [[bin]] name = "mock-node" # To make mock node work, we must disable some checks in chain, which is controlled by this feature. diff --git a/tools/mock-node/benches/README.md b/tools/mock-node/benches/README.md deleted file mode 100644 index f17d5c4a270..00000000000 --- a/tools/mock-node/benches/README.md +++ /dev/null @@ -1,37 +0,0 @@ - -The benchmarks in this directory use the mock node framework to define -benchmarks that measure the time taken to sync from an empty home dir -to a particular height in the chain defined by the sample home -directory archives included here. To run all the benchmarks: - -```shell -$ cargo bench -p mock-node -F mock_node -``` - -This will take quite a while though, as each iteration of the -benchmark `mock_node_sync_full` takes several minutes, and it's run 10 -times. To run just the quicker one: - -```shell -$ cargo bench -p mock-node -F mock_node -- mock_node_sync_empty -``` - -You can pretty easily define and run your own benchmark based on some -other source home directory by creating a gzipped tar archive and -moving it to, say, `tools/mock_node/benches/foo.tar.gz`, and modifying -the code like so: - -```diff ---- a/tools/mock_node/benches/sync.rs -+++ b/tools/mock_node/benches/sync.rs -@@ -123,5 +123,9 @@ fn sync_full_chunks(c: &mut Criterion) { - do_bench(c, "./benches/full.tar.gz", Some(100)) - } - --criterion_group!(benches, sync_empty_chunks, sync_full_chunks); -+fn sync_foo_chunks(c: &mut Criterion) { -+ do_bench(c, "./benches/foo.tar.gz", Some(123)) -+} -+ -+criterion_group!(benches, sync_empty_chunks, sync_full_chunks, sync_foo_chunks); -``` diff --git a/tools/mock-node/benches/empty.tar.gz b/tools/mock-node/benches/empty.tar.gz deleted file mode 100644 index 8d3802316b7..00000000000 Binary files a/tools/mock-node/benches/empty.tar.gz and /dev/null differ diff --git a/tools/mock-node/benches/full.tar.gz b/tools/mock-node/benches/full.tar.gz deleted file mode 100644 index 31528c43063..00000000000 Binary files a/tools/mock-node/benches/full.tar.gz and /dev/null differ diff --git a/tools/mock-node/benches/sync.rs b/tools/mock-node/benches/sync.rs deleted file mode 100644 index 361b5f7a182..00000000000 --- a/tools/mock-node/benches/sync.rs +++ /dev/null @@ -1,147 +0,0 @@ -#[macro_use] -extern crate criterion; - -use actix::System; -use anyhow::anyhow; -use criterion::Criterion; -use flate2::read::GzDecoder; -use mock_node::setup::{setup_mock_node, MockNode}; -use mock_node::MockNetworkConfig; -use near_actix_test_utils::{block_on_interruptible, setup_actix}; -use near_chain_configs::GenesisValidationMode; -use near_client::GetBlock; -use near_crypto::{InMemorySigner, KeyType}; -use near_o11y::WithSpanContextExt; -use near_primitives::types::BlockHeight; -use std::fs::File; -use std::path::{Path, PathBuf}; -use std::time::{Duration, Instant}; -use tar::Archive; - -// The point of this is to return this struct from the benchmark -// function so that we can run the code in its drop() function after the -// benchmark has been measured. It would be possible to just run all -// that code in the benchmark function, but we don't really want to -// include that in the measurements. -struct Sys { - sys: Option, - servers: Vec<(&'static str, actix_web::dev::ServerHandle)>, -} - -impl Drop for Sys { - fn drop(&mut self) { - // TODO: we only have to do this because shutdown is not well handled right now. Ideally we would not have - // to tear down the whole system, and could just stop the client actor/view client actors each time. - let system = System::current(); - let sys = self.sys.take().unwrap(); - - sys.block_on(async move { - futures::future::join_all(self.servers.iter().map(|(_name, server)| async move { - server.stop(true).await; - })) - .await; - }); - system.stop(); - sys.run().unwrap(); - near_store::db::RocksDB::block_until_all_instances_are_dropped(); - } -} - -/// "./benches/empty.tar.gz" -> "empty" -fn test_name(home_archive: &str) -> &str { - Path::new(home_archive.strip_suffix(".tar.gz").unwrap()).file_name().unwrap().to_str().unwrap() -} - -/// "./benches/empty.tar.gz" -> "/tmp/near_mock_node_sync_empty" -fn extracted_path(home_archive: &str) -> anyhow::Result { - if !home_archive.ends_with(".tar.gz") { - return Err(anyhow!("{} doesn't end with .tar.gz", home_archive)); - } - let mut ret = PathBuf::from("/tmp"); - let dir_name = String::from("near_mock_node_sync_") + test_name(home_archive); - ret.push(dir_name); - Ok(ret) -} - -// Expects home_archive to be a gzipped tar archive and extracts -// it to a /tmp directory if not already extracted. -fn extract_home(home_archive: &str) -> anyhow::Result { - let extracted = extracted_path(home_archive)?; - if extracted.exists() { - return Ok(extracted); - } - - let tar_gz = File::open(home_archive)?; - let tar = GzDecoder::new(tar_gz); - let mut archive = Archive::new(tar); - archive.unpack(&extracted)?; - Ok(extracted) -} - -// Sets up a mock node with the extracted contents of `home_archive` serving as the equivalent -// to the `chain_history_home_dir` argument to the `start_mock_node` tool, and measures the time -// taken to sync to target_height. -fn do_bench(c: &mut Criterion, home_archive: &str, target_height: Option) { - let name = String::from("mock_node_sync_") + test_name(home_archive); - let mut group = c.benchmark_group(name.clone()); - // The default of 100 is way too big for the longer running ones, and 10 is actually the minimum allowed. - group.sample_size(10); - group.bench_function(name, |bench| { - bench.iter_with_setup(|| { - let home = extract_home(home_archive).unwrap(); - let mut near_config = nearcore::config::load_config(home.as_path(), GenesisValidationMode::Full) - .unwrap_or_else(|e| panic!("Error loading config: {:#}", e)); - near_config.validator_signer = None; - near_config.client_config.min_num_peers = 1; - let signer = InMemorySigner::from_random("mock_node".parse().unwrap(), KeyType::ED25519); - near_config.network_config.node_key = signer.secret_key; - near_config.client_config.tracked_shards = - (0..near_config.genesis.config.shard_layout.num_shards()).collect(); - (setup_actix(), near_config, home) - }, - |(sys, near_config, home)| { - let tempdir = tempfile::Builder::new().prefix("mock_node").tempdir().unwrap(); - let network_config = MockNetworkConfig::with_delay(Duration::from_millis(100)); - let servers = block_on_interruptible(&sys, async move { - let MockNode {view_client, servers, target_height, ..} = setup_mock_node( - tempdir.path(), - home.as_path(), - near_config, - &network_config, - 0, - None, - target_height, - false, - ); - - let started = Instant::now(); - loop { - // TODO: make it so that we can just get notified when syncing has finished instead - // of asking over and over. - if let Ok(Ok(block)) = view_client.send(GetBlock::latest().with_span_context()).await { - if block.header.height >= target_height { - break; - } - } - if started.elapsed() > Duration::from_secs(target_height * 5) { - panic!("mock_node sync bench timed out with home dir {:?}, target height {:?}", &home, target_height); - } - } - servers - }); - Sys{sys: Some(sys), servers: servers.unwrap()} - }) - }); - group.finish(); -} - -fn sync_empty_chunks(c: &mut Criterion) { - do_bench(c, "./benches/empty.tar.gz", Some(100)) -} - -fn sync_full_chunks(c: &mut Criterion) { - do_bench(c, "./benches/full.tar.gz", Some(100)) -} - -criterion_group!(benches, sync_empty_chunks, sync_full_chunks); -criterion_main!(benches); diff --git a/tools/mock-node/src/setup.rs b/tools/mock-node/src/setup.rs index e2e6d663b3e..d2d9e17979e 100644 --- a/tools/mock-node/src/setup.rs +++ b/tools/mock-node/src/setup.rs @@ -78,8 +78,6 @@ pub struct MockNode { pub client: Addr, // view client under test pub view_client: Addr, - // RPC servers started by the client - pub servers: Option>, // target height actually available to sync to in the chain history database pub target_height: BlockHeight, } @@ -307,17 +305,7 @@ pub fn setup_mock_node( }); network_adapter.bind(mock_network_actor.with_auto_span_context()); - let servers = config.rpc_config.map(|rpc_config| { - near_jsonrpc::start_http( - rpc_config, - config.genesis.config, - client.clone(), - view_client.clone(), - None, - ) - }); - - MockNode { client, view_client, servers, target_height } + MockNode { client, view_client, target_height } } #[cfg(test)]