I have been reading many blogs about Socket.IO these days and impressed by features of it. I am planning to use it one of chat applications and for normal number of users with minimal number of users it is working perfectly. But are there any pitfalls in Socket.IO when used in production networks? Is Socket.IO best fit for large scale messaging system where messaging flow will be very huge. If yes, what is the best technology stack to be used along Socket.IO to make it work "100% reliable even when load is more". Anyone have already have an experience with Socket.IO in implementing large scale messaging system. Stack I want to use is Socket.IO, Redis, Cassandra and MySQL.
这些天我一直在阅读很多关于Socket.IO的博客,并对它的功能印象深刻。我计划将其中一个聊天应用程序用于正常数量的用户,并且用户数量最少,而且工作正常。但是在生产网络中使用Socket.IO时是否存在任何陷阱? Socket.IO最适合大规模消息传递系统,其中消息流将非常庞大。如果是,那么沿着Socket.IO使用的最佳技术堆栈是什么,使其“即使负载更多也能100%可靠”。任何人都已经有过使用Socket.IO实现大规模消息传递系统的经验。我想使用的堆栈是Socket.IO,Redis,Cassandra和MySQL。
As of now I have gone through many examples of Socket.IO and many people were trying to do in different ways. Some people used Array to store Socket ids while some using Redis. I understand that using Redis will help definitely. But I do not want to stop there. I would like to learn best architecture for Socket.IO application.
截至目前,我已经经历了许多Socket.IO的例子,很多人都试图以不同的方式做。有些人使用Array来存储Socket ID,而有些则使用Redis。我知道使用Redis肯定会有所帮助。但我不想止步于此。我想学习Socket.IO应用程序的最佳架构。
Please suggest me a path to it.
请建议我走一条路。
Edit
For me best stack is nothing but, something for which rate of failure is less compared to others.
对我而言,最好的堆栈只不过是,与其他人相比,失败率较低的东西。
1 个解决方案
#1
11
You first need to understand that Socket.IO is merely an abstraction, and a very elegant one at that, for the WebSocket protocol. Being that it enjoys incredible support, the protocol itself is probably the best choice you can make today when you need two-way communication between your server and your clients across public networks, so you are definitely on the right track.
首先需要了解的是,对于WebSocket协议,Socket.IO只是一个抽象,而且非常优雅。由于它拥有令人难以置信的支持,当您需要在服务器和客户之间通过公共网络进行双向通信时,协议本身可能是您今天可以做出的最佳选择,因此您肯定是在正确的轨道上。
The resources required to operate a Socket.IO server mainly revolve around the total amount of connections and the data being transferred across at any given point in time. With that said, a Socket.IO server is bound to network I/O and will scale to as many clients your networking hardware can handle.
操作Socket.IO服务器所需的资源主要围绕连接总量和在任何给定时间点传输的数据。话虽如此,Socket.IO服务器绑定到网络I / O,并将扩展到您的网络硬件可以处理的客户端数量。
Whats worth taking into account is the fact that Socket.IO is built on top of asynchronous networking libraries. Blocking I/O from other services is deferred, enabling the server to continue handling other communication. The memory footprint usually contains the in-memory representation of the connections and the immediate data being transferred--even though one client may be relaying megabytes of data to other clients, it will stream the data in discrete chunks and as soon as one chunk is transmitted successfully to all parties the resources are immediately released.
值得考虑的是Socket.IO是建立在异步网络库之上的。延迟阻止来自其他服务的I / O,使服务器能够继续处理其他通信。内存占用通常包含连接的内存中表示和正在传输的即时数据 - 即使一个客户端可能正在将兆字节的数据中继到其他客户端,它也会以离散块的形式流式传输数据,并且只要一个块就是成功传输给所有各方,资源立即释放。
Of course, even when managing straightforward communication, like chat messages between multiple users across multiple rooms, it's impossible to be able to scale to the size of, say, Freenode, which can have hundreds of thousands of users in thousands of rooms, with just a single server.
当然,即使在管理简单的通信时,例如跨多个房间的多个用户之间的聊天消息,也不可能扩展到Freenode的大小,Freenode可以在数千个房间中拥有数十万用户,而且只是一台服务器。
This is where services like Redis come in to play, where you can use a highly available central storage for some intermediary, representative connection data to scale horizontally by seamlessly distributing clients across several Socket.IO instances.
这就是Redis等服务的用武之地,您可以使用高可用性的*存储来为一些中间代表连接数据进行水平扩展,通过在多个Socket.IO实例之间无缝分配客户端。
You can get to 99%+ reliability today, by using stacks like CoreOS to describe each distinct parts of your architecture as units which can be distributed across available hardware, introducing new instances as the load increases, services like etcd for discovery when these come on or suddenly go dark, and distributed WebSocket proxies like hipache to keep all of your Socket.IO instances saturated, but never allowing any to exhaust all of it's available resources.
今天你可以通过使用像CoreOS这样的堆栈将架构的每个不同部分描述为可以分布在可用硬件上的单元,在负载增加时引入新实例,像etcd这样的服务,以便在发现这些时发现或突然变暗,并分发像hipache这样的WebSocket代理,以保持所有Socket.IO实例饱和,但绝不允许任何人耗尽所有可用资源。
#1
11
You first need to understand that Socket.IO is merely an abstraction, and a very elegant one at that, for the WebSocket protocol. Being that it enjoys incredible support, the protocol itself is probably the best choice you can make today when you need two-way communication between your server and your clients across public networks, so you are definitely on the right track.
首先需要了解的是,对于WebSocket协议,Socket.IO只是一个抽象,而且非常优雅。由于它拥有令人难以置信的支持,当您需要在服务器和客户之间通过公共网络进行双向通信时,协议本身可能是您今天可以做出的最佳选择,因此您肯定是在正确的轨道上。
The resources required to operate a Socket.IO server mainly revolve around the total amount of connections and the data being transferred across at any given point in time. With that said, a Socket.IO server is bound to network I/O and will scale to as many clients your networking hardware can handle.
操作Socket.IO服务器所需的资源主要围绕连接总量和在任何给定时间点传输的数据。话虽如此,Socket.IO服务器绑定到网络I / O,并将扩展到您的网络硬件可以处理的客户端数量。
Whats worth taking into account is the fact that Socket.IO is built on top of asynchronous networking libraries. Blocking I/O from other services is deferred, enabling the server to continue handling other communication. The memory footprint usually contains the in-memory representation of the connections and the immediate data being transferred--even though one client may be relaying megabytes of data to other clients, it will stream the data in discrete chunks and as soon as one chunk is transmitted successfully to all parties the resources are immediately released.
值得考虑的是Socket.IO是建立在异步网络库之上的。延迟阻止来自其他服务的I / O,使服务器能够继续处理其他通信。内存占用通常包含连接的内存中表示和正在传输的即时数据 - 即使一个客户端可能正在将兆字节的数据中继到其他客户端,它也会以离散块的形式流式传输数据,并且只要一个块就是成功传输给所有各方,资源立即释放。
Of course, even when managing straightforward communication, like chat messages between multiple users across multiple rooms, it's impossible to be able to scale to the size of, say, Freenode, which can have hundreds of thousands of users in thousands of rooms, with just a single server.
当然,即使在管理简单的通信时,例如跨多个房间的多个用户之间的聊天消息,也不可能扩展到Freenode的大小,Freenode可以在数千个房间中拥有数十万用户,而且只是一台服务器。
This is where services like Redis come in to play, where you can use a highly available central storage for some intermediary, representative connection data to scale horizontally by seamlessly distributing clients across several Socket.IO instances.
这就是Redis等服务的用武之地,您可以使用高可用性的*存储来为一些中间代表连接数据进行水平扩展,通过在多个Socket.IO实例之间无缝分配客户端。
You can get to 99%+ reliability today, by using stacks like CoreOS to describe each distinct parts of your architecture as units which can be distributed across available hardware, introducing new instances as the load increases, services like etcd for discovery when these come on or suddenly go dark, and distributed WebSocket proxies like hipache to keep all of your Socket.IO instances saturated, but never allowing any to exhaust all of it's available resources.
今天你可以通过使用像CoreOS这样的堆栈将架构的每个不同部分描述为可以分布在可用硬件上的单元,在负载增加时引入新实例,像etcd这样的服务,以便在发现这些时发现或突然变暗,并分发像hipache这样的WebSocket代理,以保持所有Socket.IO实例饱和,但绝不允许任何人耗尽所有可用资源。