← Load Test Directory

Load Testing WebSockets

Guide on load testing WebSocket-based applications with LoadForge using Locust.

You are now browsing the LoadForge locust test directory. You can use these tests as a starting point for your own tests, or use our AI wizard to generate one automatically.

World

Overview

LoadForge provides support for generic WebSocket testing via the WebSocketUser from locust-plugins. You can open WebSocket connections, send and receive messages, and simulate concurrency to measure performance under load.

Locust Test Script (locust.py)

# locust.py
import time
from locust import HttpUser, between, task
from locust_plugins.users import WebSocketUser

class MyWebSocketUser(WebSocketUser):
    wait_time = between(1, 3)
    host = "wss://YOUR_WS_URL_HERE"

    def on_start(self):
        # Connect to WebSocket server
        self.connect("/ws")

    @task
    def send_message(self):
        # Send a message to the WebSocket
        self.send("hello", name="SendMessage")
        # Optionally wait for server response
        time.sleep(1)

    def on_message(self, message):
        # Handle incoming message
        print(f"Received: {message}")

if __name__ == "__main__":
    from locust import run_single_user
    run_single_user(MyWebSocketUser)

Notes:

  • Install dependencies: pip install locust locust-plugins websockets if you wish to test locally.
  • Replace YOUR_WS_URL_HERE and endpoint /ws with your actual WebSocket URL and path.

Ready to run your test?
Run your test today with LoadForge.