Validate real-time connection performance
WebSocket Load Testing
Open hundreds of concurrent WebSocket connections and exchange messages at scale. Measure connection establishment time, message latency, and throughput under load.
loadtest.dev runs HTTP plans; this guide uses k6 directly.
Concurrent WebSocket connection testing
Message send/receive latency tracking
Connection stability under load
Custom message payloads (JSON, binary)
Reconnection and error handling patterns
Compatible with Socket.io and raw WebSockets
websocket-test.js
import ws from 'k6/ws';
import { check } from 'k6';
export const options = { vus: 100, duration: '2m' };
export default function () {
const res = ws.connect('wss://echo.example.com', {}, (socket) => {
socket.on('open', () => {
socket.send(JSON.stringify({ type: 'ping' }));
});
socket.on('message', (msg) => {
check(msg, {
'got response': (m) => m.length > 0,
});
});
socket.setTimeout(() => socket.close(), 10000);
});
check(res, { 'connected': (r) => r && r.status === 101 });
}Frequently asked questions
Related guides
Run this as a plan
Put the scenario in your app's Config/load-plan.json and run it from the narduk-app CLI.