Skip to content

Commit

Permalink
Merge pull request #106 from MystenLabs/selectively-benchmark-differe…
Browse files Browse the repository at this point in the history
…nt-code-paths

Added options to benchmark orders vs certs
  • Loading branch information
oxade authored Dec 30, 2021
2 parents 1a9bdf4 + 8c53130 commit 0c802fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions fastpay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ serde_json = "1.0.57"
structopt = "0.3"
tempfile = "3.2.0"
tokio = { version = "0.2.22", features = ["full"] }
strum = "0.23.0"
strum_macros = "0.23"
num_cpus = "1.13.1"

fastpay_core = { path = "../fastpay_core" }
Expand Down
36 changes: 30 additions & 6 deletions fastpay/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use tokio::{runtime::Builder, time};
use std::env;
use std::fs;
use std::thread;
use strum_macros::EnumString;

#[derive(Debug, Clone, StructOpt)]
#[structopt(
Expand Down Expand Up @@ -51,8 +52,21 @@ struct ClientServerBenchmark {
/// Maximum size of datagrams received and sent (bytes)
#[structopt(long, default_value = transport::DEFAULT_MAX_DATAGRAM_SIZE)]
buffer_size: usize,
/// Which execution path to track. OrdersAndCerts or OrdersOnly or CertsOnly
#[structopt(long, default_value = "OrdersAndCerts")]
benchmark_type: BenchmarkType,
}
#[derive(Debug, Clone, PartialEq, EnumString)]
enum BenchmarkType {
OrdersAndCerts,
OrdersOnly,
CertsOnly,
}
impl std::fmt::Display for BenchmarkType {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

fn main() {
env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init();
let benchmark = ClientServerBenchmark::from_args();
Expand Down Expand Up @@ -88,6 +102,7 @@ fn main() {

impl ClientServerBenchmark {
fn make_structures(&self) -> (AuthorityState, Vec<Bytes>) {
info!("Starting benchmark: {}", self.benchmark_type);
info!("Preparing accounts.");
let mut keys = Vec::new();
for _ in 0..self.committee_size {
Expand Down Expand Up @@ -157,8 +172,12 @@ impl ClientServerBenchmark {
let serialized_certificate = serialize_cert(&certificate);
assert!(!serialized_certificate.is_empty());

orders.push(serialized_order.into());
orders.push(serialized_certificate.into());
if self.benchmark_type != BenchmarkType::OrdersOnly {
orders.push(serialized_order.into());
}
if self.benchmark_type != BenchmarkType::CertsOnly {
orders.push(serialized_certificate.into());
}
}

(state, orders)
Expand All @@ -177,8 +196,12 @@ impl ClientServerBenchmark {

async fn launch_client(&self, mut orders: Vec<Bytes>) {
time::delay_for(Duration::from_millis(1000)).await;

let items_number = orders.len() / 2;
let order_len_factor = if self.benchmark_type == BenchmarkType::OrdersAndCerts {
2
} else {
1
};
let items_number = orders.len() / order_len_factor;
let time_start = Instant::now();

let connections: usize = num_cpus::get();
Expand Down Expand Up @@ -229,7 +252,8 @@ impl ClientServerBenchmark {

let time_total = time_start.elapsed().as_micros();
warn!(
"Total time: {}us, items: {}, tx/sec: {}",
"Completed benchmark for {}\nTotal time: {}us, items: {}, tx/sec: {}",
self.benchmark_type,
time_total,
items_number,
1_000_000.0 * (items_number as f64) / (time_total as f64)
Expand Down

1 comment on commit 0c802fc

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bench results

�[0m�[1m�[33mwarning�[0m�[0m�[1m: unused variable: num_immutable_objects�[0m
�[0m �[0m�[0m�[1m�[38;5;12m--> �[0m�[0mfastx_programmability/adapter/src/adapter.rs:377:13�[0m
�[0m �[0m�[0m�[1m�[38;5;12m|�[0m
�[0m�[1m�[38;5;12m377�[0m�[0m �[0m�[0m�[1m�[38;5;12m| �[0m�[0m let mut num_immutable_objects = 0;�[0m
�[0m �[0m�[0m�[1m�[38;5;12m| �[0m�[0m �[0m�[0m�[1m�[33m^^^^^^^^^^^^^^^^^^^^^�[0m�[0m �[0m�[0m�[1m�[33mhelp: if this is intentional, prefix it with an underscore: _num_immutable_objects�[0m
�[0m �[0m�[0m�[1m�[38;5;12m= �[0m�[0m�[1mnote�[0m�[0m: #[warn(unused_variables)] on by default�[0m

�[0m�[0m�[1m�[33mwarning�[0m�[1m:�[0m fastx-adapter (lib) generated 1 warning
�[0m�[0m�[1m�[32m Finished�[0m release [optimized + debuginfo] target(s) in 2.13s
�[0m�[0m�[1m�[32m Running�[0m target/release/bench
[2021-12-30T22:20:27Z INFO bench] Starting benchmark: OrdersAndCerts
[2021-12-30T22:20:27Z INFO bench] Preparing accounts.
[2021-12-30T22:20:29Z INFO bench] Preparing transactions.
[2021-12-30T22:20:37Z INFO fastpay::network] Listening to Tcp traffic on 127.0.0.1:9555
[2021-12-30T22:20:38Z INFO bench] Set max_in_flight to 500
[2021-12-30T22:20:38Z INFO bench] Sending requests.
[2021-12-30T22:20:38Z INFO fastpay::network] Sending Tcp requests to 127.0.0.1:9555
[2021-12-30T22:20:39Z INFO fastpay::network] 127.0.0.1:9555 has processed 5000 packets
[2021-12-30T22:20:40Z INFO fastpay::network] In flight 500 Remaining 35000
[2021-12-30T22:20:40Z INFO fastpay::network] 127.0.0.1:9555 has processed 10000 packets
[2021-12-30T22:20:41Z INFO fastpay::network] 127.0.0.1:9555 has processed 15000 packets
[2021-12-30T22:20:42Z INFO fastpay::network] In flight 500 Remaining 30000
[2021-12-30T22:20:42Z INFO fastpay::network] 127.0.0.1:9555 has processed 20000 packets
[2021-12-30T22:20:43Z INFO fastpay::network] In flight 500 Remaining 30000
[2021-12-30T22:20:43Z INFO fastpay::network] 127.0.0.1:9555 has processed 25000 packets
[2021-12-30T22:20:44Z INFO fastpay::network] In flight 500 Remaining 25000
[2021-12-30T22:20:44Z INFO fastpay::network] 127.0.0.1:9555 has processed 30000 packets
[2021-12-30T22:20:45Z INFO fastpay::network] In flight 500 Remaining 25000
[2021-12-30T22:20:45Z INFO fastpay::network] 127.0.0.1:9555 has processed 35000 packets
[2021-12-30T22:20:46Z INFO fastpay::network] In flight 500 Remaining 20000
[2021-12-30T22:20:46Z INFO fastpay::network] 127.0.0.1:9555 has processed 40000 packets
[2021-12-30T22:20:47Z INFO fastpay::network] In flight 500 Remaining 20000
[2021-12-30T22:20:47Z INFO fastpay::network] 127.0.0.1:9555 has processed 45000 packets
[2021-12-30T22:20:48Z INFO fastpay::network] In flight 500 Remaining 15000
[2021-12-30T22:20:48Z INFO fastpay::network] 127.0.0.1:9555 has processed 50000 packets
[2021-12-30T22:20:49Z INFO fastpay::network] In flight 500 Remaining 15000
[2021-12-30T22:20:49Z INFO fastpay::network] 127.0.0.1:9555 has processed 55000 packets
[2021-12-30T22:20:50Z INFO fastpay::network] In flight 500 Remaining 10000
[2021-12-30T22:20:50Z INFO fastpay::network] 127.0.0.1:9555 has processed 60000 packets
[2021-12-30T22:20:51Z INFO fastpay::network] 127.0.0.1:9555 has processed 65000 packets
[2021-12-30T22:20:51Z INFO fastpay::network] In flight 500 Remaining 5000
[2021-12-30T22:20:51Z INFO fastpay::network] 127.0.0.1:9555 has processed 70000 packets
[2021-12-30T22:20:52Z INFO fastpay::network] In flight 500 Remaining 5000
[2021-12-30T22:20:52Z INFO fastpay::network] 127.0.0.1:9555 has processed 75000 packets
[2021-12-30T22:20:52Z INFO fastpay::network] Done sending Tcp requests to 127.0.0.1:9555
[2021-12-30T22:20:53Z INFO fastpay::network] 127.0.0.1:9555 has processed 80000 packets
[2021-12-30T22:20:53Z INFO fastpay::network] Done sending Tcp requests to 127.0.0.1:9555
[2021-12-30T22:20:53Z INFO bench] Received 80000 responses.
[2021-12-30T22:20:53Z WARN bench] Completed benchmark for OrdersAndCerts
Total time: 14627155us, items: 40000, tx/sec: 2734.6397847018097

Please sign in to comment.