|
| 1 | +# API Benchmark Suite |
| 2 | + |
| 3 | +This directory contains a reproducible benchmark suite for the platform API. |
| 4 | + |
| 5 | +## Coverage |
| 6 | + |
| 7 | +The suite covers every route mounted under `/api/` in `apps/api/src/app.js` plus `/health` for server readiness: |
| 8 | + |
| 9 | +- `POST /api/auth/register` |
| 10 | +- `POST /api/auth/login` |
| 11 | +- `GET /api/auth/oauth/:provider/callback` |
| 12 | +- `POST /api/auth/refresh` |
| 13 | +- `GET /api/users` |
| 14 | +- `POST /api/users` |
| 15 | +- `GET /api/jobs` |
| 16 | +- `POST /api/jobs` |
| 17 | +- `GET /api/proposals` |
| 18 | +- `POST /api/proposals` |
| 19 | +- `POST /api/payments` |
| 20 | +- `GET /api/reviews` |
| 21 | +- `POST /api/reviews` |
| 22 | +- `GET /api/messages` |
| 23 | +- `POST /api/messages` |
| 24 | +- `GET /api/notifications` |
| 25 | +- `POST /api/notifications` |
| 26 | +- `POST /api/uploads` |
| 27 | +- `GET /api/search?q=...` |
| 28 | +- `GET /api/admin/metrics` with a benchmark token |
| 29 | + |
| 30 | +Payloads live in `routes.mjs` so reviewers can inspect and tune realistic request bodies without changing the runner. |
| 31 | + |
| 32 | +## Commands |
| 33 | + |
| 34 | +From the repository root: |
| 35 | + |
| 36 | +```bash |
| 37 | +npm run benchmark |
| 38 | +``` |
| 39 | + |
| 40 | +Smoke mode for CI: |
| 41 | + |
| 42 | +```bash |
| 43 | +npm run benchmark:smoke |
| 44 | +``` |
| 45 | + |
| 46 | +Optional overrides: |
| 47 | + |
| 48 | +```bash |
| 49 | +npm run benchmark -- --requests 20 --concurrency 4 --warmup 2 |
| 50 | +npm run benchmark:smoke -- --requests 3 --concurrency 1 |
| 51 | +``` |
| 52 | + |
| 53 | +## Target selection |
| 54 | + |
| 55 | +If `BENCHMARK_TARGET_URL` is unset, the runner starts the local Express app on a random loopback port and benchmarks that process. |
| 56 | + |
| 57 | +If `BENCHMARK_TARGET_URL` is set, the runner benchmarks that local/staging host instead: |
| 58 | + |
| 59 | +```bash |
| 60 | +BENCHMARK_TARGET_URL=http://localhost:4000 npm run benchmark |
| 61 | +``` |
| 62 | + |
| 63 | +Do not run this against production unless the service owner has explicitly approved the load profile. |
| 64 | + |
| 65 | +## Auth-protected routes |
| 66 | + |
| 67 | +`GET /api/admin/metrics` uses a dedicated benchmark token. |
| 68 | + |
| 69 | +- Set `BENCHMARK_AUTH_TOKEN` to use a real staging benchmark token. |
| 70 | +- If omitted, the runner creates a short-lived HS256 token using `JWT_SECRET` or the local development default. |
| 71 | + |
| 72 | +## Output |
| 73 | + |
| 74 | +Every run writes both machine-readable and human-readable output: |
| 75 | + |
| 76 | +```text |
| 77 | +benchmarks/results/<mode>-<timestamp>.json |
| 78 | +benchmarks/results/<mode>-<timestamp>.md |
| 79 | +``` |
| 80 | + |
| 81 | +Captured per endpoint: |
| 82 | + |
| 83 | +- p50, p95, p99 latency in milliseconds |
| 84 | +- p50, p95, p99 time-to-first-byte in milliseconds |
| 85 | +- sustained requests per second |
| 86 | +- peak requests-per-second estimate |
| 87 | +- error rate percentage |
| 88 | +- status-code counts |
| 89 | + |
| 90 | +## Regression gate |
| 91 | + |
| 92 | +`thresholds.json` stores reviewable limits. CI runs smoke mode and fails if any endpoint exceeds configured p99 latency or error-rate thresholds. |
| 93 | + |
| 94 | +The default thresholds are intentionally conservative for local/CI smoke checks. Tighten them after collecting representative staging baselines. |
0 commit comments