简体   繁体   English

Node.js“网络”连接负载平衡

[英]Node.js “net” connections load balancing

I am researching Node.js net library's potential to implement a chat server. 我正在研究Node.js网络库实现聊天服务器的潜力。 I am very much new to node.js. 我对node.js非常陌生。 I was wondering how client connections to net TCP server can be load balanced across multiple servers (to handle a large load) and a message can be sent to all connections across the servers. 我想知道如何在多个服务器之间平衡客户端到Net TCP服务器的连接(以处理较大的负载),以及如何将消息发送到服务器之间的所有连接。 Are there any servers available which can help with this? 是否有可用的服务器可以帮助您解决此问题? or should I look into socket.io or other libraries for the implementation? 还是应该研究socket.io或其他库来实现?

I came across a similar problem when developing Mote.io and decided to go with a hosted solution instead of building a load balancer. 在开发Mote.io时遇到了类似的问题, 因此决定采用托管解决方案而不是构建负载平衡器。 Dealing with this problem is pretty difficult as you need to sync data across servers or load balance your clients to the same instance to make sure they get all the same messages. 解决此问题非常困难,因为您需要跨服务器同步数据或将客户端负载平衡到同一实例,以确保它们获得所有相同的消息。

Socket.io won't help much specifically. Socket.io并不会有多大帮助。 You would need to implement redis, some other data sync or load balancing app. 您将需要实现redis,其他一些数据同步或负载平衡应用程序。

PubNub will take care of this as well. PubNub也将解决此问题。 The backend is responsible for syncing messages, load balancing, etc at an abstract level so all you do is supply a channel name and PubNub will ensure that all clients in that channel get the message. 后端负责在抽象级别上同步消息,负载平衡等,因此您要做的就是提供一个通道名,PubNub将确保该通道中的所有客户端都收到消息。

Real-time Chat Apps in 10 Lines of Code 10行代码的实时聊天应用

在此处输入图片说明

Enter Chat and press enter
<div><input id=input placeholder=you-chat-here /></div>

Chat Output
<div id=box></div>

<script src=http://cdn.pubnub.com/pubnub.min.js></script>
<script>(function(){
var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chat';
PUBNUB.subscribe({
    channel  : channel,
    callback : function(text) { box.innerHTML = (''+text).replace( /[<>]/g, '' ) + '<br>' + box.innerHTML }
});
PUBNUB.bind( 'keyup', input, function(e) {
    (e.keyCode || e.charCode) === 13 && PUBNUB.publish({
        channel : channel, message : input.value, x : (input.value='')
    })
} )
})()</script>

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

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