Scaling to 1 million websockets in PHP

submited by
Style Pass
2024-11-17 11:00:04

A client asked me: How does one scale software to handle 1 million websocket connections? At 1000k connections when every client sends only one message per 30 seconds you have to deal with 33333 websocket messages per second. Dealing with that many requests per second is well understood in HTTP, but unfortunately these are messages on a websocket. Nevertheless, let's assume that these are HTTP requests for now.

Laravel behind Nginx can do 2908 requests per second on a Dell R440 Xeon Gold + 10 GbE when the average API call is 20 database queries per request (see here). This means that in order to handle 33333 API requests for 1 million websockets you need a minimum of 12 of these machines. Also, the corresponding 666k queries per second may need horizontal scaling of the database (unless the queries are really cheap, see here).

Approximately 2 dedicated machines with Haproxy behind DNS round-robin may be able to handle the reverse proxy load of stripping SSL and distributing over multiple machines for about 33k HTTPS requests (see here).

Leave a Comment