Skip to content

Commit b98c68c

Browse files
fix(keynote-2): split demo and bench CLI parsing (#4703)
# Description of Changes This cleans up the `keynote-2` benchmark CLI and fixes the `bench` path that was broken after `demo` and `bench` started sharing a single parser. `demo` and `bench` now parse their own command grammars instead of sharing one import-time parser. This avoids `bench` inheriting `demo`-style validation and breaking on `test-1 --connectors ...`. in addition, `bench` also uses the same `cac`-builder as `demo` now, and I've deleted the unused `runner_1.ts`. # API and ABI breaking changes None # Expected complexity level and risk 3 # Testing Manually tested the following from `templates/keynote-2`: - `pnpm bench test-1 --seconds 10 --concurrency 50 --alpha 1.5 --connectors spacetimedb` - `pnpm demo --seconds 1 --concurrency 5 --alpha 1.5 --systems spacetimedb --skip-prep --no-animation` - `deno run --sloppy-imports -A src/demo.ts --help` - `deno run --sloppy-imports -A src/cli.ts --help` - `deno run --sloppy-imports -A src/cli.ts test-1 --seconds 10 --concurrency 50 --alpha 1.5 --connectors spacetimedb`
1 parent 36c416f commit b98c68c

26 files changed

Lines changed: 785 additions & 734 deletions

templates/keynote-2/.env.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ USE_DOCKER=1 # 1 = run docker compose up for pg/crdb; 0 = skip
55
#SKIP_SQLITE=1 # 1 = don't init SQLite in prep
66
#SKIP_SUPABASE=1 # 1 = don't init Supabase in prep
77
SKIP_CONVEX=1 # 1 = don't init Convex in prep
8-
USE_SPACETIME_METRICS_ENDPOINT=0
8+
SPACETIME_METRICS_ENDPOINT=0
99

1010
# ===== PostgreSQL =====
1111
POSTGRES_USER=postgres
@@ -26,7 +26,6 @@ SQLITE_MODE=default
2626
STDB_URL=ws://127.0.0.1:3000
2727
STDB_MODULE=test-1
2828
STDB_MODULE_PATH=./spacetimedb
29-
STDB_METRICS_URL=http://127.0.0.1:3000/v1/metrics
3029
STDB_CONFIRMED_READS=1
3130

3231
# ===== Supabase =====

templates/keynote-2/DEVELOP.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ The script will:
3434
- `--skip-prep` - Skip database seeding
3535
- `--no-animation` - Disable animated output
3636

37+
`demo` always runs the built-in `test-1` scenario. Use `bench` if you need to choose a test explicitly.
38+
`demo` uses `--systems`; `bench` uses `--connectors`.
39+
3740
---
3841

3942
## Prerequisites
@@ -70,7 +73,7 @@ Copy `.env.example` to `.env` and adjust.
7073
- `SKIP_SQLITE``1` = don't init SQLite in prep
7174
- `SKIP_SUPABASE``1` = don't init Supabase in prep
7275
- `SKIP_CONVEX``1` = don't init Convex in prep
73-
- `USE_SPACETIME_METRICS_ENDPOINT``1` = read committed transfer counts from the SpacetimeDB metrics endpoint; otherwise only local counters are used
76+
- `SPACETIME_METRICS_ENDPOINT``1` = read committed transfer counts from the derived SpacetimeDB metrics endpoint; otherwise only local counters are used
7477

7578
**PostgreSQL / CockroachDB:**
7679

@@ -87,7 +90,6 @@ Copy `.env.example` to `.env` and adjust.
8790
- `STDB_URL` – WebSocket URL for SpacetimeDB
8891
- `STDB_MODULE` – module name to load (e.g. `test-1`)
8992
- `STDB_MODULE_PATH` – filesystem path to the module source (for local dev)
90-
- `STDB_METRICS_URL` – HTTP URL for the SpacetimeDB metrics endpoint
9193
- `STDB_CONFIRMED_READS``1` = force confirmed reads on, `0` = force them off
9294

9395
**Supabase:**
@@ -164,26 +166,26 @@ cd ..
164166
### 1. Run a test
165167

166168
```bash
167-
npm run bench [test-name] [--seconds N] [--concurrency N] [--alpha A] [--connectors list]
169+
npm run bench -- [test-name] [--seconds N] [--concurrency N] [--alpha A] [--connectors list]
168170
```
169171

170172
Examples:
171173

172174
```bash
173-
# Default test (test-1), default args (note: only 1 test right now, and it's embedded)
175+
# Default test (test-1), default args
174176
npm run bench
175177

176178
# Explicit test name
177-
npm run bench test-1
179+
npm run bench -- test-1
178180

179181
# Short run, 100 concurrent workers
180-
npm run bench test-1 --seconds 10 --concurrency 100
182+
npm run bench -- test-1 --seconds 10 --concurrency 100
181183

182184
# Heavier skew on hot accounts
183-
npm run bench test-1 --alpha 2.0
185+
npm run bench -- test-1 --alpha 2.0
184186

185187
# Only run selected connectors
186-
npm run bench test-1 --connectors spacetimedb,sqlite
188+
npm run bench -- test-1 --connectors spacetimedb,sqlite_rpc
187189
```
188190

189191
### 2. Run the distributed TypeScript SpacetimeDB benchmark
@@ -392,7 +394,7 @@ From `src/cli.ts`:
392394
- Example:
393395

394396
```bash
395-
--connectors spacetimedb,sqlite,postgres
397+
--connectors spacetimedb,sqlite_rpc,postgres_rpc
396398
```
397399

398400
- If omitted, all connectors for that test are run
@@ -422,7 +424,7 @@ docker compose run --rm bench \
422424
--connectors convex
423425
```
424426

425-
If using Docker, make sure to set `USE_DOCKER=1` in `.env`, verify docker-compose env variables, verify you've run supabase init, and run `npm prep` before running bench.
427+
If using Docker, make sure to set `USE_DOCKER=1` in `.env`, verify docker-compose env variables, verify you've run supabase init, and run `npm run prep` before running bench.
426428
427429
## Output
428430

templates/keynote-2/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ A benchmark suite comparing SpacetimeDB against traditional web application stac
77
See SpacetimeDB's performance advantage with one command:
88

99
```bash
10-
npm install
10+
pnpm install
1111
npm run demo
1212
```
1313

1414
The demo compares SpacetimeDB and Convex by default, since both are easy for anyone to set up and run locally without additional infrastructure. Other systems (Postgres, CockroachDB, SQLite, etc.) are also supported but require more setup. The demo checks that required services are running (prompts you to start them if not), seeds databases, and displays animated results.
1515

1616
**Options:** `--systems a,b,c` | `--seconds N` | `--skip-prep` | `--no-animation`
1717

18-
**Note:** You will need to [install Rust](https://rust-lang.org/tools/install/) to run the spacetimedb benchmark, because we run a [Rust Client](#rust-client).
18+
**Note:** `demo` always runs the built-in `test-1` scenario. Use `bench` if you need to specify a test name directly.
19+
**Note:** `demo` selects targets with `--systems`; `bench` filters test connectors with `--connectors`.
1920

2021
## Results Summary
2122

@@ -198,7 +199,7 @@ docker compose up -d pg crdb
198199
npm run prep
199200

200201
# Run benchmark
201-
npm run bench -- --seconds 10 --concurrency 50 --alpha 1.5 --connectors spacetimedb,postgres_rpc,sqlite_rpc
202+
npm run bench -- test-1 --seconds 10 --concurrency 50 --alpha 1.5 --connectors spacetimedb,postgres_rpc,sqlite_rpc
202203
```
203204

204205
## Output

templates/keynote-2/src/cli.ts

Lines changed: 29 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -6,101 +6,26 @@ import type { TestCaseModule } from './tests/types';
66
import { fileURLToPath } from 'node:url';
77
import { join } from 'node:path';
88
import { RunResult } from './core/types.ts';
9-
10-
const args = process.argv.slice(2);
11-
12-
let testName = 'test-1';
13-
let posArgs = args;
14-
15-
if (args.length > 0 && !args[0].startsWith('--')) {
16-
testName = args[0];
17-
posArgs = args.slice(1);
18-
}
19-
20-
let seconds = 1,
21-
concurrency = 10,
22-
accounts = process.env.SEED_ACCOUNTS
23-
? Number(process.env.SEED_ACCOUNTS)
24-
: 100_000,
25-
alpha = 1.5,
26-
connectors: string[] | null = null,
27-
contentionTests: {
28-
startAlpha: number;
29-
endAlpha: number;
30-
step: number;
31-
concurrency: number;
32-
} | null = null,
33-
concurrencyTests: {
34-
startConc: number;
35-
endConc: number;
36-
step: number;
37-
alpha: number;
38-
} | null = null;
39-
40-
for (let i = 0; i < posArgs.length; ) {
41-
const arg = posArgs[i];
42-
if (!arg.startsWith('--')) {
43-
i++;
44-
continue;
45-
}
46-
const key = arg.slice(2);
47-
const val = posArgs[i + 1];
48-
if (!val || val.startsWith('--')) {
49-
i++;
50-
continue;
51-
}
52-
53-
switch (key) {
54-
case 'seconds':
55-
seconds = Number(val);
56-
i += 2;
57-
break;
58-
case 'concurrency':
59-
concurrency = Number(val);
60-
i += 2;
61-
break;
62-
case 'alpha':
63-
alpha = Number(val);
64-
i += 2;
65-
break;
66-
case 'connectors':
67-
connectors = val
68-
.split(',')
69-
.map((s) => s.trim())
70-
.filter(Boolean);
71-
i += 2;
72-
break;
73-
case 'contention-tests':
74-
contentionTests = {
75-
startAlpha: Number(posArgs[i + 1]),
76-
endAlpha: Number(posArgs[i + 2]),
77-
step: Number(posArgs[i + 3]),
78-
concurrency: Number(posArgs[i + 4]),
79-
};
80-
concurrency = Number(posArgs[i + 4]);
81-
82-
i += 5;
83-
break;
84-
case 'concurrency-tests':
85-
concurrencyTests = {
86-
startConc: Number(posArgs[i + 1]),
87-
endConc: Number(posArgs[i + 2]),
88-
step: Number(posArgs[i + 3]),
89-
alpha: Number(posArgs[i + 4]),
90-
};
91-
alpha = Number(posArgs[i + 4]);
92-
93-
i += 5;
94-
break;
95-
}
96-
}
97-
98-
interface BenchmarkConfig {
99-
connector: any;
100-
scenario: any;
101-
seconds: number;
102-
accounts: number;
103-
}
9+
import { parseBenchOptions } from './opts.ts';
10+
11+
const options = parseBenchOptions();
12+
const {
13+
testName,
14+
seconds,
15+
concurrency,
16+
accounts,
17+
alpha,
18+
connectors,
19+
contentionTests,
20+
concurrencyTests,
21+
} = options;
22+
23+
type RunOneArgs = Parameters<typeof runOne>[0];
24+
25+
type BenchmarkConfig = Pick<
26+
RunOneArgs,
27+
'connector' | 'scenario' | 'seconds' | 'accounts' | 'runtimeConfig'
28+
>;
10429

10530
class BenchmarkTester {
10631
private config: BenchmarkConfig;
@@ -229,11 +154,17 @@ const testDirPath = fileURLToPath(testDirUrl);
229154
const makeConnector = CONNECTORS[tc.system];
230155
if (!makeConnector) throw new Error(`Unknown connector ${tc.system}`);
231156

232-
const connector = makeConnector();
157+
const connector = makeConnector(options);
233158

234159
let res: any;
235160

236-
const config = { connector, scenario: tc.run, seconds, accounts };
161+
const config = {
162+
connector,
163+
scenario: tc.run,
164+
seconds,
165+
accounts,
166+
runtimeConfig: options,
167+
};
237168

238169
const tester = new BenchmarkTester(config);
239170

@@ -259,6 +190,7 @@ const testDirPath = fileURLToPath(testDirUrl);
259190
concurrency,
260191
accounts,
261192
alpha,
193+
runtimeConfig: options,
262194
});
263195
}
264196

0 commit comments

Comments
 (0)