与标准网络服务器一起扩展解耦实时服务器 [英] Scaling a decoupled realtime server alongside a standard webserver

查看:61
本文介绍了与标准网络服务器一起扩展解耦实时服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个典型的 web 服务器,它为客户端提供标准的 HTML 页面,还有一个 websocket 服务器与它一起运行,用于实时更新(聊天、通知等).

Say I have a typical web server that serves standard HTML pages to clients, and a websocket server running alongside it used for realtime updates (chat, notifications, etc.).

我的一般工作流程是,当主服务器上发生触发实时消息需求的事件时,主服务器将该消息发送到实时服务器(通过消息队列),实时服务器将其分发到任何相关连接.

My general workflow is when something occurs on the main server that triggers the need for a realtime message, the main server sends that message to the realtime server (via a message queue) and the realtime server distributes it to any related connection.

我担心的是,如果我想扩大规模并添加另一个实时服务器,似乎我唯一的选择是:

My concern is, if I want to scale things up a bit, and add another realtime server, it seems my only options are:

  1. 让主服务器跟踪客户端的实时服务器连接到.当该客户收到通知/聊天时消息,主服务器只将该消息转发给客户端连接的实时服务器.这里的缺点是代码复杂,因为主服务器不得不做一些额外的书保持.
  2. 或者让主服务器简单地传递该消息与每个实时服务器一起;只有客户端是服务器连接到实际上会用它做任何事情.这会导致在许多浪费的消息被传递.

我在这里错过了另一个选择吗?我只是想确保我不会在其中一条道路上走得太远,并意识到我做的事情完全错误.

Am I missing another option here? I'm just trying to make sure I don't go too far down one of these paths and realize I'm doing things totally wrong.

推荐答案

如果场景是

a) 主 Web 服务器在执行操作时发出消息(假设插入了一条记录)b ) 他通知相应的实时服务器

a) The main web server raises a message upon an action (let's say a record is inserted) b ) He notifies the appropriate real-time server

您可以通过使用将消息转发到指定收件人的中间发布/订阅架构来分离这两个步骤.

you could decouple these two steps by using an intermediate pub/sub architecture that forwards the messages to the indended recipient.

一个实现是

1) 您有一个 redis pub-sub 频道,当客户端连接到实时套接字时,您开始在该频道中收听

1) You have a redis pub-sub channel where upon a client connecting to a real-time socket, you start listening in that channel

2) 当主应用程序想要通过实时服务器通知用户时,它会向频道推送一条消息,实时服务器获取并转发给目标用户.

2) When the main app wants to notify a user via the real-time server, it pushes to the channel a message, the real-time server get's it and forwards it to the intended user.

通过这种方式,您可以将实时通知与主应用程序分离,而不必跟踪用户的位置.

This way, you decouple the realtime notification from the main app and you don't have to keep track of where the user is.

这篇关于与标准网络服务器一起扩展解耦实时服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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