Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add codspeed for benchmark #4993

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/test_benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

name: Benchmark Test

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "core/src/**"
- "core/benches/**"
- "!core/src/docs/**"
- ".github/workflows/test_benchmark.yml"
# `workflow_dispatch` is needed by codspeed for first time trigger
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: ./.github/actions/setup
- name: Setup codspeed
run: cargo install cargo-codspeed
- name: Setup Memory env
uses: ./.github/services/memory/memory
- name: Build the benchmark targets
run: cargo codspeed build --features tests
- name: Run the benchmarks
uses: CodSpeedHQ/action@v3
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please load from 1password.

Copy link
Member Author

@dqhl76 dqhl76 Aug 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will use 1password after I get the token. Thanks for the review.

Copy link

@adriencaccia adriencaccia Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Xuanwo I have a new idea for not directly modifying files under core:

Only modify the github action, and not directly modifying the source code. That way, the code would only be modified during the actual action run.

Suggested change
- name: Build the benchmark targets
run: cargo codspeed build --features tests
- name: Run the benchmarks
uses: CodSpeedHQ/action@v3
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
- name: Install codpseed-criterion-compat
run: cargo add --dev --rename criterion --features async,async_tokio [email protected]
- name: Build the benchmark targets
run: cargo codspeed build --features tests
- name: Run the benchmarks
uses: CodSpeedHQ/action@v3
with:
run: cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}

Would that meet your requirements?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, that looks good to me!

35 changes: 35 additions & 0 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ probe = { version = "0.5.1", optional = true }
getrandom = { version = "0.2", features = ["js"] }

[dev-dependencies]
codspeed-criterion-compat = { version = "2.6.0", features = ["async", "async_tokio"] }
dqhl76 marked this conversation as resolved.
Show resolved Hide resolved
criterion = { version = "0.5", features = ["async", "async_tokio"] }
dqhl76 marked this conversation as resolved.
Show resolved Hide resolved
dotenvy = "0.15"
fastrace = { version = "0.6", features = ["enable"] }
Expand Down
4 changes: 2 additions & 2 deletions core/benches/ops/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mod read;
mod utils;
mod write;

use criterion::criterion_group;
use criterion::criterion_main;
use codspeed_criterion_compat::criterion_group;
use codspeed_criterion_compat::criterion_main;

criterion_group!(benches, read::bench, write::bench);
criterion_main!(benches);
7 changes: 4 additions & 3 deletions core/benches/ops/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// specific language governing permissions and limitations
// under the License.

use criterion::Criterion;
use codspeed_criterion_compat::Criterion;
use codspeed_criterion_compat::Throughput;
use futures::io;
use opendal::raw::tests::init_test_service;
use opendal::raw::tests::TEST_RUNTIME;
Expand Down Expand Up @@ -47,7 +48,7 @@ fn bench_read_full(c: &mut Criterion, name: &str, op: Operator) {
let path = uuid::Uuid::new_v4().to_string();
let temp_data = TempData::generate(op.clone(), &path, content.clone());

group.throughput(criterion::Throughput::Bytes(size.bytes() as u64));
group.throughput(Throughput::Bytes(size.bytes() as u64));
group.bench_with_input(size.to_string(), &(op.clone(), &path), |b, (op, path)| {
b.to_async(&*TEST_RUNTIME).iter(|| async {
let r = op.reader_with(path).await.unwrap();
Expand Down Expand Up @@ -84,7 +85,7 @@ fn bench_read_parallel(c: &mut Criterion, name: &str, op: Operator) {
let temp_data = TempData::generate(op.clone(), &path, content.clone());

for parallel in [1, 2, 4, 8, 16] {
group.throughput(criterion::Throughput::Bytes(parallel * size.bytes() as u64));
group.throughput(Throughput::Bytes(parallel * size.bytes() as u64));
group.bench_with_input(
format!("{}x{}", parallel, size.to_string()),
&(op.clone(), &path, buf_size),
Expand Down
2 changes: 1 addition & 1 deletion core/benches/ops/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use criterion::Criterion;
use codspeed_criterion_compat::Criterion;
use opendal::raw::tests::init_test_service;
use opendal::raw::tests::TEST_RUNTIME;
use opendal::Operator;
Expand Down
6 changes: 4 additions & 2 deletions core/benches/types/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
// under the License.

use bytes::Buf;
use criterion::Criterion;
use codspeed_criterion_compat::measurement::WallTime;
use codspeed_criterion_compat::BenchmarkGroup;
use codspeed_criterion_compat::Criterion;
use opendal::Buffer;
use rand::thread_rng;
use size::Size;
Expand Down Expand Up @@ -83,7 +85,7 @@ pub fn bench_non_contiguous_buffer(c: &mut Criterion) {
}

pub fn bench_non_contiguous_buffer_with_extreme(c: &mut Criterion) {
let mut group: criterion::BenchmarkGroup<criterion::measurement::WallTime> =
let mut group: BenchmarkGroup<WallTime> =
c.benchmark_group("bench_non_contiguous_buffer_with_extreme");

let mut rng = thread_rng();
Expand Down
4 changes: 2 additions & 2 deletions core/benches/types/concurrent_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

use std::time::Duration;

use criterion::BatchSize;
use criterion::Criterion;
use codspeed_criterion_compat::BatchSize;
use codspeed_criterion_compat::Criterion;
use once_cell::sync::Lazy;
use opendal::raw::ConcurrentTasks;
use opendal::Executor;
Expand Down
4 changes: 2 additions & 2 deletions core/benches/types/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ mod buffer;
mod concurrent_tasks;
mod utils;

use criterion::criterion_group;
use criterion::criterion_main;
use codspeed_criterion_compat::criterion_group;
use codspeed_criterion_compat::criterion_main;

criterion_group!(
benches,
Expand Down
Loading