الملفات
back_end_oudelaa/PERFORMANCE_TESTING.md
boutmoun123 5bd5e19a89
فشلت بعض الفحوصات
/ deploy (push) Failing after 1m22s
feat: expand backend admin marketplace and scaling
2026-05-14 16:44:07 +03:00

2.9 KiB

Performance Testing

This project now includes built-in scripts to check correctness, startup time, endpoint latency, and basic load.

1. Correctness first

Run these before any performance test:

npm run build
npm test -- --runInBand
npm run test:e2e -- --runInBand

2. Startup time

Build the app, then measure cold start:

npm run build
npm run perf:startup

Optional parameters:

node scripts/startup-benchmark.js --port 4200 --timeout 45000

3. Health endpoint load

If the API is already running on port 4000:

npm run perf:health

This runs a simple GET benchmark against http://127.0.0.1:4000/api/v1/health.

4. Custom endpoint load

Examples:

node scripts/load-test.js --url http://127.0.0.1:4000/api/v1/health --duration 20 --concurrency 50
node scripts/load-test.js --url http://127.0.0.1:4000/api/v1/feed/trending --header "Authorization: Bearer YOUR_TOKEN" --duration 30 --concurrency 25
node scripts/load-test.js --url http://127.0.0.1:4000/api/v1/auth/login --method POST --body "{\"email\":\"user@example.com\",\"password\":\"secret\"}" --duration 20 --concurrency 10

Supported options:

  • --url
  • --method
  • --duration
  • --concurrency
  • --timeout
  • --warmup
  • --header "Key: Value"
  • --body
  • --body-file

5. What to watch

  • requestsPerSecond: throughput
  • successRate: percentage of successful requests
  • non2xxCount: server or validation failures
  • timeoutCount: slow requests
  • latencyMs.p95 and latencyMs.p99: tail latency under load

6. Practical test order

  1. build
  2. unit tests
  3. e2e tests
  4. startup benchmark
  5. health benchmark
  6. authenticated benchmarks for hot endpoints:
    • auth/login
    • feed/me
    • feed/trending
    • posts
    • chat/messages
    • notifications

7. Real API benchmark examples

Login:

node scripts/load-test.js --url http://127.0.0.1:4000/api/v1/auth/login --method POST --header "Content-Type: application/json" --body "{\"email\":\"user@example.com\",\"password\":\"secret123\"}" --duration 20 --concurrency 10

Trending feed with bearer token:

node scripts/load-test.js --url http://127.0.0.1:4000/api/v1/feed/trending --header "Authorization: Bearer YOUR_ACCESS_TOKEN" --duration 30 --concurrency 25

Authenticated user feed:

node scripts/load-test.js --url http://127.0.0.1:4000/api/v1/feed/me?limit=20 --header "Authorization: Bearer YOUR_ACCESS_TOKEN" --duration 30 --concurrency 15

Notifications:

node scripts/load-test.js --url http://127.0.0.1:4000/api/v1/notifications --header "Authorization: Bearer YOUR_ACCESS_TOKEN" --duration 20 --concurrency 15

8. Limits

These scripts are useful local benchmarks, not full production profiling. They do not replace:

  • database profiling
  • CPU and memory profiling
  • distributed load tools like k6 or Gatling
  • multi-instance tests behind a reverse proxy