Answer the question
In order to leave comments, you need to log in
How to send data streams via WebSocket?
Good afternoon.
Share your experience on how to solve this problem:
There is a server, there are 5 thousand data streams. Let's say each thread is just a number that changes periodically. That is, there are 5 thousand numbers, each of which changes periodically.
There are 1 million users (customers, say, mob applications). Each client wants to subscribe (via WebSocket or otherwise) to some data stream.
That is, for each data stream, there are 200-1000 subscribers.
If we take an understandable analogy, then this is like a server with quotes that are constantly changing, and thousands of applications that receive quotes from this server.
Question: how to make such a server? Is there something ready? I have never encountered such a number of connections, and in general, the task seems not difficult - I got a new number, sent it to 1000 connections, but there are doubts that it will work quickly.
Somewhere I read that Netty holds a huge number of creations without problems - is that so?
Answer the question
In order to leave comments, you need to log in
Yes, it's true about Netty. Only it is very low-level, it is better to take Spring WebFlux or Play Framework.
This is already akin to multicasts (iptv), where most of the load lies on the transport (switches) and not on the soft side.
Based on recent experience, I would suggest to raise several servers with Swoole (write in PHP and not Java) For example, 200k connections per each (with white IPs).
DNS round robin : One name points to multiple IPs and hopefully spreads connections evenly. Or hide behind a load balancer, but then each network interface will accept a smaller number of connections, no more than 65k in theory, less in practice.
Use Redis as a PubSub broker. From each server, subscribe to messages from Redis.
When a WebSocket client connects, its subscriptions are stored in the Memory Table of the server it connected to. Key$fd
connections, keep 1/0 for each of the 1000 channels in the columns, or simply list the channel numbers through a separator in a single string field.
When a message arrives (a new number in one of the subscriptions), loop through the table (all connections of this server) and send a message to those who have this subscription enabled.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question