<- Test Directory

Testing websockets with SocketIO

How to use LoadForge to load test websocket / SocketIO based applications


LoadForge supports SocketIO load testing for websockets. We have a guide using standard libraries available on our default websockets test guide.

The SocketIO implementation makes it much easier to test, as you can see below.

Example Code

import time
import json
from locust import task
from locust_plugins.users import SocketIOUser

class MySocketIOUser(SocketIOUser):
    def my_task(self):
        self.my_value = None


        # example of subscribe
        self.send('42["subscribe",{"url":"/game/237382","sendInitialUpdate": true}]')

        # wait until I get a push message to on_message
        while not self.my_value:

        # you can do http in the same taskset as well

        # wait for additional pushes, while occasionally sending heartbeats, like a real client would

    def on_message(self, message):
        self.my_value = json.loads(message)["my_value"]

    if __name__ == "__main__":
        host = "http://example.com"

This guide is part of the LoadForge Directory, an index of locustfile's for use with LoadForge website and API load tests. We also provide a wizard to generate tests, and onboarding assistance for clients. Contact us should you have any questions.

LoadForge provides load testing and stress tests for websites, APIs and servers. It uses your cloud account to rapidly scale large numbers of simulated users to load test your website, store, API, or application for cheap - just cents per test!

For more help on Tests please see our official documentation. Logged in users can also use our wizard to generate a locustfile, or you can record your browser steps.

Ready to run your test?
Start your first test within minutes.