Skip to content

Commit 64bbd34

Browse files
authored
Add single destination per block option to benchmark client (#4331)
## Motivation Right now the default is for every chain to always send transfers to every other chain, in a way that in each block we cycle through the chains. ## Proposal Add an option so that we continue sending chains to every other chain, but every block contains transactions to just one of the other chains, and we cycle through chains per block instead of per transfer. ## Test Plan Deploy a network and test this mode against it. ## Release Plan - Nothing to do / These changes follow the usual release cycle.
1 parent 5124634 commit 64bbd34

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

CLI.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ Start a single benchmark process, maintaining a given TPS
568568
* `--runtime-in-seconds <RUNTIME_IN_SECONDS>` — How long to run the benchmark for. If not provided, the benchmark will run until it is interrupted
569569
* `--delay-between-chains-ms <DELAY_BETWEEN_CHAINS_MS>` — The delay between chains, in milliseconds. For example, if set to 200ms, the first chain will start, then the second will start 200 ms after the first one, the third 200 ms after the second one, and so on. This is used for slowly ramping up the TPS, so we don't pound the validators with the full TPS all at once
570570
* `--config-path <CONFIG_PATH>` — Path to YAML file containing chain IDs to send transfers to. If not provided, only transfers between chains in the same wallet
571+
* `--single-destination-per-block` — Transaction distribution mode. If false (default), distributes transactions evenly across chains within each block. If true, sends all transactions in each block to a single chain, rotating through chains for subsequent blocks
571572

572573

573574

@@ -601,6 +602,7 @@ Run multiple benchmark processes in parallel
601602
* `--runtime-in-seconds <RUNTIME_IN_SECONDS>` — How long to run the benchmark for. If not provided, the benchmark will run until it is interrupted
602603
* `--delay-between-chains-ms <DELAY_BETWEEN_CHAINS_MS>` — The delay between chains, in milliseconds. For example, if set to 200ms, the first chain will start, then the second will start 200 ms after the first one, the third 200 ms after the second one, and so on. This is used for slowly ramping up the TPS, so we don't pound the validators with the full TPS all at once
603604
* `--config-path <CONFIG_PATH>` — Path to YAML file containing chain IDs to send transfers to. If not provided, only transfers between chains in the same wallet
605+
* `--single-destination-per-block` — Transaction distribution mode. If false (default), distributes transactions evenly across chains within each block. If true, sends all transactions in each block to a single chain, rotating through chains for subsequent blocks
604606
* `--processes <PROCESSES>` — The number of benchmark processes to run in parallel
605607

606608
Default value: `1`

linera-client/src/benchmark.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl<Env: Environment> Benchmark<Env> {
121121
delay_between_chains_ms: Option<u64>,
122122
chain_listener: ChainListener<C>,
123123
shutdown_notifier: &CancellationToken,
124+
single_destination_per_block: bool,
124125
) -> Result<(), BenchmarkError> {
125126
let num_chains = chain_clients.len();
126127
let bps_counts = (0..num_chains)
@@ -183,6 +184,7 @@ impl<Env: Environment> Benchmark<Env> {
183184
notifier_clone,
184185
runtime_control_sender_clone,
185186
delay_between_chains_ms,
187+
single_destination_per_block,
186188
))
187189
.await?;
188190

@@ -566,6 +568,7 @@ impl<Env: Environment> Benchmark<Env> {
566568
notifier: Arc<Notify>,
567569
runtime_control_sender: Option<mpsc::Sender<()>>,
568570
delay_between_chains_ms: Option<u64>,
571+
single_destination_per_block: bool,
569572
) -> Result<(), BenchmarkError> {
570573
barrier.wait().await;
571574
if let Some(delay_between_chains_ms) = delay_between_chains_ms {
@@ -600,6 +603,7 @@ impl<Env: Environment> Benchmark<Env> {
600603
transactions_per_block,
601604
fungible_application_id,
602605
&mut destination_manager,
606+
single_destination_per_block,
603607
),
604608
vec![]
605609
) => {
@@ -643,21 +647,37 @@ impl<Env: Environment> Benchmark<Env> {
643647
transactions_per_block: usize,
644648
fungible_application_id: Option<ApplicationId>,
645649
destination_manager: &mut ChainDestinationManager,
650+
single_destination_per_block: bool,
646651
) -> Vec<Operation> {
647-
let mut operations = Vec::with_capacity(transactions_per_block);
648652
let amount = Amount::from_attos(1);
649653

650-
for _ in 0..transactions_per_block {
654+
if single_destination_per_block {
651655
let recipient_chain_id = destination_manager.get_next_destination();
652-
operations.push(Self::create_operation(
653-
fungible_application_id,
654-
recipient_chain_id,
655-
owner,
656-
amount,
657-
));
658-
}
659656

660-
operations
657+
(0..transactions_per_block)
658+
.map(|_| {
659+
Self::create_operation(
660+
fungible_application_id,
661+
recipient_chain_id,
662+
owner,
663+
amount,
664+
)
665+
})
666+
.collect()
667+
} else {
668+
let mut operations = Vec::with_capacity(transactions_per_block);
669+
for _ in 0..transactions_per_block {
670+
let recipient_chain_id = destination_manager.get_next_destination();
671+
672+
operations.push(Self::create_operation(
673+
fungible_application_id,
674+
recipient_chain_id,
675+
owner,
676+
amount,
677+
));
678+
}
679+
operations
680+
}
661681
}
662682

663683
/// Closes the chain that was created for the benchmark.

linera-service/src/cli/command.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ pub struct BenchmarkOptions {
9191
/// If not provided, only transfers between chains in the same wallet.
9292
#[arg(long)]
9393
pub config_path: Option<PathBuf>,
94+
95+
/// Transaction distribution mode. If false (default), distributes transactions evenly
96+
/// across chains within each block. If true, sends all transactions in each block
97+
/// to a single chain, rotating through chains for subsequent blocks.
98+
#[arg(long)]
99+
pub single_destination_per_block: bool,
94100
}
95101

96102
impl Default for BenchmarkOptions {
@@ -108,6 +114,7 @@ impl Default for BenchmarkOptions {
108114
runtime_in_seconds: None,
109115
delay_between_chains_ms: None,
110116
config_path: None,
117+
single_destination_per_block: false,
111118
}
112119
}
113120
}

linera-service/src/cli/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ impl Runnable for Job {
811811
runtime_in_seconds,
812812
delay_between_chains_ms,
813813
config_path,
814+
single_destination_per_block,
814815
} = benchmark_options;
815816
assert!(
816817
options.context_options.max_pending_message_bundles
@@ -892,6 +893,7 @@ impl Runnable for Job {
892893
delay_between_chains_ms,
893894
chain_listener,
894895
&shutdown_notifier,
896+
single_destination_per_block,
895897
)
896898
.await?;
897899

0 commit comments

Comments
 (0)