Skip to content

Commit

Permalink
Benchmark CI (redis-rs#880)
Browse files Browse the repository at this point in the history
Add basic benchmark reporting to CI
  • Loading branch information
jaymell authored and nihohit committed Jul 23, 2023
1 parent e7148d4 commit 4937335
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
55 changes: 53 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- 1.60.0

steps:

- name: Cache redis
id: cache-redis
uses: actions/cache@v3
Expand Down Expand Up @@ -57,15 +58,16 @@ jobs:
run: |
echo "$HOME" >> $GITHUB_PATH
- name: Install latest nightly
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt

- uses: Swatinem/rust-cache@v1
- uses: actions/checkout@v2

- uses: actions/checkout@v3

- name: Run tests
run: make test
Expand Down Expand Up @@ -138,3 +140,52 @@ jobs:
run: cargo doc --no-deps --document-private-items
env:
RUSTDOCFLAGS: -Dwarnings

benchmark:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
env:
redis_ver: 7.0.0
rust_ver: stable
steps:

- name: Cache redis
id: cache-redis
uses: actions/cache@v3
with:
path: |
~/redis-cli
~/redis-server
key: ${{ runner.os }}-${{ env.redis_ver }}-redis

- name: Install redis
if: steps.cache-redis.outputs.cache-hit != 'true'
run: |
sudo apt-get update
wget https://github.com/redis/redis/archive/${{ env.redis_ver }}.tar.gz;
tar -xzvf ${{ env.redis_ver }}.tar.gz;
pushd redis-${{ env.redis_ver }} && BUILD_TLS=yes make && sudo mv src/redis-server src/redis-cli /usr/bin/ && popd;
echo $PATH
- name: set PATH
run: |
echo "$HOME" >> $GITHUB_PATH
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.rust_ver }}
override: true

- uses: Swatinem/rust-cache@v1

- uses: actions/checkout@v3

- name: Benchmark
run: |
cargo install critcmp
cargo bench --all-features -- --measurement-time 15 --save-baseline changes
git fetch
git checkout ${{ github.base_ref }}
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 @@ -153,6 +153,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 4937335

Please sign in to comment.