如何扩展 Node.js WebSocket Redis 服务器? [英] How to Scale Node.js WebSocket Redis Server?

查看:22
本文介绍了如何扩展 Node.js WebSocket Redis 服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Acani 编写一个聊天服务器,我有一些关于 缩放 node.js具有负载均衡器可扩展性的 websockets.

  1. 负载均衡 Node.js 究竟意味着什么?这是否意味着我的服务器应用程序将运行 n 个独立版本,每个版本都在单独的服务器上?

  2. 为了允许一个客户端向所有其他客户端广播消息,我存储了一组在服务器上打开的所有 webSocketConnections.但是,如果我有 n 个独立版本的服务器应用程序运行,每个版本都在单独的服务器上,那么我将有 n 组不同的 webSocketConnections?

  3. 如果答案为 1 &2 是肯定的,那么我如何存储一个通用的 webSocketConnections 集(跨所有服务器)?我认为可以做到这一点的一种方法是使用 Redis Pub/Sub 并让每个 webSocketConnection 订阅 Redis 上的一个频道.

  4. 但是,那么,单个Redis服务器会不会成为瓶颈?那么我将如何扩展Redis?扩展Redis意味着什么?这是否意味着我有 m 个独立版本的 Redis 运行在不同的服务器上?这可能吗?

  5. 我听说 Redis 无法扩展.为什么会有人这么说.这意味着什么?如果是这样,是否有更好的解决方案来发布/订阅和/或存储所有广播消息的列表?

注意:如果您的答案是 Acani 永远不需要扩展,即使地球上所有 70 亿人(并且还在不断增长)中的每一个每秒都向地球上的其他人广播一条消息,那么请给出有效的解释.

解决方案

嗯,你的问题很少有答案:

  1. 为了负载均衡Node.js,它的意思就是你想的那样,除了你真的不需要单独的服务器,你可以在同一台机器上运行多个节点服务器的进程.

  2. 节点服务器的每个服务器/进程都有自己的连接,websockets(例如Socket.IO)的默认存储是MemoryStore,这意味着所有连接都将存储在机器内存中,它需要使用 RedisStore 才能使用 redis 作为连接存储.

  3. Redis PUB/SUB 是实现这个任务的好方法

  4. 您在这里说的没错,redis 目前无法扩展,并且运行大量连接到 redis 的进程/连接会使 redis 成为瓶颈.

  5. Redis 无法扩展,这是正确的,但根据本演示文稿,您可以看到集群开发在 redis 中是重中之重,而 redis 确实有一个集群,只是还不稳定:(取自http://redis.io/download)

<块引用>

Redis 集群在哪里?

Redis 开发目前专注于 Redis 2.6,它将为您带来对 Lua 脚本的支持和许多其他改进.这是我们当前的优先事项,但是不稳定分支已经包含了 Redis 集群的大部分基础部分.在 2.6 版本发布之后,我们将把精力集中在将当前的 Redis Cluster alpha 转变为用户可以开始认真测试的 beta 产品.很难做出预测,因为只有当我们认为 Redis Cluster 对我们的客户非常可靠和有用时,我们才会将其发布为稳定版,但我们希望在 2012 年夏季有一个合理的测试版,并在 2012 年之前发布第一个稳定版2012 年底.

在此处查看演示:http://redis.io/presentation/Redis_Cluster.pdf

I'm writing a chat server for Acani, and I have some questions about Scaling node.js and websockets with load balancer scalability.

  1. What exactly does it mean to load balance Node.js? Does that mean there will be n independent versions of my server application running, each on a separate server?

  2. To allow one client to broadcast a message to all the others, I store a set of all the webSocketConnections opened on the server. But, if I have n independent versions of my server application running, each on a separate server, then will I have n different sets of webSocketConnections?

  3. If the answers to 1 & 2 are affirmative, then how do I store a universal set of webSocketConnections (across all servers)? One way I think I could do this is use Redis Pub/Sub and just have every webSocketConnection subscribe to a channel on Redis.

  4. But, then, won't the single Redis server become the bottleneck? How would I then scale Redis? What does it even mean to scale Redis? Does that mean I have m independent versions of Redis running on different servers? Is that even possible?

  5. I heard Redis doesn't scale. Why would someone say that. What does that mean? If that's true, is there a better solution to for pub/sub and/or storing a list of all broadcasted messages?

Note: If your answer is that Acani would never have to scale, even if each of all seven billion people (and growing) on Earth were to broadcast a message every second to everyone else on earth, then please give a valid explanation.

解决方案

Well, few answers for your question:

  1. To load balance Node.js, it means exactly what you thought about what it is, except that you don't really need separate server, you can run more then one process of your node server on the same machine.

  2. Each server/process of your node server will have it's own connections, the default store for websockets (for example Socket.IO) is MemoryStore, it means that all the connections will be stored on the machine memory, it is required to work with RedisStore in order to work with redis as a connection store.

  3. Redis PUB/SUB is a good way to achieve this task

  4. You are right about what you said here, redis doesn't scale at this moment and running a lot of processes/connections connected to redis can make redis to be a bottleneck.

  5. Redis doesn't scale, that is correct, but according to this presentation you can see that a cluster development is in top priority at redis and redis do have a cluster, it's just not stable yet: (taken from http://redis.io/download)

Where's Redis Cluster?

Redis development is currently focused on Redis 2.6 that will bring you support for Lua scripting and many other improvements. This is our current priority, however the unstable branch already contains most of the fundamental parts of Redis Cluster. After the 2.6 release we'll focus our energies on turning the current Redis Cluster alpha in a beta product that users can start to seriously test. It is hard to make forecasts since we'll release Redis Cluster as stable only when we feel it is rock solid and useful for our customers, but we hope to have a reasonable beta for summer 2012, and to ship the first stable release before the end of 2012.

See the presentation here: http://redis.io/presentation/Redis_Cluster.pdf

这篇关于如何扩展 Node.js WebSocket Redis 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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