实现可扩展聊天服务器的策略 [英] Strategy to implement a scalable chat server

查看:33
本文介绍了实现可扩展聊天服务器的策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望实现某种聊天服务器.我希望它可以扩展.这似乎是一个大问题,所以我想我希望答案是方向指针,有点探索性.

I am looking to implement some sort of chat server. And I want it to scale. This seems like a big question, so I guess I expect the answers to be direction pointers, sort of exploratory.

最终用户客户端是网络或电话客户端.我认为某种 websocket 实现,例如 Socket.IO 很好.

The end-user clients are web or phone client. I think some sort of websocket implementation, such as Socket.IO is nice.

在服务器端,我希望使用 Node.js.我希望架构是可扩展的,以便用户数量不受限制(好吧,在合理范围内,预计不会有大的机会,如果是,则有更聪明、有经验的人来工作的机会是合理的而不是目前只有我在编码)希望每个聊天室的用户数量不受限制,或者可能是固定的大量用户.这意味着我需要使用多个用 Node 编写的服务器进行水平扩展.

On the server side I wish to use Node.js. I want the architecture to be scalable so that the number of users are not limited (well, within reason, the chance of big hit is not expected, and if it is, the chance of having smarter, experienced people to work on it is reasonable instead of currently just me coding) The number of users per chatroom is hopefully not limited, or maybe some fixed large number. And that means I need to scale horizontally using several servers written in Node.

假设某个负载均衡器(希望将来不会出现单点故障,但我不知道如何实现这一点,或者只是转移到 AWS)正在将 SocketIO 连接从终端客户端分派到聊天室服务器.不同的用户连接到不同的服务器可能在同一个房间,所以消息需要发送到其他服务器.

Suppose some load balancer (and hopefully in the future not a single point of failure, but I don't know how I would achieve that, or maybe just move to AWS) are dispatching SocketIO connections from the end clients to the chat servers. Different users connection to different servers may be in the same room, so the messages need to be send to other servers.

我如何切实可行地实现这样的事情?希望不要太复杂.

How would I feasibly implement something like this? Hopefully not too complex.

问题:(1) 如果所有服务器都需要处理所有消息,因为用户可以通过任何服务器登录,这是否可以扩展?(2) 服务器之间是否需要某种消息队列才能进行通信?Rabbitmq 的 Pub-sub 是否可用于此?或者如果是 zeromq,我将如何使用 pub sub 进行扩展?Zeromq 指南解释了如何使用 REQ/REP 类型的应用程序扩展到多个服务器.但不是 Pub Sub.(3) 还是应该从XMPP开始?

Questions: (1) If all servers need to handle all messages as users can be logged on via any of the servers, does this scale? (2) Do I need some sort of message queue for the servers to talk among them? Is Pub-sub from Rabbitmq usable for this? Or if zeromq, how would I scale with pub sub? The Zeromq guide is has explanations for scaling to more than one server with REQ/REP type of applications. But not Pub Sub. (3) Or should I start with XMPP?

我希望让它尽可能简单.

I am hoping to make it work as easy as possible.

推荐答案

Socket.io 站点上有一个很好的解释.看看

There's a rather good explanation at the Socket.io site. Have a look at

建议使用 Nginx 作为 HTTP 负载均衡器,使用 Node.js 集群(使用粘性会话),使用 Redis 作为消息后端.

It suggests using Nginx as HTTP load balancer, Node.js clustering (with sticky sessions) and Redis as the message backend.

我认为你的目标应该是可以实现的,几乎不需要编码,只需要使用给定的模块和配置机制.

I think your goals should be achievable with little to none coding involved, only using the given modules and configuration mechanisms.

这篇关于实现可扩展聊天服务器的策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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