node-websocket-server: possible to have multiple, separate “broadcasts” for a single node.js process?

前端 未结 4 1224
野趣味
野趣味 2020-11-30 16:40

I\'d like to know if it\'s possible to broadcast on different websocket \"connections\" running from the same node-websocket-server app instance. Imagine a chatroom server w

4条回答
  •  野性不改
    2020-11-30 17:29

    Shripad K's answer is very well structured. Good job.

    I think that solution will have some scaling issues though.

    If you had 10,000 concurrent users in 500 chat rooms, then every time any user sent a message, you'd have to loop through all 10,000 clients. I suspect that it would be faster to store the list of clients in a given room in a structure in redis and just grab this list and send to those clients.

    1) Not sure if that's actually faster. 2) Not sure what could be stored in redis that would then allow us to reference clients. Maybe there could be a hash of all clients in the server, by a unique id and in redis, we could just store a set of the user id's per chat room?

    Does this seem any more scalable?

    I've written a node chat server based on fzysqr's and need to make it scalable for multiple chats before we roll it out widely.

提交回复
热议问题