-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use the simulator as a benchmark (#1616)
* Moving simulator to the test fixture * Split the simulator into two pieces in preparation for bench * Remove println statements * Fix server fmt * chore: add a file that I missed * Add a fixed seed for the test And increase the time available for benching. --------- Signed-off-by: Lars Eggert <[email protected]> Co-authored-by: Lars Eggert <[email protected]>
- Loading branch information
1 parent
cb2d623
commit 9260ba3
Showing
12 changed files
with
309 additions
and
104 deletions.
There are no files selected for viewing
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,64 @@ | ||
use std::time::Duration; | ||
|
||
use criterion::{criterion_group, criterion_main, BatchSize::SmallInput, Criterion}; | ||
use test_fixture::{ | ||
boxed, | ||
sim::{ | ||
connection::{ConnectionNode, ReceiveData, SendData}, | ||
network::{Delay, TailDrop}, | ||
Simulator, | ||
}, | ||
}; | ||
|
||
const ZERO: Duration = Duration::from_millis(0); | ||
const JITTER: Duration = Duration::from_millis(10); | ||
const TRANSFER_AMOUNT: usize = 1 << 22; // 4Mbyte | ||
|
||
fn benchmark_transfer(c: &mut Criterion, label: &str, seed: Option<impl AsRef<str>>) { | ||
c.bench_function(label, |b| { | ||
b.iter_batched( | ||
|| { | ||
let nodes = boxed![ | ||
ConnectionNode::default_client(boxed![SendData::new(TRANSFER_AMOUNT)]), | ||
TailDrop::dsl_uplink(), | ||
Delay::new(ZERO..JITTER), | ||
ConnectionNode::default_server(boxed![ReceiveData::new(TRANSFER_AMOUNT)]), | ||
TailDrop::dsl_downlink(), | ||
Delay::new(ZERO..JITTER), | ||
]; | ||
let mut sim = Simulator::new(label, nodes); | ||
if let Some(seed) = &seed { | ||
sim.seed_str(seed); | ||
} | ||
sim.setup() | ||
}, | ||
|sim| { | ||
sim.run(); | ||
}, | ||
SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
fn benchmark_transfer_variable(c: &mut Criterion) { | ||
benchmark_transfer( | ||
c, | ||
"Run multiple transfers with varying seeds", | ||
std::env::var("SIMULATION_SEED").ok(), | ||
); | ||
} | ||
|
||
fn benchmark_transfer_fixed(c: &mut Criterion) { | ||
benchmark_transfer( | ||
c, | ||
"Run multiple transfers with the same seed", | ||
Some("62df6933ba1f543cece01db8f27fb2025529b27f93df39e19f006e1db3b8c843"), | ||
); | ||
} | ||
|
||
criterion_group! { | ||
name = transfer; | ||
config = Criterion::default().warm_up_time(Duration::from_secs(5)).measurement_time(Duration::from_secs(15)); | ||
targets = benchmark_transfer_variable, benchmark_transfer_fixed | ||
} | ||
criterion_main!(transfer); |
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
Oops, something went wrong.