与php/ruby​​/etc + nginx相比,使用node.js +节点http服务器有什么优势? [英] what's advantages on using node.js+ node http server over php/ruby/etc + nginx?

查看:94
本文介绍了与php/ruby​​/etc + nginx相比,使用node.js +节点http服务器有什么优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多文档都说node.js http服务器的主要优点是事件化的io体系结构,但是Nginx也事件化了io,因此,使用node.js + node http服务器超过php或其他语言的优势是什么? Nginx吗?

I have seeing many docs saying that the main advantage of node.js http server is the evented io architecture, but Nginx has evented io too, so whats advantage of using node.js + node http server OVER php or other language with Nginx ?

推荐答案

任何答案的核心都应该是取决于您要做什么"的陈述..例如,您可能正在尝试.

At the core of any answer should be the statement 'it depends on what you are trying to do'.. So for example you might be trying to...

  • 在聊天室中支持1万个并发客户端
  • 每月提供1M静态页面
  • 为3k用户提供类似CMS的功能
  • 为小型企业使用的简单博客类型网站提供服务
  • 支持拥有数百万用户的重载系统(例如游戏)
  • 建立一个消费者银行网站
  • 等.

人们普遍认为,应该选择正确的技术来解决当前的问题-任何关于将一种技术与另一种技术相结合的优点的讨论,无论它们是否固有地处理事件IO,都不会涉及上下文.在任何决策过程中价值有限.

It's a commonly held belief that one should choose the right technologies to solve the problem in hand - any discussion about the virtues of combining one technology with another, whether they inherently handle event IO or not, without context is going to be of limited value in any decision making process.

在为您的技术栈制定决策时,另一个极具影响力的因素是可用于实现项目目标的技能和经验.

Another highly influential factor in decision making for your technology stack are the skills and experience available to deliver on the goals of the project.

但是...

使用了您所指的所有技术后,我将为您提供一些我们认为已解决的问题以及为什么选择某些配置的示例:

Having used all of the technologies you are referring to, i'll give you some examples of problems we believe to have solved and why certain configurations were selected:

PHP + Nginx

是的,PHP正在被阻止,但这并不妨碍Facebook和其他将其用作核心Web应用程序语言的人.在更传统的LAMP堆栈中,A是Apache,在高流量情况下可能会出现一个众所周知的长期存在的问题,在这种情况下,您可能会在入站到Apache的Web请求和与该Apache的连接之间创建一对一的关联.数据库.如果预计您要为1000个以上的并发客户端提供服务,并且您的数据库的连接限制为1000个,那么我希望您会遇到困难.

Yes PHP is blocking, but that isn't any impediment to Facebook and others using it as their core web application language. In the more traditional LAMP stack, the A being Apache, you have a well known and long standing issue which can arise under high traffic conditions where you might have created a 1-to-1 correlation between web requests inbound to Apache and connections to the Database. If you are expected to serve more than a 1000 concurrent clients, and your DB has a 1000 connection limit , I expect you'd be running into difficulties.

这种资源匮乏在过载条件下为用户创造了令人难忘的体验.

This kind of resource starvation creates a breaking experience for users under overloaded conditions.

在这种情况下,Nginx可以为您带来更多收益,因为事件IO使Web请求与出站PHP数据库连接之间的相关性解耦.有很多文献可以证实这一点.请记住,这不是神奇的-这是基于配置NGinx和PHP的方式-您可以通过启用默认值来轻松地吊死自己.

Nginx in this situation can give you more bang for your buck since the evented IO de-couples the correlation between web request and outbound PHP database connection. There's plenty of literature out there to corroborate this. Bear in mind, this isn't by magic - this is by dint of how you configure NGinx and PHP - you can easily hang yourself by leaving defaults enabled.

假设已经考虑到配置问题,NGinx的事件IO具有缓冲请求的最终效果,可以将请求以数据库可以处理的速率发送给PHP.

Assuming a thought through configuration is in place, NGinx's evented IO has the net effect of buffering requests, farming them out to PHP at a rate that the database can handle.

PHP应用程序广泛使用诸如Memcached之类的缓存,以进一步支持读取繁重的系统中的高容量.

PHP apps widely employ caches like Memcached to further support high volumes in read heavy systems.

Node.js(纯HTTP)

我们选择Node.js作为其支持的生产解决方案的原因是

Our reason for choosing Node.js for the production solution that it supports are

  • 这不是关键任务(Node.js是新的,因此您不希望在其上运行银行系统)
  • 我们想要一些轻巧的东西
  • 我们想学习和尝试-通常在许多业务系统中不允许使用此标准

Node的新颖性及其引发的IO编程概念的微妙之处,使我们多次中断,使最终的解决方案花了比固定在PHP上更长的时间.

The newness of Node and the subtlety of it's evented IO programming concepts meant that we broke things quite a few times and it took us longer to get the final solution squared up than had we stuck to PHP.

Web应用程序的框架还处于起步阶段

The frameworks for web apps are somewhat in their infancy

  • Express.js
  • 套接字流
  • Backbone.js
  • 也许其他人...

鉴于他们都还年轻,他们仍在进行中.根据您要为该项目实现的目标,它们可能会为您提供很好的服务,也可能会浪费您的时间和精力进行学习.

Given how young they all are, they are still very much works in progress. Depending on what you are trying to achieve for the project, they may serve you well or drain time and effort in your learning them.

例如,在Express.js中,诸如处理HTTP缓存头,内容的GZIPing之类的简单事情并不完全是标准的,因此,如果这类事情是必不可少的,则必须开始制定定制的解决方案或在其他地方寻找.

For example, in Express.js, simple things like dealing with HTTP cache headers, GZIPing of content are not entirely standard, so if that sort of stuff is essential, you'll have to start making bespoke solutions or look elsewhere.

与NGinx或Apache不同,没有任何Node.js安装或使用它构建的应用程序可以确保在运行级别启动它.这意味着您必须找出一些解决方案,以使用Node.js之外的其他方法来管理重新启动时的应用程序自动启动以及其他恢复. (我们使用Monit)

There is nothing native to a Node.js installation or app built with it that ensures it's started in the run-levels, unlike NGinx or Apache. That means you have to figure out some solutions to manage the application autostart on reboot, and other recoveries, using something in addition to Node.js. (We use Monit)

Node.js + NGinx

您敢打赌,为什么不呢..NGinx更成熟了,因此,由于我们需要先终止SSL连接,然后才能将其连接到Node.js,这就是我们要做的.额外的好处是,现在NGinx可以通过GZIP内容了.

You bet, why not.. NGinx is more mature so since we need to terminate SSL connections before farming them out to Node.js, thats what we've done. The added benefit is that now NGinx can GZIP content passing through.

这篇关于与php/ruby​​/etc + nginx相比,使用node.js +节点http服务器有什么优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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