-
Notifications
You must be signed in to change notification settings - Fork 0
308 lines (267 loc) · 9.73 KB
/
rust-benchmark.yml
File metadata and controls
308 lines (267 loc) · 9.73 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
name: Rust Benchmark
on:
push:
branches: [main, master]
paths: ['rust/**', 'spacetime-module/**', '.github/workflows/rust-benchmark.yml']
pull_request:
branches: [main, master]
paths: ['rust/**', 'spacetime-module/**', '.github/workflows/rust-benchmark.yml']
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
defaults:
run:
working-directory: rust
jobs:
test:
name: Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Setup Rust (nightly)
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- name: Cache cargo registry
uses: Swatinem/rust-cache@v2
with:
workspaces: rust -> target
cache-on-failure: "true"
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run Clippy
run: cargo clippy --all-targets
- name: Install SpacetimeDB CLI
shell: bash
run: |
curl -sSf https://install.spacetimedb.com | sh -s -- -y
echo "$HOME/.local/bin" >> $GITHUB_PATH
working-directory: .
- name: Build SpacetimeDB module (WASM)
run: cargo build --release --target wasm32-unknown-unknown
working-directory: rust/spacetime-module
- name: Start SpacetimeDB server
shell: bash
run: |
spacetime start &
echo "Waiting for SpacetimeDB server to be ready..."
for i in $(seq 1 30); do
if curl -sf http://localhost:3000/ > /dev/null 2>&1; then
echo "SpacetimeDB server is ready"
break
fi
sleep 1
done
working-directory: .
- name: Publish SpacetimeDB module
shell: bash
run: |
spacetime publish \
--server http://localhost:3000 \
--bin-path target/wasm32-unknown-unknown/release/spacetime_module.wasm \
--yes \
benchmark-links
working-directory: rust/spacetime-module
- name: Run tests
env:
SPACETIMEDB_URI: http://localhost:3000
SPACETIMEDB_DB: benchmark-links
# Run tests sequentially to avoid parallel interference with shared SpacetimeDB state.
run: cargo test -- --test-threads=1
# Quick benchmark validation for pull requests.
# Runs benchmarks with reduced scale to verify they work and produce results
# in well under 10 minutes. Results are not committed but uploaded as artifacts.
#
# Parameters chosen to keep total benchmark time under 5 minutes:
# BENCHMARK_LINK_COUNT=10, BACKGROUND_LINK_COUNT=30: reduces SpacetimeDB
# round trips per iteration from ~8000 to ~80, making each iteration ~0.1s.
# --sample-size 10: collect 10 samples per benchmark (instead of 100 default).
# --warm-up-time 1: 1s warm-up instead of 3s default.
# --measurement-time 2: 2s measurement instead of 5s default.
# Expected runtime: ~3-5 minutes total for all 35 benchmarks.
benchmark-pr:
name: Benchmark (PR validation)
runs-on: ubuntu-latest
needs: [test]
if: github.event_name == 'pull_request'
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Setup Rust (nightly)
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
targets: wasm32-unknown-unknown
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python dependencies
run: pip install matplotlib numpy
- name: Cache cargo registry
uses: Swatinem/rust-cache@v2
with:
workspaces: rust -> target
cache-on-failure: "true"
- name: Install SpacetimeDB CLI
run: |
curl -sSf https://install.spacetimedb.com | sh -s -- -y
echo "$HOME/.local/bin" >> $GITHUB_PATH
working-directory: .
- name: Build SpacetimeDB module (WASM)
run: cargo build --release --target wasm32-unknown-unknown
working-directory: rust/spacetime-module
- name: Start SpacetimeDB server
run: |
spacetime start &
for i in $(seq 1 30); do
if curl -sf http://localhost:3000/ > /dev/null 2>&1; then
echo "SpacetimeDB server is ready"
break
fi
sleep 1
done
working-directory: .
- name: Publish SpacetimeDB module
run: |
spacetime publish \
--server http://localhost:3000 \
--bin-path target/wasm32-unknown-unknown/release/spacetime_module.wasm \
--yes \
benchmark-links
working-directory: rust/spacetime-module
- name: Build benchmark
run: cargo build --release
- name: Run benchmark (quick mode for PR validation)
env:
# Reduced scale: 10 links instead of 1000, 30 background instead of 3000.
# This reduces SpacetimeDB round trips per iteration from ~8000 to ~80,
# keeping each iteration under 0.1s and total benchmark time under 5 minutes.
BENCHMARK_LINK_COUNT: 10
BACKGROUND_LINK_COUNT: 30
SPACETIMEDB_URI: http://localhost:3000
SPACETIMEDB_DB: benchmark-links
run: |
cargo bench --bench bench -- \
--output-format bencher \
--sample-size 10 \
--warm-up-time 1 \
--measurement-time 2 \
--nresamples 1000 \
| tee out.txt
- name: Generate charts
run: python3 out.py
- name: Upload PR benchmark artifacts
uses: actions/upload-artifact@v4
with:
name: benchmark-results-pr
path: |
rust/out.txt
rust/bench_rust.png
rust/bench_rust_log_scale.png
# Full benchmark run for commits to main/master.
# Uses full scale (1000 links, 3000 background) with reduced sample count
# to produce statistically meaningful results while fitting within 1 hour.
#
# Parameters:
# BENCHMARK_LINK_COUNT=1000, BACKGROUND_LINK_COUNT=3000: realistic scale.
# --sample-size 20: 20 samples per benchmark (down from 100 default).
# --nresamples 10000: 10k bootstrap resamples (down from 100k default).
# Expected runtime: ~30-45 minutes total for all 35 benchmarks.
benchmark:
name: Benchmark (full)
runs-on: ubuntu-latest
needs: [test]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
timeout-minutes: 180
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Rust (nightly)
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
targets: wasm32-unknown-unknown
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python dependencies
run: pip install matplotlib numpy
- name: Cache cargo registry
uses: Swatinem/rust-cache@v2
with:
workspaces: rust -> target
cache-on-failure: "true"
- name: Install SpacetimeDB CLI
run: |
curl -sSf https://install.spacetimedb.com | sh -s -- -y
echo "$HOME/.local/bin" >> $GITHUB_PATH
working-directory: .
- name: Build SpacetimeDB module (WASM)
run: cargo build --release --target wasm32-unknown-unknown
working-directory: rust/spacetime-module
- name: Start SpacetimeDB server
run: |
spacetime start &
for i in $(seq 1 30); do
if curl -sf http://localhost:3000/ > /dev/null 2>&1; then
echo "SpacetimeDB server is ready"
break
fi
sleep 1
done
working-directory: .
- name: Publish SpacetimeDB module
run: |
spacetime publish \
--server http://localhost:3000 \
--bin-path target/wasm32-unknown-unknown/release/spacetime_module.wasm \
--yes \
benchmark-links
working-directory: rust/spacetime-module
- name: Build benchmark
run: cargo build --release
- name: Run benchmark (full mode for main branch)
env:
# Full scale: 1000 links, 3000 background for realistic results.
# --sample-size 20 reduces total runtime from ~2h (default 100) to ~25-40 min
# while still providing statistically valid measurements.
BENCHMARK_LINK_COUNT: 1000
BACKGROUND_LINK_COUNT: 3000
SPACETIMEDB_URI: http://localhost:3000
SPACETIMEDB_DB: benchmark-links
run: |
cargo bench --bench bench -- \
--output-format bencher \
--sample-size 20 \
--nresamples 10000 \
| tee out.txt
- name: Generate charts
run: python3 out.py
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit benchmark results
run: |
git add -f out.txt bench_rust.png bench_rust_log_scale.png 2>/dev/null || true
git diff --staged --quiet || git commit -m "chore: update benchmark results [skip ci]"
git push
- name: Upload benchmark artifacts
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
rust/out.txt
rust/bench_rust.png
rust/bench_rust_log_scale.png