Skip to content

Commit 368b957

Browse files
authored
Merge pull request #197 from cipherstash/benchmarks
feat: pgbench with postgres, pgbouncer and proxy
2 parents 1c22384 + b868479 commit 368b957

File tree

25 files changed

+824
-34
lines changed

25 files changed

+824
-34
lines changed

.github/actions/setup-rust/action.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Setup Test
2+
description: |
3+
This action sets up the environment for running tests in a Rust project.
4+
It installs Rust, sets up caching, and installs mise.
5+
6+
runs:
7+
using: composite
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Install rust
11+
shell: /bin/bash -l {0}
12+
run: rustup toolchain install stable --profile minimal --no-self-update
13+
- name: Setup Rust cache
14+
uses: Swatinem/rust-cache@v2
15+
with:
16+
cache-provider: buildjet
17+
cache-all-crates: true
18+
- uses: jdx/mise-action@v2
19+
with:
20+
version: 2025.1.0 # [default: latest] mise version to install
21+
install: true # [default: true] run `mise install`
22+
cache: true # [default: true] cache mise using GitHub's cache

.github/workflows/benchmark.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Benchmark Proxy
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
push:
7+
branches:
8+
- main
9+
workflow_dispatch:
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
permissions:
15+
# deployments permission to deploy GitHub pages website
16+
deployments: write
17+
# contents permission to update benchmark contents in gh-pages branch
18+
contents: write
19+
20+
jobs:
21+
benchmark:
22+
name: Performance regression check
23+
runs-on: buildjet-16vcpu-ubuntu-2204
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: ./.github/actions/setup-test
27+
- run: |
28+
mise run postgres:up --extra-args "--detach --wait"
29+
- name: Run benchmark
30+
working-directory: tests/benchmark
31+
env:
32+
CS_WORKSPACE_ID: ${{ secrets.CS_WORKSPACE_ID }}
33+
CS_CLIENT_ACCESS_KEY: ${{ secrets.CS_CLIENT_ACCESS_KEY }}
34+
CS_DEFAULT_KEYSET_ID: ${{ secrets.CS_DEFAULT_KEYSET_ID }}
35+
CS_CLIENT_ID: ${{ secrets.CS_CLIENT_ID }}
36+
CS_CLIENT_KEY: ${{ secrets.CS_CLIENT_KEY }}
37+
RUST_BACKTRACE: "1"
38+
run: mise run benchmark:continuous
39+
# Download previous benchmark result from cache (if exists)
40+
- name: Download previous benchmark data
41+
uses: actions/cache@v4
42+
with:
43+
path: ./cache
44+
key: ${{ runner.os }}-benchmark
45+
# Run `github-action-benchmark` action
46+
- name: Store benchmark result
47+
uses: benchmark-action/github-action-benchmark@v1
48+
with:
49+
# What benchmark tool the output.txt came from
50+
tool: 'customSmallerIsBetter'
51+
# Where the output from the benchmark tool is stored
52+
output-file-path: tests/benchmark/results/output.json
53+
54+
github-token: ${{ secrets.GITHUB_TOKEN }}
55+
fail-on-alert: true
56+
comment-on-alert: true
57+
summary-always: true
58+
auto-push: true
59+
benchmark-data-dir-path: docs

.github/workflows/test.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: test
1+
name: Test
22
on:
33
pull_request:
44
branches:
@@ -10,25 +10,14 @@ on:
1010

1111
env:
1212
CARGO_TERM_COLOR: always
13+
1314
jobs:
1415
test:
1516
name: Test
1617
runs-on: buildjet-16vcpu-ubuntu-2204
1718
steps:
1819
- uses: actions/checkout@v4
19-
- name: Install rust
20-
shell: /bin/bash -l {0}
21-
run: rustup toolchain install stable --profile minimal --no-self-update
22-
- name: Setup Rust cache
23-
uses: Swatinem/rust-cache@v2
24-
with:
25-
cache-provider: buildjet
26-
cache-all-crates: true
27-
- uses: jdx/mise-action@v2
28-
with:
29-
version: 2025.1.0 # [default: latest] mise version to install
30-
install: true # [default: true] run `mise install`
31-
cache: true # [default: true] cache mise using GitHub's cache
20+
- uses: ./.github/actions/setup-test
3221
- run: |
3322
mise run postgres:up --extra-args "--detach --wait"
3423
- env:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ rust-toolchain.toml
1818

1919
# credentials for local dev
2020
.env.proxy.docker
21+
22+
## benchmark result data
23+
tests/benchmark/results/*.csv
24+
tests/benchmark/benchmark-*.png

Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,29 @@ edition = "2021"
1010
incremental = true
1111
debug = true
1212

13+
# [profile.dev.package]# aws-lc-sys.opt-level = 3
14+
# proc-macro2.opt-level = 3
15+
# quote.opt-level = 3
16+
# serde_derive.opt-level = 3
17+
# sqlparser.opt-level = 3
18+
# syn.opt-level = 3
19+
1320
[profile.dev.build-override]
1421
opt-level = 3
1522

1623
[profile.test]
1724
incremental = true
1825
debug = true
1926

27+
# Default release profile (https://doc.rust-lang.org/cargo/reference/profiles.html)
2028
[profile.release]
2129
codegen-units = 1
2230
strip = "symbols"
23-
lto = true
31+
32+
[profile.profiling]
33+
inherits = "release"
34+
strip = "none"
35+
debug = true
2436

2537
[workspace.dependencies]
2638
sqlparser = { version = "^0.52", features = ["bigdecimal", "serde"] }

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,41 @@ If the proxy is running on a host other than localhost, access on that host.
786786
| `-h`, `--help` | Displays this help message | - |
787787

788788

789+
## Benchmarks
790+
791+
Benchmarking is integrated into CI, and can be run locally.
792+
793+
The benchmark uses `pgbench` to compare direct access to PostgreSQL against `pgbouncer` and Proxy.
794+
Benchmarks are executed in Docker containers, as the focus is on providing a repeatable baseline for performance.
795+
Your mileage may vary when comparing against a "real-world" production configuration.
796+
797+
The benchmarks use the extended protocol option and cover:
798+
- the default `pgbench` transaction
799+
- insert, update & select of plaintext data
800+
- insert, update & select of encrypted data (CipherStash Proxy only)
801+
802+
The benchmark setup includes the database configuration, but does requires access to a CipherStash account environment.
803+
804+
### Require environment variables
805+
```
806+
CS_WORKSPACE_ID
807+
CS_CLIENT_ACCESS_KEY
808+
CS_DEFAULT_KEYSET_ID
809+
CS_CLIENT_ID
810+
CS_CLIENT_KEY
811+
```
812+
813+
814+
### Running the benchmark
815+
816+
```bash
817+
cd tests/benchmark
818+
mise run benchmark
819+
```
820+
821+
Results are graphed in a file called `benchmark-{YmdHM}.png` where `YmdHM` is a generated timestamp.
822+
Detailed results are generated in `csv` format and in the `results` directory.
823+
789824

790825
## More info
791826

mise.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ mise run test:unit
111111
mise run test:integration
112112
"""
113113

114+
[tasks."reset"]
115+
alias = 'r'
116+
description = "Reset database"
117+
run = """
118+
mise run postgres:down
119+
mise run postgres:up --extra-args "--detach --wait"
120+
mise run postgres:setup
121+
"""
122+
114123
[tasks."test:local:unit"]
115124
alias = 'lu'
116125
description = "Runs test/s"

packages/cipherstash-proxy/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ uuid = { version = "1.11.0", features = ["serde", "v4"] }
5656
x509-parser = "0.17.0"
5757
vitaminc-protected = "0.1.0-pre2"
5858

59-
6059
[dev-dependencies]
6160
recipher = "0.1.3"
6261
temp-env = "0.3.6"

packages/cipherstash-proxy/src/postgresql/messages/terminate.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use bytes::{BufMut, BytesMut};
2-
31
use super::FrontendCode;
2+
use bytes::{BufMut, BytesMut};
43

54
pub struct Terminate;
65

0 commit comments

Comments
 (0)