Antigravity - Benchmark APIs#620
Open
lqkhanh295 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a baseline benchmarking suite for the API using autocannon, with CI smoke benchmarks and persisted JSON/markdown reports to support regression tracking (Issue #30).
Changes:
- Adds a root
benchmarkscript plusautocannon/dotenvdev dependencies. - Introduces
benchmarks/run.mjs+benchmarks/thresholds.jsonto run/load-gated benchmarks and write results tobenchmarks/results/. - Adds a GitHub Actions workflow to start the API and run a smoke benchmark on PRs/pushes.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Adds benchmark script and benchmarking dev dependencies. |
| package-lock.json | Locks new benchmarking dependency tree (autocannon, dotenv, transitive deps). |
| benchmarks/thresholds.json | Defines regression thresholds (p99, error rate, min RPS). |
| benchmarks/run.mjs | Implements benchmark runner, results serialization, and CI gating. |
| benchmarks/results/summary.md | Checks in a sample human-readable benchmark summary. |
| benchmarks/results/results.json | Checks in a sample machine-readable benchmark output. |
| .github/workflows/benchmark.yml | Adds CI job to run a smoke benchmark against a locally started API server. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+13
to
+16
| const HOST = process.env.BENCHMARK_TARGET_HOST || 'http://localhost:3000'; | ||
| const TOKEN = process.env.BENCHMARK_AUTH_TOKEN || 'test_token'; | ||
| const DURATION = parseInt(process.env.BENCHMARK_DURATION || '5', 10); | ||
| const CONNECTIONS = parseInt(process.env.BENCHMARK_CONNECTIONS || '10', 10); |
Comment on lines
+47
to
+49
| if (endpoint.auth) { | ||
| opts.headers['Authorization'] = `Bearer ${TOKEN}`; | ||
| } |
Comment on lines
+79
to
+81
| const p50 = result.latency.p50; | ||
| const p95 = result.latency.p95; | ||
| const p99 = result.latency.p99; |
Comment on lines
+82
to
+85
| const rps = result.requests.average; | ||
| const errorRate = (result.errors / result.requests.total) * 100 || 0; | ||
| // We estimate TTFB by using min latency or a proxy, but autocannon latency is effectively TTFB to full response. | ||
| const ttfb = result.latency.min; |
Comment on lines
+91
to
+93
| p50, p95, p99, rps, errorRate, ttfb, | ||
| passed: p99 <= thresholds.maxP99LatencyMs && errorRate <= thresholds.maxErrorRatePercent | ||
| }; |
Comment on lines
+25
to
+28
| run: | | ||
| npm run dev -w apps/api & | ||
| # Wait for server to start | ||
| sleep 5 |
Comment on lines
+34
to
+39
| run: | | ||
| export BENCHMARK_DURATION=2 | ||
| export BENCHMARK_CONNECTIONS=5 | ||
| npm run benchmark | ||
| env: | ||
| CI: true |
Comment on lines
+6
to
+13
| | Endpoint | Method | Path | p50 (ms) | p95 (ms) | p99 (ms) | RPS | Error Rate | TTFB (ms) | Status | | ||
| |---|---|---|---|---|---|---|---|---|---| | ||
| | Health Check | GET | `/health` | 1 | undefined | 3 | 3206.00 | 0.00% | 1 | ✅ PASS | | ||
| | Get Users | GET | `/api/users` | 1 | undefined | 3 | 3174.00 | 0.00% | 1 | ✅ PASS | | ||
| | Get Jobs | GET | `/api/jobs` | 1 | undefined | 4 | 3090.00 | 0.00% | 1 | ✅ PASS | | ||
| | Search | GET | `/api/search?q=test` | 0 | undefined | 2 | 5169.50 | 0.00% | 1 | ✅ PASS | | ||
| | Admin Metrics | GET | `/api/admin/metrics` | 0 | undefined | 1 | 8785.00 | 0.00% | 1 | ✅ PASS | | ||
| | Post Job | POST | `/api/jobs` | 2 | undefined | 8 | 1976.50 | 0.00% | 1 | ✅ PASS | |
Comment on lines
+1
to
+12
| [ | ||
| { | ||
| "name": "Health Check", | ||
| "path": "/health", | ||
| "method": "GET", | ||
| "p50": 1, | ||
| "p99": 3, | ||
| "rps": 3206, | ||
| "errorRate": 0, | ||
| "ttfb": 1, | ||
| "passed": true | ||
| }, |
Comment on lines
+10
to
+14
| // Load env config | ||
| dotenv.config({ path: path.join(__dirname, '.env.benchmark') }); | ||
|
|
||
| const HOST = process.env.BENCHMARK_TARGET_HOST || 'http://localhost:3000'; | ||
| const TOKEN = process.env.BENCHMARK_AUTH_TOKEN || 'test_token'; |
af5d8b7 to
8830293
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #30
Benchmark Results
Target: http://localhost:4000
Connections: 5 | Duration: 2s per endpoint
/health/api/users/api/jobs/api/search?q=test/api/admin/metrics/api/jobs