Pub sub

February 10, 2022

The Goal

Handle a million or more websocket connections with 2-4 GB RAM and with 1-4 cores.


Inspiration

I was searching for a scalable way of handling a million or more websocket connections. While searching I found a great presentation by Eran Yanay showing every step of how optimize the server in variety different ways. I used the boilerplate he provided with all the optimizations, and built on top of it a pub sub server, you can find the boilerplate here.


Setting up the server

The server can only be deployed on Linux. Because the server utilizes linux specific syscalls, such as epoll and Setrlimit. Though if you are on windows you can overcome this by installing windows subsystem for linux (WSL).


How does the Prototype work?

I wanted to make it as fast as possible and as simple as possible so avoided using json to decode the messages. And implemented a custom protocol that is very simple and easy to understand.


Client Messages

Client Recieve Messages