A large number of WebSocket connections

I am writing an application that tracks content that is being moved between users of a specific task. I mean using WebSockets to send new content, as they are available to all users who are currently using the application for this task.

I am writing this on Rails, and the client application is on iOS (it will probably also be on Android). I am afraid that this WebSocket solution will not scale well. I am after some tips and things to consider when deciding to go with WebSockets against some kind of polling solution.

Will a Ruby on Rails server (e.g. Heroku) support a large number of WebSockets at the same time? Say a million bonds for the sake of argument. Any stuff that can provide me with such things?

Will it cost a lot more on the server if I create it?

Can millions of WebSockets be supported at the same time? I feel that this may not be the best design decision.

This is my first attempt at a proper Rails API. Any advice is much appreciated. thanks.

+4
source share
2 answers

A million connections through WebSockets, using Ruby, I do not see it real unless you use clustering to distribute connections between different instances to handle all data processing.
The problem here is serialization and deserialization of data.

You also need to research how often you will need to pull data to the client from the server, and if you only use periodic checks using AJAX, then process the connection all the time. Because if you are processing a connection and then you are not using it, it is a waste of resources. WebSockets are built on top of the TCP level, and all connections are not "cheap", and also pass through the OS and require data retransmission, this is not an easy process, with millions of connections it is almost impossible without using the most advanced technologies in the world.

I believe Erlang is capable of handling millions of connections, but I have no details. In addition, a connection is one thing, the other is data processing and the interaction between connections - you might want to check this out, because if you have complex processing algorithms, you definitely need to look at horizontal scaling options for clustering solutions.

+2
source
  • If you use chat, use websockets.
  • If you are implementing single-user messages in real time, use the server that sent the events.
  • If you are running single-user messages sent every few hours or so, use APNS.

The proverb goes on the phone in his hand, uses events related to servers / servers. Phone in your pocket, use APNS.

APNS will ease wifi failures, tcp / ip hangs and many other problems. Really helpful. It is likely that a little time may pass for the passage. But then again, there is a chance that websockets will take

Recent versions of iOS allow you to send APNS to a client without a pop-up message to the client so that it can request additional information from the server. This, together with some background implementations, really improves the situation.

If possible, do not implement fully anonymous clients. It is very difficult to determine if the client will reinstall the application. That way you end up sending duplicates to the client. This must be considered.

APNS looks trivial to implement in ruby, but I suggest avoiding desire and am going to use an existing gem / service that supports both Google and Apple. This is much more complicated than it might seem at first glance.

If you decide to stick with web maps, it might make sense to just use websockets in nginx, like https://github.com/wandenberg/nginx-push-stream-module

ASIDE: Using SMS, where speed is critical, is very expensive. $ 1 / month only sends a maximum speed of 1 message per second to a phone number. Thus, sending 100 messages per second = $ 100 / month plus message fee. Please note that 100 messages at a speed of 50 messages per second = $ 50 per month. But if you want to send 1k messages, it will take 20 seconds.

Good luck.

+1
source

Source: https://habr.com/ru/post/1412465/


All Articles