简体   繁体   English

如何扩展Node.js WebSocket Redis服务器?

[英]How to Scale Node.js WebSocket Redis Server?

I'm writing a chat server for Acani , and I have some questions about Scaling node.js and websockets with load balancer scalability . 我正在为Acani编写一个聊天服务器,我有一些关于Scaling node.jswebsockets以及负载均衡器可扩展性的问题

  1. What exactly does it mean to load balance Node.js? Node.js负载均衡到底意味着什么? Does that mean there will be n independent versions of my server application running, each on a separate server? 这是否意味着我的服务器应用程序将运行n个独立版本,每个版本都在一个单独的服务器上?

  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. 为了允许一个客户端向所有其他客户端广播消息,我存储了一组在服务器上打开的所有webSocketConnections 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 ? 但是,如果我有我的服务器应用程序运行的n个独立版本,每一个单独的服务器上,然后将我有n个不同的组webSocketConnections

  3. If the answers to 1 & 2 are affirmative, then how do I store a universal set of webSocketConnections (across all servers)? 如果1和2的答案是肯定的,那么如何存储一组通用的webSocketConnections (跨所有服务器)? One way I think I could do this is use Redis Pub/Sub and just have every webSocketConnection subscribe to a channel on Redis. 我认为我可以这样做的一种方法是使用Redis Pub / Sub,并让每个webSocketConnection订阅Redis上的频道。

  4. But, then, won't the single Redis server become the bottleneck? 但是,那么,单个Redis服务器不会成为瓶颈吗? How would I then scale Redis? 然后我如何缩放Redis? What does it even mean to scale Redis? 扩展Redis甚至意味着什么? Does that mean I have m independent versions of Redis running on different servers? 这是否意味着我有m个不同的服务器上运行的Redis的独立版本? Is that even possible? 这甚至可能吗?

  5. I heard Redis doesn't scale. 我听说Redis没有扩展。 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? 如果这是真的,对于pub / sub和/或存储所有广播消息的列表是否有更好的解决方案?

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. 注意:如果你的回答是Acani永远不必扩展,即使地球上所有70亿人(并且正在增长)中的每一个人每秒向地球上的其他人广播一条消息,那么请给出有效的解释。

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. 要对Node.js进行负载均衡,这意味着你对它的看法正是如此,除了你真的不需要单独的服务器之外,你可以在同一台机器上运行多个节点服务器进程。

  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. 节点服务器的每个服务器/进程都有自己的连接,websockets的默认存储(例如Socket.IO)是MemoryStore,这意味着所有连接都将存储在机器内存中,需要与RedisStore一起使用为了使用redis作为连接存储。

  3. Redis PUB/SUB is a good way to achieve this task Redis PUB / SUB是实现此任务的好方法

  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. 你对这里说的是正确的,redis在这个时刻不会扩展,并且运行许多连接到redis的进程/连接会使redis成为瓶颈。

  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 ) Redis没有扩展,这是正确的,但根据这个演示文稿,您可以看到集群开发在redis中处于首要位置,redis确实有一个集群,它还不稳定:(取自http:// redis。 io /下载

Where's Redis Cluster? Redis集群在哪里?

Redis development is currently focused on Redis 2.6 that will bring you support for Lua scripting and many other improvements. Redis开发目前专注于Redis 2.6,它将为您提供对Lua脚本和许多其他改进的支持。 This is our current priority, however the unstable branch already contains most of the fundamental parts of Redis Cluster. 这是我们当前的优先级,但不稳定分支已经包含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. 在2.6发布之后,我们将集中精力将当前的Redis Cluster alpha转换为用户可以开始认真测试的beta产品。 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. 很难做出预测,因为只有当我们认为Redis Cluster坚如磐石且对我们的客户有用时,我们才会发布Redis Cluster,但我们希望在2012年夏季能够获得合理的测试版,并在发布之前发布第一个稳定版本。 2012年底。

See the presentation here: http://redis.io/presentation/Redis_Cluster.pdf 请参阅此处的演示文稿: http//redis.io/presentation/Redis_Cluster.pdf

2) Using Redis might not work to store connections: Redis can store data in string format, and if the connecion object has circular references (ie, Engine.IO) you won't be able serialise them 2)使用Redis可能无法存储连接:Redis可以以字符串格式存储数据,如果连接对象具有循环引用(即Engine.IO),您将无法将它们序列化

3) Creating a new Redis client for each client might not be a good approach so avoid that trap if you can 3)为每个客户端创建一个新的Redis客户端可能不是一个好方法,所以如果可以,请避免使用该陷阱

Consider using ZMQ node library to have processes communicate with each other through TCP (or IPC if they are clustered as in master-worker) 考虑使用ZMQ节点库让进程通过TCP(或IPC,如果它们像在master-worker中一样聚集)相互通信

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM