Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.benchmark.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BENCHMARK_TARGET_URL=http://127.0.0.1:4000
BENCHMARK_ADMIN_TOKEN=
BENCHMARK_CONCURRENCY=2
BENCHMARK_REQUESTS_PER_ENDPOINT=8
BENCHMARK_OUTPUT_DIR=benchmarks/results
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ node_modules
dist
.env
.env.*
!.env.benchmark.example
coverage
*.log
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "node src/server.js",
"start": "node src/server.js",
"test": "node --test src/tests"
"test": "node --test src/tests/*.js"
},
"dependencies": {
"cors": "^2.8.5",
Expand Down
38 changes: 38 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# API Benchmarks

This benchmark suite covers every currently mounted API endpoint in `apps/api/src/app.js`, plus `/health`.

## Commands

```sh
npm run benchmark
npm run benchmark:smoke
npm run benchmark:coverage
```

By default the runner starts the Express app in-process on a random loopback port. To run against an already running local or staging server, set `BENCHMARK_TARGET_URL`.

## Configuration

Copy `.env.benchmark.example` into your shell environment or CI secret configuration and adjust values as needed:

- `BENCHMARK_TARGET_URL`: optional target base URL. If unset, the runner starts the local app.
- `BENCHMARK_ADMIN_TOKEN`: optional bearer token for protected admin routes. If unset for local runs, the runner creates a short-lived benchmark token.
- `BENCHMARK_CONCURRENCY`: parallel requests per endpoint.
- `BENCHMARK_REQUESTS_PER_ENDPOINT`: measured requests per endpoint.
- `BENCHMARK_OUTPUT_DIR`: output directory for JSON and Markdown reports.

Thresholds live in `benchmarks/thresholds.json`. `npm run benchmark:smoke` is the low-concurrency gate command intended for CI, while local full runs provide broader baseline data.

`npm run benchmark:coverage` checks the benchmark endpoint inventory against the API route mounts in `apps/api/src/app.js`.

## Output

Each run writes:

- `benchmarks/results/full-latest.json`
- `benchmarks/results/full-latest.md`
- `benchmarks/results/smoke-latest.json`
- `benchmarks/results/smoke-latest.md`

Reports include p50, p95, p99 latency, p99 time to first byte, requests per second, peak requests per second, and error rate for each endpoint.
186 changes: 186 additions & 0 deletions benchmarks/endpoints.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
export const benchmarkEndpoints = [
{
name: "health",
method: "GET",
path: "/health",
expectedStatus: 200
},
{
name: "auth-register",
method: "POST",
path: "/api/auth/register",
expectedStatus: 201,
json: ({ iteration }) => ({
email: `benchmark-user-${Date.now()}-${iteration}@example.com`,
password: "benchmark-pass-123",
role: "freelancer"
})
},
{
name: "auth-login",
method: "POST",
path: "/api/auth/login",
expectedStatus: 200,
json: {
email: "benchmark-user@example.com",
password: "benchmark-pass-123"
}
},
{
name: "auth-oauth-callback",
method: "GET",
path: "/api/auth/oauth/benchmark/callback",
expectedStatus: 200
},
{
name: "auth-refresh",
method: "POST",
path: "/api/auth/refresh",
expectedStatus: 200
},
{
name: "users-list",
method: "GET",
path: "/api/users",
expectedStatus: 200
},
{
name: "users-create",
method: "POST",
path: "/api/users",
expectedStatus: 201,
json: ({ iteration }) => ({
email: `benchmark-client-${iteration}@example.com`,
name: "Benchmark Client",
role: "client"
})
},
{
name: "jobs-list",
method: "GET",
path: "/api/jobs",
expectedStatus: 200
},
{
name: "jobs-create",
method: "POST",
path: "/api/jobs",
expectedStatus: 201,
json: {
title: "Benchmark API implementation",
description: "Create a benchmark suite with realistic local payloads.",
budgetMin: 500,
budgetMax: 1500,
categoryId: "software-development",
skills: ["node", "express", "benchmarking"]
}
},
{
name: "proposals-list",
method: "GET",
path: "/api/proposals",
expectedStatus: 200
},
{
name: "proposals-create",
method: "POST",
path: "/api/proposals",
expectedStatus: 201,
json: {
jobId: "job_benchmark",
freelancerId: "usr_benchmark",
coverLetter: "I can deliver a reproducible API benchmark suite.",
price: 950,
timelineDays: 5
}
},
{
name: "payments-create",
method: "POST",
path: "/api/payments",
expectedStatus: 201,
json: {
amount: 95000,
currency: "usd",
jobId: "job_benchmark"
}
},
{
name: "reviews-list",
method: "GET",
path: "/api/reviews",
expectedStatus: 200
},
{
name: "reviews-create",
method: "POST",
path: "/api/reviews",
expectedStatus: 201,
json: {
jobId: "job_benchmark",
reviewerId: "usr_client",
revieweeId: "usr_freelancer",
rating: 5,
comment: "Fast delivery and clear reporting."
}
},
{
name: "messages-list",
method: "GET",
path: "/api/messages",
expectedStatus: 200
},
{
name: "messages-create",
method: "POST",
path: "/api/messages",
expectedStatus: 201,
json: {
fromUserId: "usr_client",
toUserId: "usr_freelancer",
body: "Can you share the latest benchmark report?"
}
},
{
name: "notifications-list",
method: "GET",
path: "/api/notifications",
expectedStatus: 200
},
{
name: "notifications-create",
method: "POST",
path: "/api/notifications",
expectedStatus: 201,
json: {
userId: "usr_client",
type: "proposal_received",
message: "A freelancer submitted a proposal."
}
},
{
name: "uploads-create",
method: "POST",
path: "/api/uploads",
expectedStatus: 201,
multipart: {
fieldName: "file",
filename: "benchmark-profile.txt",
type: "text/plain",
body: "Synthetic benchmark upload payload for API route coverage."
}
},
{
name: "search",
method: "GET",
path: "/api/search?q=benchmark",
expectedStatus: 200
},
{
name: "admin-metrics",
method: "GET",
path: "/api/admin/metrics",
expectedStatus: 200,
auth: true
}
];
Loading