Better Programming

Advice for programmers.

Follow publication

Member-only story

Load Testing WebSockets With k6

Ng Wai Foong
Better Programming
Published in
6 min readMar 2, 2021
A K6 client running a script.js file
Image by the author

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.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Ng Wai Foong
Ng Wai Foong

Written by Ng Wai Foong

Senior AI Engineer@Yoozoo | Content Writer #NLP #datascience #programming #machinelearning | Linkedin: https://www.linkedin.com/in/wai-foong-ng-694619185/

Write a response