diff --git a/README.md b/README.md index c0509e9..a2b937a 100644 --- a/README.md +++ b/README.md @@ -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 - [!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 diff --git a/scripts/load_test.js b/scripts/load_test.js new file mode 100644 index 0000000..1500bf9 --- /dev/null +++ b/scripts/load_test.js @@ -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, + }); +}