IoT Websocket Connections

Hello,

My company is creating and Django service that will ideally maintain a constant Web Socket connection to IoT devices indefinitely. We’re approaching our go-live and through testing we found that our server is not able to reliable maintain more than about 2000 Web Socket connections on a server with 10Gb Ram and 10vCPUS, leading me to believe our Web Socket consumer is extremely unoptimized. Currently we do about 10 synchronous database calls to create and update records for each websocket message we receive from the IoT device. What would be the best way of migrating these database operations out of the consumer and are there other areas within the consumer I should be investigating to try and improve the efficiency of the server?

Thank you!

Welcome @taylor !

Is your Python code making the websocket connections or are the IoT devices initiating them?

If you are initiating these connections, how are you doing it? (What websocket client are you using?)

If your code is the target of these connections, what ASGI server are you using? (Daphne? Uvicorn? Something else?)

I don’t do database operations in the consumer. When I’m collecting data like this, I set up independent Channel Worker processes. The consumer doesn’t do anything other than receive data and pass it along to the worker through the channel layer. All the database (and other work) is done in the workers.
This allows the consumer to be as responsive as possible, while allowing the workers to batch operations for efficiency.

We currently use Daphne as our ASGI server and the IoT device is responsible for establishing the Web Socket to the server.