使用 redis 水平缩放 socket.io [英] Horizontally scale socket.io with redis

查看:59
本文介绍了使用 redis 水平缩放 socket.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在创建一个水平可扩展的 socket.io 服务器,如下所示:

I currently am creating a horizontally scalable socket.io server which looks like the following:

                 LoadBalancer (nginx)

      Proxy1      Proxy2      Proxy3      Proxy{N}

 BackEnd1   BackEnd2   BackEnd3   BackEnd4   BackEnd{N}

我的问题是,使用 socket-io redis 模块,如果后端服务器都连接到同一个 redis 服务器,我是否可以向连接到其中一个代理服务器的特定套接字发送消息?如果是这样,我该怎么做?

My question is, with socket-io redis module, can I send a message to a specific socket connected to one of the proxy servers from one of the backend servers if they are all connected to the same redis server? If so, how do I do that?

推荐答案

当你想扩展 socket.io 服务器,并且你已经使用 nginx 作为负载均衡器时,不要忘记设置 sticky load balance,其他单连接会基于负载均衡器连接到多个服务器,将连接传递给socket.io服务器.所以最好使用粘性负载平衡

As you wan to scale socket.io server, and you have used nginx as load balancer, do not forget to setup sticky load balancing, othersie single connection will be connected to multiple server based on load balancer pass the connection to socket.io server. So better to use sticky load balancing

使用redis socket io适配器,您可以借助Redis Pub/Sub implementation与一个或多个socket.io服务器发送和接收消息.

With the redis socket io adapter, you can send and receive message with one or more socket.io server with help of Redis Pub/Sub implementation.

如果您告诉我代理和后端使用哪种技术,我会告诉您更多相关信息.

if you tell me which technology is used for Proxy and Backend, i will let you know more information on this.

这篇关于使用 redis 水平缩放 socket.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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