简体   繁体   English

编程语言的速度对Web应用程序是否重要?

[英]Does the speed of a programming language matter for web applications?

I see a lot of benchmarks between PHP, Python, Ruby, etc all over the Internet. 我在整个互联网上看到PHP,Python,Ruby等之间的许多基准测试。 Ruby has gotten a lot of flak for being super slow, which leads to developers refusing to use it for web development for "performance reasons". Ruby因超级速度而受到很多抨击,导致开发人员出于“性能原因”而拒绝将其用于Web开发。 But does the performance of the interpreter really matter for web applications? 但是,解释器的性能对Web应用程序真的很重要吗? Isn't the bottleneck located in the database 99% of the time anyway? 99%的时间不是瓶颈位于数据库中吗? So why is everyone freaking out? 那么为什么每个人都吓坏了?

Note: I realize that in some edge cases, such as certain mathematical/scientific web applications, performance matters a lot, but I'm not talking about those; 注意:我意识到在某些边缘情况下,例如某些数学/科学Web应用程序,性能很重要,但我不是在谈论那些; I'm talking about your average social networks, Stack Overflows, etc. 我说的是你的平均社交网络,Stack Overflows等。

What should keep you shivering scared in the corner is that multiple studies done by amazon.com and google.com have found that a < 1 second decrease in page load time had a significant ( for them ) impact on their conversion rates and therefore profit. 什么应该让你害怕在角落里发抖,amazon.com和google.com进行的多项研究发现,页面加载时间减少<1秒对他们的转换率和利润有显着影响(对他们而言)。

Therefore performance matters a lot, even for small sites. 因此,即使是小型网站,性能也很重要。 The question is how much will it matter. 问题是它有多重要。 Losing .1% of sales doesn't really matter when your doing 100 uniques a day, but when your doing 10 million then all of a sudden that .1% costs you a lot of money. 当你每天做100次独立时,失去.1%的销售并不重要,但是当你做1000万时,那么突然间.1%会花费你很多钱。

Even small changes in response times can have significant effects. 即使响应时间的微小变化也会产生重大影响。 Google found that moving from a 10-result page loading in 0.4 seconds to a 30-result page loading in 0.9 seconds decreased traffic and ad revenues by 20% (Linden 2006). 谷歌发现,从0.4秒的10个结果页面加载到0.9秒的30个结果页面加载,流量和广告收入减少了20%(Linden 2006)。 When the home page of Google Maps was reduced from 100KB to 70-80KB, traffic went up 10% in the first week, and an additional 25% in the following three weeks (Farber 2006). 当谷歌地图的主页从100KB减少到70-80KB时,流量在第一周增加了10%,在接下来的三周内增加了25%(Farber 2006)。 Tests at Amazon revealed similar results: every 100 ms increase in load time of Amazon.com decreased sales by 1% (Kohavi and Longbotham 2007). 亚马逊的测试显示了类似的结果:亚马逊的加载时间每增加100毫秒,销售额下降1%(Kohavi和Longbotham,2007年)。 Experiments at Microsoft on Live Search showed that when search results pages were slowed by 1 second: (Kohavi 2007) 微软在Live Search上的实验显示,当搜索结果页面减慢1秒时:(Kohavi 2007)

 * Queries per user declined by 1.0%, and * Ad clicks per user declined by 1.5% 

After slowing the search results page by 2 seconds: 将搜索结果页面减慢2秒后:

 * Queries per user declined by 2.5%, and * Ad clicks per user declined by 4.4% 

http://www.websiteoptimization.com/speed/tweak/psychology-web-performance/ http://www.websiteoptimization.com/speed/tweak/psychology-web-performance/

Does performance matter? 性能是否重要? Eventually, sure. 最后,当然。

But your website will have to get so large that you're into the millions of hits per month range before it will even be an issue for you outside of traditional optimization (eg proper indexing in your database). 但是,您的网站必须变得如此之大,以至于您在传统优化之外甚至会成为一个问题(例如,在您的数据库中正确编制索引)之前,您将达到每月数百万次点击量。

I don't think the Ruby distaste is so much to do with performance (although there have been issues with this). 我不认为Ruby厌恶与性能有很大关系(尽管存在问题)。 It's more that it's unproven, has a reputation for instability and forced a very rigid framework on you (yes I know you can use Ruby without Rails, etc). 它更多的是它未经证实,有不稳定的声誉,并强迫你的一个非常严格的框架(是的,我知道你可以使用没有Rails的Ruby等)。 I'm not a Ruby fan for the same reason I'm not a fan of the heavyweight PHP frameworks like CakePHP or Symfony: I find these frameworks overly invasive and so heavyweight that you're not doing PHP anymore. 我不是Ruby的粉丝,因为我不是像CakePHP或Symfony这样的重量级PHP框架的粉丝:我发现这些框架过于侵入性和重量级,你不再做PHP了。 Compare this to lighter weight framewrks like CodeIgniter, which have a much better return on investment (imho). 相比之下,像CodeIgniter这样的轻量级框架,它具有更好的投资回报率(imho)。

I don't think your question is very well-thought out. 我认为你的问题没有经过深思熟虑。

First you assert that most web apps don't require fantastic performance on the application-side of things, which is probably true for a lot of them. 首先,您断言大多数Web应用程序在应用程序方面都不需要出色的性能,这对很多人来说可能都是如此。 Then you give some examples of web applications that do require good performance, and wave them away saying that people just write them in C++ or Java instead! 然后你给的那些需要良好性能的Web应用程序的一些例子,和波他们离开话说,人们只是把它们记C ++或Java,而不是!

Well, don't you think they might prefer to write them in Ruby or Python? 那么,你不觉得他们可能更喜欢用Ruby或Python编写它们吗? Perhaps that's why people are interested in measuring Ruby and Python's performance! 也许这就是人们对测量Ruby和Python性能感兴趣的原因!

EDIT : OK, so you're interested in very run-of-the-mill web apps. 编辑 :好的,所以你对普通的网络应用感兴趣。 So then you and I can both see that there are two possibilities: 那么你和我都可以看到有两种可能性:

  • Performance actually is important, which is why they are concerned about Ruby and Python and PHP's performance. 性能实际上很重要,这就是为什么他们关注Ruby和Python以及PHP的性能。

  • Performance is not important, so they are mistaken, and they are either ignorant of that fact or making an excuse. 表现并不重要,所以他们错了,他们要么不知道这个事实,要么找借口。

That should not be the focus of your question. 这不应该是你问题的焦点。 Instead you should focus on how the content can be delivered to the end user in the most efficient means possible. 相反,您应该专注于如何以最有效的方式将内容传递给最终用户。 If a web application is well written I think any major server-side language is a good choice. 如果Web应用程序写得很好,我认为任何主要的服务器端语言都是一个不错的选择。

Does performance matter for web applications? 性能对Web应用程序是否重要?

Yes! 是! Even more so than for desktop applications! 甚至超过桌面应用程序!

With a desktop application, if you need it you can use nearly all of the considerable resources available to your users' computer. 使用桌面应用程序,如果需要,您可以使用用户计算机上几乎所有可用的资源。 With a web app, one computer has to potentially handle running your app for a lot of simultaneous users. 使用Web应用程序,一台计算机必须能够为大量并发用户运行应用程序。 If you can't get it to do that easily, you're in real trouble. 如果你不能轻易做到这一点,那你就陷入了困境。

It can matter a lot, depending on the context. 根据具体情况,它可能很重要。 Most websites are run on shared hosting servers where that stuff adds up. 大多数网站都是在共享主机服务器上运行的,这些内容会增加。 With a few hundred web applications running on the same box you're going to have CPU and memory bottlenecks. 在同一个盒子上运行几百个Web应用程序,您将遇到CPU和内存瓶颈。

There's a couple of different arguments here: because the code is running on your server, and if your code is inefficient, then it's going to overload and degrade the experience for everybody. 这里有几个不同的参数:因为代码在您的服务器上运行,如果您的代码效率低下,那么它会过载并降低每个人的体验。

The other side of the coin is that you need to be successful for it to matter , as Ted Dziuba so eloquently and profanely said. 硬币的另一面是, 你需要成功才能发挥作用 ,正如Ted Dziuba如此雄辩和亵渎地说。 "Slow" languages tend to be much faster to develop in and more expressive than compiled languages, so they allow a team to get a site up and running more quickly. 开发中的“慢”语言往往比编译语言更快,更具表现力,因此它们允许团队更快地启动和运行网站。

You're right. 你是对的。 Most of the time the bottleneck will be independent of your server-side language. 大多数情况下,瓶颈将独立于您的服务器端语言。 Of course 90% of all statistics are made up on the fly, but I'd say 9 times out of 10 the bottleneck is either going to be in bandwidth/transfer speeds or database operations. 当然,所有统计数据中有90%是动态编写的,但我会说10次中有9次瓶颈要么是带宽/传输速度还是数据库操作。

Assuming you make good use of each language, there are limited cases where the performance of PHP vs Python vs Ruby vs .NET vs whatever will ever be noticed by the user. 假设您充分利用了每种语言,那么PHP与Python与Ruby vs .NET的性能相比,用户可能会注意到的情况有限。 When things like XML parsing, and compression are done on a very large scale then you may start to notice, but otherwise I'd just stick to what you're most proficient with. 当像XML解析和压缩这样的事情大规模地完成时,你可能会开始注意到,但是否则我只会坚持你最熟练的东西。

Often times some of the greatest improvements in website speed can come from gzip compression and careful use of caching/content expiration. 通常,网站速度的一些最大改进可能来自gzip压缩和小心使用缓存/内容过期。 And both of those things can be configured in Apache or IIS. 这两件事都可以在Apache或IIS中配置。 I wrote about that topic here: http://swortham.blogspot.com/2007/10/three-ways-to-improve-your-websites.html 我在这里写了关于这个主题的文章: http//swortham.blogspot.com/2007/10/three-ways-to-improve-your-websites.html

Most sites will release first-version code as soon as the site is functional. 一旦网站正常运行,大多数网站都会发布第一版代码。 If they are at all successful, pretty soon there are multi-second pages, and they need to attend to either hardware or software, and you're I guess suggesting an implicit distinction between page code and database software. 如果它们一点都很成功,很快就会出现多秒页面,他们需要关注硬件或软件,我猜你是在暗示页面代码和数据库软件之间的隐含区别。

Are you wondering if we should not bother with the page code and assume any non-hardware scaling issues are in the database? 您是否想知道我们是否应该不关心页面代码并假设数据库中存在任何非硬件扩展问题? That's not my experience; 那不是我的经历; although it's usually the database that gets released soonest because like horseshoes, too often close is good enough (as long as the answer is what you expected.) 虽然它通常是最快发布的数据库,因为像马蹄铁一样,通常关闭足够好(只要答案是你所期望的。)

But I've seen a lot more page code that tried to do what databases are designed to do (eg with arrays) than vice versa (eg cursors), with equally detrimental consequences on speed and scalability. 但是我已经看到了更多的页面代码试图做数据库的设计(例如使用数组)而不是反之亦然(例如游标),同时对速度和可伸缩性产生同样的不利后果。 And optimizing a database query is in my experince less work than fixing PHP code. 优化数据库查询在我的工作中比修复PHP代码要少。

I think most speed problems are not the language (or the dbms itself) but rather the quality of the design and the code. 我认为大多数速度问题不是语言(或dbms本身),而是设计和代码的质量。 So I would think good developers would be more concerned with whether or not a language facilitates good design and good code, not how fast it runs. 所以我认为优秀的开发人员会更关心一种语言是否有助于良好的设计和良好的代码,而不是它的运行速度。

In my experience, once you really start getting busy then it's at the database where you can make the most DIFFERENCE. 根据我的经验,一旦你真正开始变得忙碌,那么它就在你可以做出最大差异的数据库中。

But i would also add one other consideration, and that's how 'big' your page size is in terms of images, JS and HTTP requests. 但我还要添加另一个考虑因素,就像图像,JS和HTTP请求而言,页面大小是多么“大”。 You could have a very slow site because your blazing fast database and app code created a monster of a web page with bloated JS and images. 你可能会有一个非常慢的网站,因为你的超快速数据库和应用程序代码创建了一个带有臃肿的JS和图像的网页怪物。 :) :)

jfar starts you down the right path. jfar让你沿着正确的道路前进。 As far as how impactful your language is on this, profiling will likely show that your language is not your bottle neck. 至于你的语言对此有多大影响,分析可能会表明你的语言不是你的瓶颈。

  • Avoid per-request compilation like old-scool cgi. 避免像old-scool cgi那样的每次请求编译。 Most modern web frameworks need to be resident between requests. 大多数现代Web框架需要驻留在请求之间。
  • If it doesn't change much, generate it and serve static. 如果它没有太大变化,则生成它并提供静态。
  • Compress. 压缩。 Enable gzip if you can, and strip whitespace and comments. 如果可以,请启用gzip,并删除空格和注释。 White space is for dev and debug. 白色空间用于开发和调试。
  • Figure out the prevailing db use case, query or insert, and tune for the right one. 找出主要的数据库用例,查询或插入,并调整正确的数据库用例。
  • Cache / render what you can. 缓存/渲染你可以。
  • Try benchmarking different app servers if you're ops people will let you change / upgrade. 如果您是操作人员将允许您更改/升级,请尝试对不同的应用服务器进行基准测试。

Any one else have some generic web tuning hints or links to other SO questions? 任何其他人都有一些通用的网络调整提示或其他SO问题的链接?

Is there a good book on web application performance tuning? 是否有关于Web应用程序性能调优的好书?

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

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