forked from kaspanet/rusty-kaspa
-
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.
Benchmark for measuring various performance aspects under high mempoo…
…l pressure (kaspanet#275) * simnet params: skip pow by default + use testnet11 bps * initial bbt bmk code with simulated mining * split mining to 2 async tasks (receiver and miner) * extract is_connected_to_peers and reuse * tweak template nonce * ignore test * fix clippy warning on devnet-prealloc feature code * use devnet-prealloc feature for mempool bmk * refactor generate prealloc utxos to a method * initial tx dag generator * rename files/mods * use kaspa tempdir for test daemon * some logs and exit logic * stopwatch; use 3 clients to support concurrency; comments * todos * more timing * rename to `has_sufficient_peer_connectivity` * add `daemon_integration_tests` * rename clients * add daemon mining test from kaspanet#249 * rpc client: assert notify arg is none on multi-listeners mode
- Loading branch information
1 parent
ef234c8
commit 7cd9e15
Showing
16 changed files
with
505 additions
and
146 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
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 |
---|---|---|
@@ -1,7 +1,34 @@ | ||
use std::time::{SystemTime, UNIX_EPOCH}; | ||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; | ||
|
||
/// Returns the number of milliseconds since UNIX EPOCH | ||
#[inline] | ||
pub fn unix_now() -> u64 { | ||
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64 | ||
} | ||
|
||
/// Stopwatch which reports on drop if the timed operation passed the threshold `TR` in milliseconds | ||
pub struct Stopwatch<const TR: u64 = 1000> { | ||
name: &'static str, | ||
start: Instant, | ||
} | ||
|
||
impl Stopwatch { | ||
pub fn new(name: &'static str) -> Self { | ||
Self { name, start: Instant::now() } | ||
} | ||
} | ||
|
||
impl<const TR: u64> Stopwatch<TR> { | ||
pub fn with_threshold(name: &'static str) -> Self { | ||
Self { name, start: Instant::now() } | ||
} | ||
} | ||
|
||
impl<const TR: u64> Drop for Stopwatch<TR> { | ||
fn drop(&mut self) { | ||
let elapsed = self.start.elapsed(); | ||
if elapsed > Duration::from_millis(TR) { | ||
kaspa_core::warn!("\n[{}] Abnormal time: {:#?}", self.name, elapsed); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use kaspa_consensus_core::network::NetworkId; | ||
use kaspa_core::{core::Core, signals::Shutdown}; | ||
use kaspa_database::utils::get_kaspa_tempdir; | ||
use kaspa_grpc_client::GrpcClient; | ||
use kaspa_rpc_core::notify::mode::NotificationMode; | ||
use kaspad::{args::Args, daemon::create_core_with_runtime}; | ||
use std::{sync::Arc, time::Duration}; | ||
use tempfile::TempDir; | ||
|
||
pub struct Daemon { | ||
// Type and suffix of the daemon network | ||
pub network: NetworkId, | ||
|
||
// Daemon ports | ||
pub rpc_port: u16, | ||
pub p2p_port: u16, | ||
|
||
core: Arc<Core>, | ||
workers: Option<Vec<std::thread::JoinHandle<()>>>, | ||
|
||
_appdir_tempdir: TempDir, | ||
} | ||
|
||
impl Daemon { | ||
pub fn new_random() -> Daemon { | ||
let args = Args { devnet: true, ..Default::default() }; | ||
Self::new_random_with_args(args) | ||
} | ||
|
||
pub fn new_random_with_args(mut args: Args) -> Daemon { | ||
// This should ask the OS to allocate free port for socket 1 to 4. | ||
let socket1 = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); | ||
let rpc_port = socket1.local_addr().unwrap().port(); | ||
|
||
let socket2 = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); | ||
let p2p_port = socket2.local_addr().unwrap().port(); | ||
|
||
let socket3 = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); | ||
let rpc_json_port = socket3.local_addr().unwrap().port(); | ||
|
||
let socket4 = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); | ||
let rpc_borsh_port = socket4.local_addr().unwrap().port(); | ||
|
||
drop(socket1); | ||
drop(socket2); | ||
drop(socket3); | ||
drop(socket4); | ||
|
||
args.rpclisten = Some(format!("0.0.0.0:{rpc_port}").try_into().unwrap()); | ||
args.listen = Some(format!("0.0.0.0:{p2p_port}").try_into().unwrap()); | ||
args.rpclisten_json = Some(format!("0.0.0.0:{rpc_json_port}").parse().unwrap()); | ||
args.rpclisten_borsh = Some(format!("0.0.0.0:{rpc_borsh_port}").parse().unwrap()); | ||
let appdir_tempdir = get_kaspa_tempdir(); | ||
args.appdir = Some(appdir_tempdir.path().to_str().unwrap().to_owned()); | ||
|
||
let network = args.network(); | ||
let core = create_core_with_runtime(&Default::default(), &args); | ||
Daemon { network, rpc_port, p2p_port, core, workers: None, _appdir_tempdir: appdir_tempdir } | ||
} | ||
|
||
pub async fn start(&mut self) -> GrpcClient { | ||
self.workers = Some(self.core.start()); | ||
// Wait for the node to initialize before connecting to RPC | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
self.new_client().await | ||
} | ||
|
||
pub fn shutdown(&mut self) { | ||
if let Some(workers) = self.workers.take() { | ||
self.core.shutdown(); | ||
self.core.join(workers); | ||
} | ||
} | ||
|
||
pub async fn new_client(&self) -> GrpcClient { | ||
GrpcClient::connect(NotificationMode::Direct, format!("grpc://localhost:{}", self.rpc_port), true, None, false, Some(500_000)) | ||
.await | ||
.unwrap() | ||
} | ||
} | ||
|
||
impl Drop for Daemon { | ||
fn drop(&mut self) { | ||
self.shutdown() | ||
} | ||
} |
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.