feat(verification): add k6 load test script and execution guide to README

This commit is contained in:
2026-09-19 14:18:41 +03:30
parent 9648620963
commit 2f4c99620e
2 changed files with 84 additions and 0 deletions

View File

@@ -42,6 +42,42 @@ Duplicate raw_ids resolved: 20 ✅
===================================== =====================================
``` ```
### 3. Load Testing (k6)
A k6 load test script is available at [`scripts/load_test.js`](scripts/load_test.js) to simulate high-concurrency ingestion (ramping up to 50 virtual users pushing sustained load).
#### Option A: Running with Docker (Recommended)
Running k6 via Docker avoids Windows host outbound socket limits:
- **Windows (PowerShell / Docker Desktop)**:
```powershell
docker run --rm -v "${PWD}/scripts:/scripts" grafana/k6 run -e API_URL="http://host.docker.internal:8000/api/v1/cdr/raw" /scripts/load_test.js
```
- **Linux / macOS (Host Network)**:
```bash
docker run --rm -i --network=host grafana/k6 run - <scripts/load_test.js
```
#### Option B: Running with Local k6
If k6 is installed on your machine:
- **Windows (PowerShell)**:
```powershell
k6 run scripts/load_test.js
# Or using explicit path:
& "C:\Program Files\k6\k6.exe" run scripts/load_test.js
```
- **Linux / macOS**:
```bash
k6 run scripts/load_test.js
```
> [!TIP]
> **Windows Ephemeral Port Note**: Under rapid high-concurrency load (>20,000 requests in <60 seconds), Windows may exhaust dynamic outbound ports held in `TIME_WAIT`, throwing `connectex: Only one usage of each socket address is normally permitted`. Running k6 inside Docker (Option A) avoids this host-level limitation.
--- ---
## 2. Architecture & Data Flow ## 2. Architecture & Data Flow

48
scripts/load_test.js Normal file
View File

@@ -0,0 +1,48 @@
import http from 'k6/http';
import { check } from 'k6';
export const options = {
scenarios: {
// Ramp up from 10 to 50 virtual users pushing sustained load
sustained_load: {
executor: 'ramping-vus',
startVUs: 10,
stages: [
{ duration: '10s', target: 50 }, // Ramp up to 50 VUs
{ duration: '30s', target: 50 }, // Stay at 50 VUs (~1,000+ req/s)
{ duration: '5s', target: 0 }, // Ramp down
],
},
},
thresholds: {
http_req_duration: ['p(95)<50'], // 95% of API responses under 50ms
http_req_failed: ['rate<0.01'], // Less than 1% failure
},
};
export default function () {
const url = __ENV.API_URL || 'http://localhost:8000/api/v1/cdr/raw';
const payload = JSON.stringify({
raw_id: `load-${__VU}-${__ITER}-${Date.now()}`,
src_ip: '10.240.1.1',
device_id: '310410998877665',
caller_num: '+19875551234',
svc: '4G_DATA',
up_bytes: 1048576,
down_bytes: 4194304,
rat: 6,
lac: '4021',
ci: '8812',
epoch_start: 1726070000,
epoch_end: 1726070300,
});
const params = {
headers: { 'Content-Type': 'application/json' },
};
const res = http.post(url, payload, params);
check(res, {
'status is 202 or 429': (r) => r.status === 202 || r.status === 429,
});
}