Skip to content

Commit

Permalink
chain microbenchmarks: run the chains once before benching to avoid m…
Browse files Browse the repository at this point in the history
…easuring init time
  • Loading branch information
rukai committed Jun 16, 2024
1 parent caa3453 commit c119a68
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions shotover/benches/benches/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function("loopback", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(TransformContextBuilder::new_test()),
wrapper: wrapper.clone(),
},
|| BenchInput::new(&chain, &wrapper),
BenchInput::bench,
BatchSize::SmallInput,
)
Expand All @@ -58,10 +55,7 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function("nullsink", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(TransformContextBuilder::new_test()),
wrapper: wrapper.clone(),
},
|| BenchInput::new(&chain, &wrapper),
BenchInput::bench,
BatchSize::SmallInput,
)
Expand Down Expand Up @@ -96,10 +90,7 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function("redis_filter", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(TransformContextBuilder::new_test()),
wrapper: wrapper.clone(),
},
|| BenchInput::new(&chain, &wrapper),
BenchInput::bench,
BatchSize::SmallInput,
)
Expand All @@ -125,10 +116,7 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function("redis_cluster_ports_rewrite", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(TransformContextBuilder::new_test()),
wrapper: wrapper.clone(),
},
|| BenchInput::new(&chain, &wrapper),
BenchInput::bench,
BatchSize::SmallInput,
)
Expand Down Expand Up @@ -172,10 +160,7 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function("cassandra_request_throttling_unparsed", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(TransformContextBuilder::new_test()),
wrapper: wrapper.clone(),
},
|| BenchInput::new(&chain, &wrapper),
BenchInput::bench,
BatchSize::SmallInput,
)
Expand Down Expand Up @@ -226,10 +211,7 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function("cassandra_rewrite_peers_passthrough", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(TransformContextBuilder::new_test()),
wrapper: wrapper.clone(),
},
|| BenchInput::new(&chain, &wrapper),
BenchInput::bench,
BatchSize::SmallInput,
)
Expand Down Expand Up @@ -272,10 +254,7 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function("cassandra_protect_unprotected", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(TransformContextBuilder::new_test()),
wrapper: wrapper.clone(),
},
|| BenchInput::new(&chain, &wrapper),
BenchInput::bench,
BatchSize::SmallInput,
)
Expand All @@ -287,10 +266,7 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function("cassandra_protect_protected", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(TransformContextBuilder::new_test()),
wrapper: wrapper.clone(),
},
|| BenchInput::new(&chain, &wrapper),
BenchInput::bench,
BatchSize::SmallInput,
)
Expand Down Expand Up @@ -322,10 +298,7 @@ fn criterion_benchmark(c: &mut Criterion) {

group.bench_function("query_counter", |b| {
b.to_async(&rt).iter_batched(
|| BenchInput {
chain: chain.build(TransformContextBuilder::new_test()),
wrapper: wrapper.clone(),
},
|| BenchInput::new(&chain, &wrapper),
BenchInput::bench,
BatchSize::SmallInput,
)
Expand Down Expand Up @@ -366,6 +339,18 @@ struct BenchInput<'a> {
}

impl<'a> BenchInput<'a> {
fn new(chain: &TransformChainBuilder, wrapper: &Wrapper<'a>) -> Self {
let mut chain = chain.build(TransformContextBuilder::new_test());

// Run the chain once so we are measuring the chain once its been fully initialized
futures::executor::block_on(chain.process_request(wrapper.clone())).unwrap();

BenchInput {
chain,
wrapper: wrapper.clone(),
}
}

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
(
Expand Down

0 comments on commit c119a68

Please sign in to comment.