Member-only story
Load Testing WebSockets With k6
Using a built-in WebSocket client to test the performance of your server

Building on top of my previous article on k6, the topic for this article is on load testing WebSocket. Unlike HTTP, WebSocket offers full-duplex communication channels over a single TCP connection. This enables your server to send push notifications directly to users.
Fortunately, k6 provides its own ws
client based on the WebSocket protocol. It’s slightly different than the http
client, as each VU runs on an asynchronous event loop.
Setup
k6 installation
Before we begin, make sure you’ve installed the necessary packages and modules for k6. Kindly refer to my previous article on how to install k6 in your local machine.
Using your own WebSocket server (optional)
This tutorial assumes you have an existing WebSocket server. If you do not have one, kindly use the following script, which is based on FastAPI. It will echo back the message sent by the user via WebSocket.