Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling websocket node server

I know this question has been asked partially before (How to Scale Node.js WebSocket Redis Server?) but I am wondering if there is any alternatives to redis for rapidly sharing websocket objects between node instances, specifically ws type sockets (https://github.com/einaros/ws). I've tried redis and ran into issues with the fact that the web socket objects are cyclic and difficult to serialise. I then used Crockford's cycle.js (https://github.com/douglascrockford/JSON-js/blob/master/cycle.js), however it seems to strip out the websocket objects methods, as I get an error from node saying "Object object has no method send" after I have read the socket back from redis and retrocycled it. Any help would be much appreciated.

Thanks in advance, James.

like image 627
jamyspex Avatar asked Jan 01 '26 20:01

jamyspex


1 Answers

IMO you should use messaging queue for that.. e.g (RabbitMQ)

  1. Application starts on Node A and Node B and connects to RabbitMQ
  2. Client A connects to Node A and subscribe to Queue named XXX Client
  3. Client B connects to Node B and subscribe to Queue named XXX
  4. Client A sendsmessage to websocket server Websocket Server sends message to Node A
  5. Node A publishes messages to RabbitMQ queue XXX
  6. Node B receives the message from RabbitMQ as it is subscribed to queue XXX
  7. Node B sends message to Client B or publishes the messages to all connected clients on node B

So, all you need is to put Messaging queue in your architecture (RabbitMQ, ZeroMQ) etc

like image 121
Jack Daniel's Avatar answered Jan 03 '26 10:01

Jack Daniel's



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!