feat: expand backend admin marketplace and scaling
فشلت بعض الفحوصات
/ deploy (push) Failing after 1m22s
فشلت بعض الفحوصات
/ deploy (push) Failing after 1m22s
هذا الالتزام موجود في:
118
PERFORMANCE_TESTING.md
Normal file
118
PERFORMANCE_TESTING.md
Normal file
@@ -0,0 +1,118 @@
|
||||
# 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:
|
||||
|
||||
```powershell
|
||||
npm run build
|
||||
npm test -- --runInBand
|
||||
npm run test:e2e -- --runInBand
|
||||
```
|
||||
|
||||
## 2. Startup time
|
||||
|
||||
Build the app, then measure cold start:
|
||||
|
||||
```powershell
|
||||
npm run build
|
||||
npm run perf:startup
|
||||
```
|
||||
|
||||
Optional parameters:
|
||||
|
||||
```powershell
|
||||
node scripts/startup-benchmark.js --port 4200 --timeout 45000
|
||||
```
|
||||
|
||||
## 3. Health endpoint load
|
||||
|
||||
If the API is already running on port `4000`:
|
||||
|
||||
```powershell
|
||||
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:
|
||||
|
||||
```powershell
|
||||
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:
|
||||
|
||||
```powershell
|
||||
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:
|
||||
|
||||
```powershell
|
||||
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:
|
||||
|
||||
```powershell
|
||||
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:
|
||||
|
||||
```powershell
|
||||
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
|
||||
المرجع في مشكلة جديدة
حظر مستخدم