Load testing
Repeatable API, messaging and media load tests, and the measured local results.
The 300-viewer livestream figure is a target, not a supported capacity. Only results from deployed infrastructure count toward capacity claims. Everything below was measured on one developer machine.
Tools
| Workload | Tool | Location |
|---|---|---|
| HTTP API (tokens, calls, REST messaging) | k6 (grafana/k6:1.3.0 container) | loadtest/k6/api.js |
| Socket.IO fan-out latency | Node script with socket.io-client | apps/api/scripts/load-messaging.ts |
| Livestream media | LiveKit's official lk load-test (livekit/livekit-cli:v2.13.2) | loadtest/livekit/run.sh |
Every script refuses *.lynkoria.com targets unless I_HAVE_PRODUCTION_AUTHORIZATION=yes is set. Use a dedicated load-test project and lynk_test_ key; raise its tokensPerMinute, maxConcurrentRooms and maxRoomSize limits first, or you will measure the limiter.
docker run --rm -i --add-host=host.docker.internal:host-gateway -e BASE_URL=http://host.docker.internal:3011 \
-e SERVICE_KEY=lynk_test_… -e VUS=50 -e DURATION=60s grafana/k6:1.3.0 run - < loadtest/k6/api.js
BASE_URL=http://127.0.0.1:3011 SERVICE_KEY=lynk_test_… RECEIVERS=500 MESSAGES=60 RATE=5 \
pnpm --filter @lynkoria/api exec tsx scripts/load-messaging.ts
BASE_URL=http://127.0.0.1:3011 SERVICE_KEY=lynk_test_… loadtest/livekit/run.sh "50 100 200 300" medium 45sFor staging, set LK_URL, LK_KEY, LK_SECRET and LK_NETWORK=host, run the load generators on separate machines from the media node, and record node CPU, memory and network with your monitoring stack (infra/monitoring).
Local results (2026-11-13)
Environment. AMD Ryzen 5 7500F (6 cores / 12 threads), 15 GiB RAM, WSL2 (kernel 6.18), Docker 29.9. One API process (built dist/, workers on, per-key limiter raised), PostgreSQL 18, Redis 8 and LiveKit v1.13.11 in local containers. Load generators ran on the same host, so they competed for CPU with the system under test. Raw output: loadtest/results/.
HTTP API (k6, 60 s per step; one iteration = token + create call + join token + end call + send message)
| VUs | Requests/s | Failed | All requests p50 / p95 / p99 (ms) | Token p95 | Join token p95 | REST send p95 |
|---|---|---|---|---|---|---|
| 20 | 429 | 0.00% | 33 / 142 / 199 | 28 | 36 | 199 |
| 50 | 595 | 40.0%* | 70 / 242 / 333 | 78 | 129 | 354 |
| 100 | 380 | 0.37%* | 222 / 502 / 622 | 221 | 312 | 622 |
* Every failure was connection refused from Docker Desktop's host.docker.internal forwarder (WSL → Windows → container), not an API response. The 50-VU step is therefore not a valid measurement. Throughput falling at 100 VUs while latency rises indicates the single API process (or the shared host) saturated; REST message send is the slowest path (per-conversation lock and sequence allocation in PostgreSQL).
Socket.IO fan-out (one sender, N receivers in one conversation)
| Receivers | Messages × rate | Deliveries | Delivery ratio | Delivery p50 / p95 / p99 (ms) | Send ack p95 |
|---|---|---|---|---|---|
| 50 | 100 × 10/s | 5,000 | 100% | 12.9 / 14.5 / 15.9 | 15.0 |
| 200 | 100 × 10/s | 20,000 | 100% | 15.6 / 18.4 / 19.7 | 19.9 |
| 500 | 60 × 5/s | 30,000 | 100% | 20.2 / 25.6 / 173 | 28.5 |
| 999 | 30 × 2/s | 29,970 | 100% | 29.0 / 37.8 / 42.5 | 43.7 |
Conversations are capped at 1,000 members. These are local loopback numbers with one API process.
Socket.IO fan-out across two API instances (2026-11-14)
Apple M1 Pro (8 cores), 16 GiB, macOS with Docker Desktop. Two API processes (apps/api/scripts/e2e-server.ts, same database, Redis and secrets) with the Redis Streams adapter (ADR 021); the sender is on instance A and receivers alternate between A and B, so half of all deliveries cross instances through Redis. The one-instance rows put every receiver on A for comparison. Generator on the same host. Raw output: loadtest/results/socket-fanout-multi-instance-local.txt.
| Receivers | Messages × rate | Instances | Delivery ratio | Delivery p50 / p95 / p99 (ms) | Send ack p95 |
|---|---|---|---|---|---|
| 200 | 100 × 10/s | 1 | 100% | 39.4 / 55.5 / 63.7 | 50.4 |
| 200 | 100 × 10/s | 2 | 100% | 35.9 / 52.1 / 55.2 | 44.9 |
| 500 | 60 × 5/s | 1 | 100% | 48.5 / 65.3 / 76.0 | 51.2 |
| 500 | 60 × 5/s | 2 | 100% | 45.9 / 63.1 / 71.8 | 48.2 |
| 999 | 30 × 2/s | 1 | 100% | 52.2 / 70.3 / 75.4 | 48.9 |
| 999 | 30 × 2/s | 2 | 100% | 52.6 / 73.8 / 90.8 | 51.3 |
Crossing instances added no measurable median latency at these rates; p99 rose at 999 receivers. Every delivery arrived. This machine differs from the one used for the single-instance table above, so compare rows within this table only.
Failure drills
node scripts/failure-drills.mjs stops Redis, PostgreSQL and LiveKit one at a time (abruptly, docker stop -t 0) under a running API, then restarts them. Raw output: loadtest/results/failure-drills-local.txt.
| Dependency down | /health/ready | Request during outage | Recovery after the container is healthy |
|---|---|---|---|
| Redis | 503 | Messaging token: 503 (rate limits fail closed) | 21 ms |
| PostgreSQL | 503 | Messaging token: 503 with Retry-After | 52 ms |
| LiveKit | 200 (unchanged) | Create call: 503; messaging token: 200 | 18 ms |
The first PostgreSQL drill crashed the API process: an idle pooled connection's termination (57P01) was an unhandled error event. The pool now handles it, a regression test terminates a pooled backend, and database outages return a retryable 503 instead of 500.
Livestream viewers (lk load-test, 1 simulcast video publisher, 45 s per step)
| Viewers | Resolution | Subscribed | Aggregate bitrate (avg/viewer) | Packet loss | LiveKit CPU† | LiveKit memory |
|---|---|---|---|---|---|---|
| 50 | medium | 50/50 | 16.8 Mbps (336 kbps) | 0% | 16% | 439 MiB |
| 100 | medium | 100/100 | 32.4 Mbps (324 kbps) | 0% | 31% | 333 MiB |
| 200 | medium | 200/200 | 60.5 Mbps (303 kbps) | 0% | 59% | 427 MiB |
| 300 | medium | 300/300 | 85.9 Mbps (286 kbps) | 0% | 80% | 598 MiB |
| 300 | high | 300/300 | 217.7 Mbps (726 kbps) | 3.22% | 175% | 621 MiB |
† docker stats percentage of one core, sampled mid-run. Simulated subscribers receive but do not decode media, and all traffic stayed on loopback, so real client CPU, Wi-Fi/cellular loss, TURN relay and internet egress are not represented. The 3.2% loss at high resolution happened with the load generator sharing the host; whether it is server- or generator-side is unknown.
Bandwidth estimate. At ~0.3 Mbps per medium-quality viewer, 300 viewers need ~90 Mbps of egress, about 40 GB per hour of streaming (≈0.14 GB per viewer-hour); at high quality ~220 Mbps (≈100 GB per hour). Price and size the media node's transfer accordingly.
Not yet measured
Staging or production environments; multiple concurrent livestreams; viewer join/leave churn; network interruption; recording/Egress under load; HLS delivery; push throughput against real providers; scanner throughput; storage throughput; reconnection time; jitter and end-to-end media latency. A 300-viewer claim requires repeating the viewer test on the deployed media node with generators on separate machines.