Skip to content

Commit

Permalink
[bench] New benchmarks against different datastores (surrealdb#2956)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgirones authored Nov 18, 2023
1 parent 7a34452 commit b0be223
Show file tree
Hide file tree
Showing 16 changed files with 957 additions and 53 deletions.
199 changes: 181 additions & 18 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,212 @@ on:
push:
branches:
- main
pull_request:

defaults:
run:
shell: bash

#
# The bench jobs will:
# 1. Run the benchmark and save the results as a baseline named "current"
# 2. Download the following baselines from S3
# - The latest baseline from the main branch
# - The latest baseline from the current branch
# 3. Compare the current benchmark results vs the baselines
# 4. Save the comparison as an artifact
# 5. Upload the current benchmark results as a new baseline and update the latest baseline for the current branch
#

jobs:
bench:
name: Bench library
runs-on: ubuntu-latest
common:
name: Bench common
runs-on:
- self-hosted
- benches
timeout-minutes: 60
steps:
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.71.1

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1

- name: Install dependencies
run: |
sudo apt-get -qq -y update
cargo install --quiet critcmp
sudo apt-get -qq -y install clang curl
cargo install --quiet critcmp cargo-make
- name: Checkout baseline
- name: Checkout changes
uses: actions/checkout@v3

- name: Run benchmark
run: |
cargo make ci-bench -- --save-baseline current
- name: Copy results from AWS S3 bucket
run: |
BRANCH_NAME=$(echo ${{ github.head_ref || github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')
aws s3 sync s3://${{ secrets.AWS_S3_GITHUB_ACTIONS_BUCKET_NAME }}/bench-results/${{ github.job }}/main/latest bench-results-main || true
aws s3 sync s3://${{ secrets.AWS_S3_GITHUB_ACTIONS_BUCKET_NAME }}/bench-results/${{ github.job }}/$BRANCH_NAME/latest bench-results-previous || true
- name: Compare current benchmark results vs baseline
run: |
mkdir -p bench-results
critcmp current bench-results-main/${{ matrix.target }}.json bench-results-previous/${{ matrix.target }}.json | tee bench-results/${{ github.job }}-comparison.txt
# Create a summary of the comparison
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
cat bench-results/${{ github.job }}-comparison.txt >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Save results as artifact
uses: actions/upload-artifact@v1
with:
ref: ${{ github.base_ref }}
name: ${{ github.job }}-comparison.txt
path: bench-results/${{ github.job }}-comparison.txt

- name: Install cargo-make
run: cargo install --debug cargo-make
- name: Copy results to AWS S3 bucket
run: |
BRANCH_NAME=$(echo ${{ github.head_ref || github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')
- name: Benchmark baseline
run: cargo make bench-baseline
cargo make ci-bench -- --load-baseline current --save-baseline previous
critcmp --export previous > bench-results/${{ matrix.target }}.json
- name: Checkout changes
aws s3 sync bench-results s3://${{ secrets.AWS_S3_GITHUB_ACTIONS_BUCKET_NAME }}/bench-results/${{ github.job }}/$BRANCH_NAME/${{ github.run_id }}
aws s3 sync bench-results s3://${{ secrets.AWS_S3_GITHUB_ACTIONS_BUCKET_NAME }}/bench-results/${{ github.job }}/$BRANCH_NAME/latest
engines:
name: Benchmark engines
runs-on:
- self-hosted
- benches
timeout-minutes: 60
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
include:
- target: "lib-mem"
features: "kv-mem"
- target: "lib-rocksdb"
features: "kv-rocksdb"
- target: "lib-fdb"
features: "kv-fdb-7_1"
- target: "sdk-mem"
features: "kv-mem"
- target: "sdk-rocksdb"
features: "kv-rocksdb"
- target: "sdk-fdb"
features: "kv-fdb-7_1"
# This one fails because the server consumes too much memory and the kernel kills it. I tried with instances up to 16GB of RAM.
# - target: "sdk-ws"
# features: "protocol-ws"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Benchmark changes
run: cargo make bench-changes
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.71.1

- name: Setup cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1

- name: Install dependencies
run: |
sudo apt-get -qq -y update
sudo apt-get -qq -y install clang curl
cargo install --quiet critcmp cargo-make
# Install FoundationDB if needed
- name: Setup FoundationDB
uses: foundationdb-rs/[email protected]
if: ${{ matrix.target == 'lib-fdb' || matrix.target == 'sdk-fdb' }}
with:
version: "7.1.30"

# Run SurrealDB in the background if needed
- name: Build and start SurrealDB
if: ${{ matrix.target == 'sdk-ws' }}
run: |
cargo make build
# Kill any potential previous instance of the server. The runner may be reused.
pkill -9 surreal || true
./target/release/surreal start 2>&1 >surrealdb.log &
set +e
echo "Waiting for surreal to be ready..."
tries=0
while [[ $tries < 5 ]]; do
./target/release/surreal is-ready 2>/dev/null && echo "Ready!" && exit 0 || sleep 1
tries=$((tries + 1))
done
- name: Benchmark results
run: cargo make bench-compare
echo "#####"
echo "SurrealDB server failed to start!"
echo "#####"
cat surrealdb.log
exit 1
- name: Run benchmark
env:
BENCH_FEATURES: "${{ matrix.features }}"
BENCH_DURATION: 60
BENCH_WORKER_THREADS: 2
run: |
cargo make bench-${{ matrix.target }} -- --save-baseline current
# Kill surreal server if it's running
pkill -9 surreal || true
- name: Copy results from AWS S3 bucket
run: |
BRANCH_NAME=$(echo ${{ github.head_ref || github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')
aws s3 sync s3://${{ secrets.AWS_S3_GITHUB_ACTIONS_BUCKET_NAME }}/bench-results/${{ github.job }}/main/latest bench-results-main || true
aws s3 sync s3://${{ secrets.AWS_S3_GITHUB_ACTIONS_BUCKET_NAME }}/bench-results/${{ github.job }}/$BRANCH_NAME/latest bench-results-previous || true
- name: Compare current benchmark results vs baseline
run: |
mkdir -p bench-results
critcmp current bench-results-main/${{ matrix.target }}.json bench-results-previous/${{ matrix.target }}.json | tee bench-results/${{ matrix.target }}-comparison.txt
# Create a summary of the comparison
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
cat bench-results/${{ matrix.target }}-comparison.txt >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Save results as artifact
uses: actions/upload-artifact@v1
with:
name: Benchmark Results
path: benchmark_results
name: ${{ matrix.target }}-comparison.txt
path: bench-results/${{ matrix.target }}-comparison.txt

- name: Copy results to AWS S3 bucket
env:
BENCH_FEATURES: "${{ matrix.features }}"
run: |
BRANCH_NAME=$(echo ${{ github.head_ref || github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')
cargo make bench-${{ matrix.target }} -- --load-baseline current --save-baseline previous
critcmp --export previous > bench-results/${{ matrix.target }}.json
aws s3 sync bench-results s3://${{ secrets.AWS_S3_GITHUB_ACTIONS_BUCKET_NAME }}/bench-results/${{ github.job }}/$BRANCH_NAME/${{ github.run_id }}
aws s3 sync bench-results s3://${{ secrets.AWS_S3_GITHUB_ACTIONS_BUCKET_NAME }}/bench-results/${{ github.job }}/$BRANCH_NAME/latest
78 changes: 52 additions & 26 deletions Makefile.ci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,34 +207,60 @@ command = "cargo"
args = ["build", "--locked", "--no-default-features", "--features", "storage-mem"]

#
# Benchmarks
# Benchmarks - Common
#
[tasks.bench-run-baseline]
[tasks.ci-bench]
category = "CI - BENCHMARK"
command = "cargo"
args = ["bench", "--quiet", "--package", "surrealdb", "--no-default-features", "--features", "kv-mem,scripting,http", "--", "--save-baseline", "baseline"]
args = ["bench", "--quiet", "--package", "surrealdb", "--no-default-features", "--features", "kv-mem,scripting,http", "${@}"]

[tasks.bench-save-baseline]
category = "CI - BENCHMARK"
script = "cp -r target/criterion /tmp/criterion"

[tasks.bench-restore-baseline]
category = "CI - BENCHMARK"
script = "mkdir -p target && cp -r /tmp/criterion target/criterion"

[tasks.bench-baseline]
category = "CI - BENCHMARK"
run_task = { name = ["bench-run-baseline", "bench-save-baseline"] }

[tasks.bench-run-changes]
category = "CI - BENCHMARK"
#
# Benchmarks - SDB - Per Target
#
[env]
BENCH_WORKER_THREADS = { value = "1", condition = { env_not_set = ["BENCH_WORKER_THREADS"] } }
BENCH_NUM_OPS = { value = "1000", condition = { env_not_set = ["BENCH_NUM_OPS"] } }
BENCH_DURATION = { value = "30", condition = { env_not_set = ["BENCH_DURATION"] } }
BENCH_SAMPLE_SIZE = { value = "10", condition = { env_not_set = ["BENCH_SAMPLE_SIZE"] } }
BENCH_FEATURES = { value = "protocol-ws,kv-mem,kv-rocksdb,kv-fdb-7_1", condition = { env_not_set = ["BENCH_FEATURES"] } }

[tasks.bench-target]
private = true
category = "CI - BENCHMARK - SurrealDB Target"
command = "cargo"
args = ["bench", "--quiet", "--package", "surrealdb", "--no-default-features", "--features", "kv-mem,scripting,http", "--", "--save-baseline", "changes"]

[tasks.bench-changes]
category = "CI - BENCHMARK"
run_task = { name = ["bench-restore-baseline", "bench-run-changes"] }

[tasks.bench-compare]
category = "CI - BENCHMARK"
script = "critcmp baseline changes | tee benchmark_results"
args = ["bench", "--package", "surrealdb", "--bench", "sdb", "--no-default-features", "--features", "${BENCH_FEATURES}", "${@}"]

[tasks.bench-lib-mem]
category = "CI - BENCHMARK - SurrealDB Target"
env = { BENCH_DATASTORE_TARGET = "lib-mem" }
run_task = { name = ["bench-target"] }

[tasks.bench-lib-rocksdb]
category = "CI - BENCHMARK - SurrealDB Target"
env = { BENCH_DATASTORE_TARGET = "lib-rocksdb" }
run_task = { name = ["bench-target"] }

[tasks.bench-lib-fdb]
category = "CI - BENCHMARK - SurrealDB Target"
env = { BENCH_DATASTORE_TARGET = "lib-fdb" }
run_task = { name = ["bench-target"] }

[tasks.bench-sdk-mem]
category = "CI - BENCHMARK - SurrealDB Target"
env = { BENCH_DATASTORE_TARGET = "sdk-mem" }
run_task = { name = ["bench-target"] }

[tasks.bench-sdk-rocksdb]
category = "CI - BENCHMARK - SurrealDB Target"
env = { BENCH_DATASTORE_TARGET = "sdk-rocksdb" }
run_task = { name = ["bench-target"] }

[tasks.bench-sdk-fdb]
category = "CI - BENCHMARK - SurrealDB Target"
env = { BENCH_DATASTORE_TARGET = "sdk-fdb" }
run_task = { name = ["bench-target"] }

[tasks.bench-sdk-ws]
category = "CI - BENCHMARK - SurrealDB Target"
env = { BENCH_DATASTORE_TARGET = "sdk-ws" }
run_task = { name = ["bench-target"] }
2 changes: 1 addition & 1 deletion Makefile.local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ args = ["clean"]
[tasks.bench]
category = "LOCAL USAGE"
command = "cargo"
args = ["bench", "--package", "surrealdb", "--no-default-features", "--features", "kv-mem,http,scripting"]
args = ["bench", "--package", "surrealdb", "--no-default-features", "--features", "kv-mem,http,scripting", "--", "${@}"]

# Run
[tasks.run]
Expand Down
4 changes: 4 additions & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,7 @@ harness = false
[[bench]]
name = "move_vs_clone"
harness = false

[[bench]]
name = "sdb"
harness = false
Loading

0 comments on commit b0be223

Please sign in to comment.