简体   繁体   English

具有AWS负载平衡的Node.js

[英]Node.js with AWS Load Balancing

I'm just about to build a chat application and I'm keen to use node.js (would be my first time using it). 我将要构建一个聊天应用程序,并且我热衷于使用node.js(这是我第一次使用它)。

I'm using Amazon ELB (no stickyness) with Multiple Linux EC2 instances (apache) and one mysql database. 我正在将Amazon ELB(不发粘)与多个Linux EC2实例(apache)和一个mysql数据库一起使用。

I have 3 questions: 我有3个问题:

  1. AWS ELB - are there any issues running node.js through an AWS Load Balancer - I've read a touch about others having issues but nothing that really said whether it could be done successfully or not. AWS ELB-通过AWS Load Balancer运行node.js是否有任何问题-我读过一些有关其他问题的信息,但并没有真正说明它能否成功完成。

  2. Can Node.js efficently listern to database tables for updates and then respond to these? Node.js可以有效地侦听数据库表以进行更新,然后对其进行响应吗? Is this realistic? 这是现实的吗? I've read its possible but it didn't sound like its a well used function. 我已经读过它的可能,但听起来不像它的一个好用的功能。

  3. I understand node.js does event listening (like jquery). 我了解node.js会监听事件(例如jquery)。 I'm concerned if I have several seperate webservers all running node.js that they will all respond to the same events. 我担心是否有几个单独的网络服务器都运行node.js,它们都将响应相同的事件。 eg: some write some chat into the DB and they all web servers try to send this to the client. 例如:有些人将一些聊天记录写入数据库,而所有Web服务器都尝试将其发送给客户端。 (this would be an issue with long polling as one web server would get the request and reply). (这将是长时间轮询的问题,因为一个Web服务器将获得请求并进行回复)。 Is this an issues? 这有问题吗?

thankyou 谢谢

to answer 1 + 3 (cant tell about 2): 回答1 + 3(不能说2):

  1. we are using aws elb's for more than a year now, and never had any issues. 我们使用aws elb已有一年多了,从来没有任何问题。 our application needs an uptime close to 100% 我们的应用程序需要接近100%的正常运行时间

  2. node.js eventing is for events in the SAME process (unless you use a messaging-solution like axon ). node.js事件是针对SAME流程中的事件的(除非您使用像axon这样的消息传递解决方案)。 so this never should be an issue, even if you run multiple webservers. 因此,即使您运行多个Web服务器,也永远不会成为问题。 start your server listening on the some port, and the load-balancer will distribute the request to any server bound to the elb. 启动服务器在某个端口上侦听,负载均衡器会将请求分发到绑定到elb的任何服务器。

a request/response-cycle itself is atomic, which means that the same server that gets the request has to send the response when he is done with his work for this request (write the chat into the db). 请求/响应周期本身是原子的,这意味着获得请求的同一服务器必须在完成该请求的工作后发送响应(将聊天记录写入数据库)。 your code basically will look something like this: 您的代码基本上看起来像这样:

http.createServer(function (request, response) {
   // do something with the request, save to db or whatever
   db.save ...

   // and now send the response

   response.write(200);
   response.end();
});

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

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