-
Notifications
You must be signed in to change notification settings - Fork 465
343 lines (291 loc) · 10.4 KB
/
benchmarks.yml
File metadata and controls
343 lines (291 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
name: Benchmarks
on:
pull_request:
paths:
- 'crates/ruvector-postgres/**'
- '.github/workflows/benchmarks.yml'
push:
branches:
- main
- develop
workflow_dispatch:
inputs:
run_sql_benchmarks:
description: 'Run SQL benchmarks'
required: false
default: 'false'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
permissions:
contents: read
pull-requests: write
issues: write
jobs:
rust-benchmarks:
name: Rust Benchmarks
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-benchmarks-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-benchmarks-
${{ runner.os }}-cargo-build-
- name: Install PostgreSQL 17
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-17 postgresql-server-dev-17
- name: Install cargo-pgrx
run: cargo install cargo-pgrx --version 0.12.6 --locked
- name: Initialize pgrx
working-directory: crates/ruvector-postgres
run: cargo pgrx init --pg17=/usr/lib/postgresql/17/bin/pg_config
- name: Install criterion
run: cargo install cargo-criterion || true
- name: Run distance benchmarks
working-directory: crates/ruvector-postgres
run: |
cargo bench --features pg17 --bench distance_bench -- --output-format bencher | tee ../../distance_bench.txt
- name: Run index benchmarks
working-directory: crates/ruvector-postgres
run: |
cargo bench --features pg17 --bench index_bench -- --output-format bencher | tee ../../index_bench.txt
- name: Run quantization benchmarks
working-directory: crates/ruvector-postgres
run: |
cargo bench --features pg17 --bench quantization_bench -- --output-format bencher | tee ../../quantization_bench.txt
- name: Run quantized distance benchmarks
working-directory: crates/ruvector-postgres
run: |
cargo bench --features pg17 --bench quantized_distance_bench -- --output-format bencher | tee ../../quantized_distance_bench.txt
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
distance_bench.txt
index_bench.txt
quantization_bench.txt
quantized_distance_bench.txt
retention-days: 30
- name: Store benchmark result
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: benchmark-action/github-action-benchmark@v1
with:
name: Rust Benchmarks
tool: 'cargo'
output-file-path: distance_bench.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
alert-threshold: '150%'
comment-on-alert: true
fail-on-alert: true
- name: Generate benchmark summary
run: |
cat > benchmark_summary.md <<EOF
# Benchmark Results Summary
## Distance Function Benchmarks
\`\`\`
$(head -n 50 distance_bench.txt)
\`\`\`
## HNSW Index Benchmarks
\`\`\`
$(head -n 50 index_bench.txt)
\`\`\`
## Quantization Benchmarks
\`\`\`
$(head -n 50 quantization_bench.txt)
\`\`\`
See full results in the artifacts.
EOF
- name: Comment PR with results
if: github.event_name == 'pull_request'
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const summary = fs.readFileSync('benchmark_summary.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});
sql-benchmarks:
name: SQL Benchmarks
runs-on: ubuntu-latest
timeout-minutes: 60
if: github.event_name == 'workflow_dispatch' && github.event.inputs.run_sql_benchmarks == 'true'
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ruvector_bench
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install pgrx
run: |
cargo install --locked cargo-pgrx
cargo pgrx init --pg16 /usr/lib/postgresql/16/bin/pg_config
- name: Install ruvector extension
working-directory: crates/ruvector-postgres
run: |
cargo pgrx install --release --pg-config /usr/lib/postgresql/16/bin/pg_config
- name: Install pgvector for comparison
run: |
sudo apt-get update
sudo apt-get install -y postgresql-server-dev-16
git clone --branch v0.5.1 https://github.com/pgvector/pgvector.git /tmp/pgvector
cd /tmp/pgvector
make
sudo make install
- name: Setup test database
env:
PGHOST: localhost
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: postgres
PGDATABASE: ruvector_bench
run: |
psql -c 'CREATE EXTENSION IF NOT EXISTS ruvector;'
psql -c 'CREATE EXTENSION IF NOT EXISTS pgvector;'
- name: Run quick SQL benchmark
env:
PGHOST: localhost
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: postgres
PGDATABASE: ruvector_bench
working-directory: crates/ruvector-postgres
run: |
psql -f benches/sql/quick_benchmark.sql | tee ../../sql_quick_bench.txt
- name: Run full workload benchmark
env:
PGHOST: localhost
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: postgres
PGDATABASE: ruvector_bench
working-directory: crates/ruvector-postgres
run: |
psql -f benches/sql/benchmark_workload.sql | tee ../../sql_workload_bench.txt
- name: Upload SQL benchmark results
uses: actions/upload-artifact@v4
with:
name: sql-benchmark-results
path: |
sql_quick_bench.txt
sql_workload_bench.txt
retention-days: 30
benchmark-comparison:
name: Compare with Baseline
runs-on: ubuntu-latest
needs: rust-benchmarks
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download current benchmarks
uses: actions/download-artifact@v4
with:
name: benchmark-results
path: current
- name: Checkout base branch
run: |
git checkout ${{ github.base_ref }}
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install PostgreSQL 17
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-17 postgresql-server-dev-17
- name: Install cargo-pgrx
run: cargo install cargo-pgrx --version 0.12.6 --locked
- name: Initialize pgrx
working-directory: crates/ruvector-postgres
run: cargo pgrx init --pg17=/usr/lib/postgresql/17/bin/pg_config
- name: Run baseline benchmarks
working-directory: crates/ruvector-postgres
run: |
cargo bench --features pg17 --bench distance_bench -- --output-format bencher | tee ../../baseline_distance.txt
cargo bench --features pg17 --bench index_bench -- --output-format bencher | tee ../../baseline_index.txt
- name: Compare results
run: |
echo "# Benchmark Comparison" > comparison.md
echo "" >> comparison.md
echo "## Distance Benchmarks" >> comparison.md
echo "" >> comparison.md
echo "### Baseline (main)" >> comparison.md
echo "\`\`\`" >> comparison.md
head -n 20 baseline_distance.txt >> comparison.md
echo "\`\`\`" >> comparison.md
echo "" >> comparison.md
echo "### Current (PR)" >> comparison.md
echo "\`\`\`" >> comparison.md
head -n 20 current/distance_bench.txt >> comparison.md
echo "\`\`\`" >> comparison.md
- name: Comment comparison
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const comparison = fs.readFileSync('comparison.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comparison
});