How to distribute socket.io

I'm using nodejs and socket.io to deliver chat in my business application, but I want to spread the deployment so that I have so many chat servers, I want to load balance the traffic.

I'm trying to pick up a load balancer from nginx, but I'm just balancing the traffic, but the communication between .io sockets is not the same for it, so a single chat message sent from user A to server S1 won't navigate to user B on server S2.

There is some tool or approach for this.

Thanks in advance.

===== EDIT =====

Here is the architecture of the application.

The main PHP application interface CodeIgniter allows you to mark it as PHPCI Chat application backend in NodeJs and SocketIO allows you to mark it as CHAT Chat model data on Redist allows you to mark it as REDIST

So, I now have it PHPCI -> CHAT -> REDIST. This works great.

I need to distribute an application so that I have as many PHPCI or CHAT or REDIST that I want, for example

 PHPCI1    CHAT1
 PHPCI2 ->       -> REDIST1
 PHPCI3    CHAT2

      

If the numbers represent instances of not different applications.

Thus, user A connected to PHPCI1 can send a message to user B connected to PHPCI3.

I think some queue in the middle of the CHAT can handle this something like rabbitmq which SocketIO can only use to deliver messages to the client.

+3


source to share


2 answers


If you are load balancing the server (and this is a requirement), I would suggest adding a dedicated chat data server (usually an in-memory database or message queue) to handle the chat state and pass messages across the edge servers.



Redis Pub / Sub is perfect for this purpose and can scale to insane levels even on a low-level machine. The Redis Cookbook has a chapter on exactly this use case.

+4


source


If you've configured your chat server-side correctly, you don't need to distribute socket.io. Since node.js is a browser and doesn't require any client code (other than resources loaded from a web page), it works automatically. On a webpage, the files needed to run socket.io are temporarily loaded by users when they are properly enabled (as with jQuery). If you are using node.js and socket.io to build an Android app, the files must be included in your app when you distribute it, not separately.



Also, if you want to use two separate socket.io servers, you must establish communication between them by connecting them in the same way as the client connects to the server, but with a special parameter that allows the other server to know that the server is connected and it can answer and set a variable for another server.

-1


source







All Articles