如何使房间具有可伸缩性的node.js服务器 [英] How to make a node.js server with rooms scalable

查看:59
本文介绍了如何使房间具有可伸缩性的node.js服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个Node.JS服务器,该服务器允许用户登录,加入会议室并使用Websocket与该会议室中的其他用户交换数据.但是,我现在正在寻找一种使此设置可扩展的方法.

I have designed a Node.JS server that allows users to log in, join a room and exchange data with other users in this room using websockets. However I am now looking for a way to make this setup scalable.

我整个下午都在研究各种负载均衡器,例如nginx和haproxy,但我仍然不知道如何组织我的设置.

I spend all afternoon researching various loadbalancers such as nginx and haproxy, but I still can't figure out how to organise my setup.

最初,用户可以登录并查看活动房间.毫不费力地使该部分具有可扩展性.但是,然后他们可以加入特定的会议室,这时它们需要与会议室中的其他实例连接到相同的node.js实例.这是我很难弄清楚的那部分.

Initally users can login and view the active rooms. No biggie to makes this part scalable. However then they can join a specific room and at that point they need to be connected to the same node.js instance as the others in the room. It's this part I have trouble figuring out.

目前,我的解决方案是创建两种不同类型的node.js实例.一种用于处理登录和房间概述请求方法的通用类型,一种用于处理多个房间的房间类型.然后,通用类型会跟踪哪个特定实例负责哪个房间,并可以将正确的地址传递给用户的应用程序.

For now my solution exists out of creating two different types of node.js instances. One generic type to handle the login and room overview request methods and one roomtype that handle a number of rooms. The generic type then keeps track of which specific instance is responsible for which room and can deliver the correct address to the user's application.

但是,我对这种解决方案不满意,因此我愿意征求建议.我知道这是一个相当模糊的问题,但是我并不是在寻找确切的解决方案,而是关于如何组织一切的暗示.

However I am not satisfied with this solution, so I am open for suggestions. I understand that this is a rather vague question, but I am not looking for a exact solution, rather hints as to how to organize everything.

推荐答案

udidu谈到了一个可能的解决方案,但是要进行扩展,您应该考虑一个可扩展的pub/sub解决方案. Redis ,一个流行的数据存储,内置了pub/sub ,我经常使用它来产生很大的效果.

udidu touched on a possible solution, but to expand, you should look at a scalable pub/sub solution; Redis, a popular data store, has pub/sub built in and I use it often to great effect.

使用Redis(或其他系统)来确保您的Node.js应用程序的每个实例都收到有关谁在哪个房间聊天的信息,从而消除了房间中所有用户都连接到同一Node.js实例的依赖性.

Using Redis (or some other system) to help make sure every instance of your Node.js app receives information about who's chatting in which room removes the dependency that all users in a room are connected to the same Node.js instance.

Redis聊天>

这篇关于如何使房间具有可伸缩性的node.js服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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