Benchmark suite includes local socket round-trip.

This commit is contained in:
Herbert Wolverson 2023-01-18 22:01:58 +00:00
parent e3b2b71289
commit 58c692425b
6 changed files with 21 additions and 46 deletions

12
src/rust/Cargo.lock generated
View File

@ -253,15 +253,6 @@ version = "3.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
[[package]]
name = "bus_benchmark"
version = "0.1.0"
dependencies = [
"anyhow",
"lqos_bus",
"tokio",
]
[[package]]
name = "byteorder"
version = "1.4.3"
@ -449,6 +440,7 @@ dependencies = [
"clap 2.34.0",
"criterion-plot",
"csv",
"futures",
"itertools",
"lazy_static",
"num-traits",
@ -461,6 +453,7 @@ dependencies = [
"serde_derive",
"serde_json",
"tinytemplate",
"tokio",
"walkdir",
]
@ -1285,6 +1278,7 @@ dependencies = [
"anyhow",
"bincode",
"cc",
"criterion",
"lqos_config",
"serde",
"tokio",

View File

@ -21,5 +21,4 @@ members = [
"lqos_node_manager", # A lightweight web interface for management and local monitoring
"lqos_python", # Python bindings for using the Rust bus directly
"webusers", # CLI control for managing the web user list
"bus_benchmark", # Simple tool to measure the overall latency of using our local socket connection
]

View File

@ -1,9 +0,0 @@
[package]
name = "bus_benchmark"
version = "0.1.0"
edition = "2021"
[dependencies]
lqos_bus = { path = "../lqos_bus" }
tokio = { version = "1.22", features = [ "rt", "macros", "net", "io-util" ] }
anyhow = "1"

View File

@ -1,22 +0,0 @@
use std::time::Instant;
use anyhow::Result;
use lqos_bus::{bus_request, BusRequest};
#[tokio::main(flavor = "current_thread")]
pub async fn main() -> Result<()> {
const RUNS: usize = 100;
println!("Sending {RUNS} bus pings, please wait.");
let mut times = Vec::new();
for _ in 0 .. RUNS {
let now = Instant::now();
let responses = bus_request(vec![BusRequest::Ping]).await?;
let runtime = now.elapsed();
assert_eq!(responses.len(), 1);
times.push(runtime);
}
let sum_usec: u128 = times.iter().map(|t| t.as_nanos()).sum();
let avg_usec = sum_usec / RUNS as u128;
println!("Average bus time: {avg_usec} nanoseconds");
Ok(())
}

View File

@ -18,7 +18,7 @@ tokio = { version = "1.22", features = [ "rt", "macros", "net", "io-util" ] }
cc = "1.0"
[dev-dependencies]
criterion = { version = "0.3", features = [ "html_reports"] }
criterion = { version = "0.3", features = [ "html_reports", "async_tokio"] }
[[bench]]
name = "socket"

View File

@ -1,7 +1,7 @@
//! Benchmarks for JSON serialization and gathering data from TC.
//! Please select an interface in `test_interface.txt` (no enter character
//! at the end). This benchmark will destructively clear and then create
//! TC queues - so don't select an interface that you need!
//! Becnhmarks for the bus system, mostly focused on serialization
//! but also including sockets.
//!
//! You MUST have lqosd running when you perform these tests.
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use lqos_bus::*;
@ -52,6 +52,19 @@ pub fn criterion_benchmark(c: &mut Criterion) {
black_box(result);
});
});
// Enable the Tokio runtime to test round-trip
let tokio_rt = tokio::runtime::Builder::new_current_thread()
.enable_io()
.build()
.unwrap();
c.bench_function("bus_ping_round_trip", |b| {
b.iter(|| {
let result = tokio_rt.block_on(bus_request(vec![BusRequest::Ping])).unwrap();
black_box(result);
});
});
}
criterion_group!(benches, criterion_benchmark);