Store multiple servers

I am using Ratchet ( http://socketo.me/ ) for websites in my PHP application. I have several virtual machines running the application, and websocket service is also hosted on each of these machines. Requests are sent to one of these virtual machines through HAProxy. Also currently the user uses the websocket service on the same node that he connects for the application.

Now I have a problem with websocket servers discussing with each other. For instance:

  • user1 connects to node1, and user2 connects to node2
  • User1 sends websocket via websocket to user2
  • User2 never receives this message because it is connected to another node

What are some good messaging practices? I have some ideas, but don’t know how to go:

  • Each client connects to each websocket node.
  • Servers also publish messages to all other nodes.
  • Use a database to synchronize messages between nodes.

Both the first and second options are not very scalable if the new nodes are tied to the cloud. Option 3 will cause some lag, because you need to check whether messages from other nodes are in the database in a loop.

Are there any other options for handling such situations? Thanks for answers!

+4
source share
1 answer

Just a few notes to point people in one possible direction:

  • Redis , - rpush, llen, lrange. .
  • onMessage, Redis. , .
  • , Ratchet , , Redis .
0

All Articles