name: Benchmark
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
deployments: write
jobs:
benchmark:
name: Performance Benchmarks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Pre-pull docker images
run: |
find tests/integration/docker-compose -name "*.yml" | xargs -P 4 -I {} docker compose -f {} pull -q
- name: Run benchmarks
shell: bash
run: |
set -o pipefail
export CARGO_TERM_COLOR=never
cargo bench --bench performance_bench --features full -- --output-format bencher | tee raw_output.txt
# Filter output to only include benchmark results, removing Docker logs and custom prints
awk '/^test / { if ($0 ~ /bench:/) { print $0; name="" } else { name=$2 } } /^bench:/ { if (name != "") { print "test " name " ... " $0; name="" } }' raw_output.txt > output.txt
- name: Generate Throughput Summary
run: |
python3 -c '
import re
import os
data = {}
try:
with open("raw_output.txt", "r") as f:
for line in f:
# Match lines like: "aws single_write: 1 iters, total time 1.48s, 673.75 msgs/sec"
m = re.search(r"^\s*(.*): .* ([\d\.]+) msgs/sec", line)
if m:
name = m.group(1).strip()
rate = float(m.group(2))
if name not in data:
data[name] = []
data[name].append(rate)
if data:
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f:
f.write("### Benchmark Throughput Results\n")
f.write("| Test Case | Average msgs/sec | Samples |\n")
f.write("|-----------|------------------|---------|\n")
for name in sorted(data.keys()):
rates = data[name]
avg = sum(rates) / len(rates)
f.write(f"| {name} | {avg:,.2f} | {len(rates)} |\n")
except Exception as e:
print(f"Error generating summary: {e}")
'
- name: Create gh-pages branch if missing
run: |
git fetch origin gh-pages || {
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git checkout --orphan gh-pages
git rm -rf .
git commit --allow-empty -m "Initialize gh-pages branch"
git push origin gh-pages
git checkout ${{ github.sha }}
}
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: Rust Benchmark
tool: 'cargo'
output-file-path: output.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
alert-threshold: '2000%'
comment-on-alert: true
fail-on-alert: false