Node: Scale socket.io / nowjs - scale across different instances

后端 未结 3 1623
一整个雨季
一整个雨季 2021-02-20 05:12

Before starting to write my application I need to know what to do when a single node.js instance (express and (socket.io or nowjs)) isn\'t enough anymore.

You might tell

3条回答
  •  余生分开走
    2021-02-20 05:54

    If you need to scale node, the first place people usually start is putting a load balancer in front of multiple node instances. The standard for this today is nginx, though I would would like to check out the node balancer 'bouncy' that came out recently. Here's an example of someone using the nginx reverse proxy to manage multiple node instances:

    Node.js + Nginx - What now?

    The second thing you mention is socket.io/nowjs. Depending on how you're using these frameworks, you could get into a situation where you want to share context between clients who are hitting multiple node.js instances. If this is the case, I would recommend using a persistent store, like redis, to bridge the gap between your node instances. Here's an example:

    How to reuse redis connection in socket.io?

    Hopefully this is enough information and reading to get you started, let me know if you have any questions.

    Happy coding!

提交回复
热议问题