Skip to content

Commit

Permalink
add loopback microbenchmark (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai authored Jan 8, 2024
1 parent 0a34dea commit df6e283
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions shotover/benches/benches/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use shotover::transforms::cassandra::peers_rewrite::CassandraPeersRewrite;
use shotover::transforms::chain::{TransformChain, TransformChainBuilder};
use shotover::transforms::debug::returner::{DebugReturner, Response};
use shotover::transforms::filter::{Filter, QueryTypeFilter};
use shotover::transforms::loopback::Loopback;
use shotover::transforms::null::NullSink;
#[cfg(feature = "alpha-transforms")]
use shotover::transforms::protect::{KeyManagerConfig, ProtectConfig};
Expand All @@ -24,6 +25,28 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("transform");
group.noise_threshold(0.2);

// loopback is the fastest possible transform as it does not even have to drop the received requests
{
let chain =
TransformChainBuilder::new(vec![Box::<Loopback>::default()], "bench".to_string());
let wrapper = Wrapper::new_with_chain_name(
vec![Message::from_frame(Frame::Redis(RedisFrame::Null))],
chain.name.clone(),
"127.0.0.1:6379".parse().unwrap(),
);

group.bench_function("loopback", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(),
wrapper: wrapper.clone(),
},
BenchInput::bench,
BatchSize::SmallInput,
)
});
}

{
let chain =
TransformChainBuilder::new(vec![Box::<NullSink>::default()], "bench".to_string());
Expand All @@ -33,7 +56,7 @@ fn criterion_benchmark(c: &mut Criterion) {
"127.0.0.1:6379".parse().unwrap(),
);

group.bench_function("NullSink", |b| {
group.bench_function("nullsink", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(),
Expand Down Expand Up @@ -361,8 +384,12 @@ struct BenchInput<'a> {
}

impl<'a> BenchInput<'a> {
async fn bench(mut self) {
self.chain.process_request(self.wrapper).await.unwrap();
async fn bench(mut self) -> (Vec<Message>, TransformChain) {
// Return both the chain itself and the response to avoid measuring the time to drop the values in the benchmark
(
self.chain.process_request(self.wrapper).await.unwrap(),
self.chain,
)
}
}

Expand Down

0 comments on commit df6e283

Please sign in to comment.