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

后端 未结 3 1646
一整个雨季
一整个雨季 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!

    0 讨论(0)
  • 2021-02-20 05:57

    Another useful link on 'Scaling Socket.IO' https://github.com/dshaw/talks/tree/master/2011-10-jsclub (slides and sample application)

    0 讨论(0)
  • 2021-02-20 06:10

    Just as a sidenote on the discussion to use nginx for reverse proxy with socket.io, the way I understand it at least, nginx 1.0.x which is stable version does not support proxying of http/1.1 connections (which is needed in order to make socket.io work with websockets). there is a workaround described on here: http://www.letseehere.com/reverse-proxy-web-sockets to make it work, or use something like this: https://github.com/nodejitsu/node-http-proxy instead, the guys at nodejitsu says this should support it.

    0 讨论(0)
提交回复
热议问题