strongloop 主管如何处理 websocket 连接? [英] how does strongloop supervisor handle websocket connections?

查看:37
本文介绍了strongloop 主管如何处理 websocket 连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个节点应用程序,我使用 WebSockets 从浏览器连接到该应用程序.

I have a node app that I connect to from a browser using WebSockets.

如果我在主管 (slc run --cluster cpu myapp.js) 下运行这个应用程序,一旦建立 websocket 连接是否总是转发到同一个工作人员?或者,当转发消息发送到这个连接时,主管会做某种负载平衡吗?

If I run this app under a supervisor (slc run --cluster cpu myapp.js), will a websocket connection be always forwarded to the same worker once established? Or will the supervisor do some sort of load balancing when forwarding messages send to this connection?

推荐答案

strong-supervisor 本身绝对不做负载平衡或集群:它自动启动和配置节点集群 (http://nodejs.org/api/cluster.html)

strong-supervisor does absolutely no load balancing or clustering on its own: it auto-starts and configures node cluster (http://nodejs.org/api/cluster.html)

节点集群在 TCP 级别分配连接,它对运行在它们上面的协议一无所知.

Node cluster distributes connections at the TCP level, it knows nothing about the protocols running over them.

使用 websockets 时,您有两种选择,使用 nginx 或其他支持 websocket 的负载均衡器,或者不要假设 websocket 和 http 连接具有进程关联性,并将共享状态保持在进程之外,可能是数据库.

When using websockets, you have two choices, use nginx or another load balancer that is websocket aware, or don't assume websocket and http connections have process affinity, and keep shared state out of process, probably a database.

如果使用 socket.io,请查看 https://github.com/automattic/socket.io-redishttps://github.com/strongloop/strong-cluster-socket.io-store

If using socket.io, look at https://github.com/automattic/socket.io-redis and https://github.com/strongloop/strong-cluster-socket.io-store

这篇关于strongloop 主管如何处理 websocket 连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆