Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ pub struct Opts {
/// Time difference between benchmarking runs
#[clap(env, short, long, value_parser = humantime::parse_duration, default_value = "15m")]
pub period: std::time::Duration,
/// Time delay between each intervalgroup of transactions
#[clap(env, short, long, value_parser = humantime::parse_duration, default_value = "5s")]
pub group_delay: std::time::Duration,
/// Override intervals for specific transaction types (JSON format: {"MpcSignEcdsa": "5m", "Swap": "10m"})
#[clap(env, long, value_parser = parse_interval_overwrite)]
pub interval_overwrite: Option<HashMap<TransactionKind, std::time::Duration>>,
Expand Down
17 changes: 6 additions & 11 deletions src/transaction/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use near_jsonrpc_primitives::types::query::QueryResponseKind;
use near_primitives::hash::CryptoHash;
use near_primitives::types::{BlockReference, Nonce};
use std::{collections::HashMap, sync::Arc};
use tokio::sync::Mutex;

use tracing::{error, info, warn};

Expand Down Expand Up @@ -120,8 +121,6 @@ impl Engine {
// Clone necessary data before borrowing
let transactions = self.transactions.clone();
let default_interval = opts.period;
let group_delay = opts.group_delay;
info!("group delay: {:?}", group_delay);

// Group transactions by their intervals
let mut interval_groups: HashMap<std::time::Duration, Vec<TransactionKind>> =
Expand All @@ -148,21 +147,16 @@ impl Engine {
.or_default()
.extend(default_transactions);
}
let run_account_transactions_once_mutex = Arc::new(Mutex::new(()));

// Spawn a task for each interval group
for (task_id, (interval_duration, transaction_kinds)) in
interval_groups.into_iter().enumerate()
{
for (interval_duration, transaction_kinds) in interval_groups.into_iter() {
let opts_clone = opts.clone();
let metrics_clone = metrics.clone();
let transactions_clone = transactions.clone();

let mutex_clone = Arc::clone(&run_account_transactions_once_mutex);
tasks.spawn(async move {
// Add 3 second delay between each interval group start
if task_id > 0 {
tokio::time::sleep(group_delay).await;
}

let mut interval = interval(interval_duration);
loop {
interval.tick().await;
Expand All @@ -181,6 +175,8 @@ impl Engine {
.map(|(kind, tx)| (kind.clone(), tx.clone()))
.collect();

let _lock = mutex_clone.lock().await;

run_account_transactions_once(
filtered_transactions,
opts_clone.clone(),
Expand Down Expand Up @@ -446,7 +442,6 @@ mod tests {
pool_id: 0,
transaction_kind: vec![],
period: Duration::from_millis(1),
group_delay: Duration::from_secs(3),
interval_overwrite: None,
metric_server_address: SocketAddr::from_str("0.0.0.0:9000").unwrap(),
location: LOCATION.to_string(),
Expand Down