Skip to content

Commit

Permalink
Add initial cluster-async benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymell committed Jul 14, 2023
1 parent 1789e06 commit 7116555
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ jobs:
RUSTDOCFLAGS: -Dwarnings

benchmark:
if: ${{ github.event_name == 'pull_request' }}
name: Benchmark
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -184,8 +185,8 @@ jobs:
- name: Benchmark
run: |
cargo install critcmp
cargo bench --all-features -- --save-baseline changes
cargo bench --all-features -- --measurement-time 15 --save-baseline changes
git fetch
git checkout ${{ github.base_ref }}
cargo bench --all-features -- --save-baseline base
cargo bench --all-features -- --measurement-time 15 --save-baseline base
critcmp base changes
5 changes: 5 additions & 0 deletions redis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ name = "bench_cluster"
harness = false
required-features = ["cluster"]

[[bench]]
name = "bench_cluster_async"
harness = false
required-features = ["cluster-async", "tokio-comp"]

[[example]]
name = "async-multiplexed"
required-features = ["tokio-comp"]
Expand Down
47 changes: 47 additions & 0 deletions redis/benches/bench_cluster_async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#![allow(clippy::unit_arg)] // want to allow this for `black_box()`
#![cfg(feature = "cluster")]
use criterion::{criterion_group, criterion_main, Criterion};
use redis::RedisError;

use support::*;
use tokio::runtime::Runtime;

#[path = "../tests/support/mod.rs"]
mod support;

fn bench_basic(
c: &mut Criterion,
con: &mut redis::cluster_async::ClusterConnection,
runtime: &Runtime,
) {
let mut group = c.benchmark_group("cluster_async_basic");
group.sample_size(1_000);
group.measurement_time(std::time::Duration::from_secs(30));
group.bench_function("set_get_and_del", |b| {
b.iter(|| {
runtime
.block_on(async {
let key = "test_key";
redis::cmd("SET").arg(key).arg(42).query_async(con).await?;
let _: isize = redis::cmd("GET").arg(key).query_async(con).await?;
redis::cmd("DEL").arg(key).query_async(con).await?;

Ok::<_, RedisError>(())
})
.unwrap()
})
});
group.finish();
}

fn bench_cluster_setup(c: &mut Criterion) {
let cluster = TestClusterContext::new(6, 1);
cluster.wait_for_cluster_up();
let runtime = current_thread_runtime();
let mut con = runtime.block_on(cluster.async_connection());

bench_basic(c, &mut con, &runtime);
}

criterion_group!(cluster_async_bench, bench_cluster_setup,);
criterion_main!(cluster_async_bench);

0 comments on commit 7116555

Please sign in to comment.