简体   繁体   English

我是否应该将haml或erb或erubis用于潜在的高流量网站?

[英]Should I use haml or erb or erubis for potentially high traffic site?

I have been playing with Haml recently and really like the way the resulting code looks to me...the developer. 我最近一直在和Haml一起玩,真的很喜欢结果代码给我看的方式......开发人员。 I'm also not too worried about a designer being able to consume or change it...we're a small team. 我也不太担心设计师能够消费或改变它......我们是一个小团队。

That said, beginning work on a project we believe will generate quite a bit of traffic (who doesn't?). 也就是说,开始研究一个我们认为会产生相当多流量的项目(谁没有?)。 I'm concerned that there are things I just don't know about haml. 我担心有一些我不知道haml的事情。 Is there anything erb can do that haml can't? 有没有什么可以做的哈哈不能? Does haml have a negative effect as a project grows? 随着项目的发展,haml会产生负面影响吗? Are there other things that should be considered? 还有其他事情需要考虑吗?

And finally...how does Haml compare speedwise to erubis? 最后...... Haml如何与erubis进行速度比较? I see that it supposedly beats erb and eruby now... 我看到它现在应该胜过erb和eruby ......

Thanks! 谢谢!

Haml rocks. 哈姆尔岩石。 I haven't seen any recent performance numbers but it is pretty close to erb these days. 我没有看到任何最近的性能数字,但这些天它非常接近erb。 I think that it might be faster than erb if you turn on ugly mode (which prevents the pretty indentation) We're doing 2.8 million pageviews a day with Haml. 我认为如果你打开丑陋的模式(这可以防止漂亮的缩进)它可能比erb更快我们每天使用Haml进行280万次网页浏览。

There is a benchmarker checked into the Haml source tree: http://github.com/nex3/haml/tree/master/test 在Haml源代码树中检查了一个基准测试程序: http//github.com/nex3/haml/tree/master/test

Update November 2009 2009年11月更新

Nathan (Haml's main developer) published some Haml 2.2 benchmarks on his blog. Nathan(Haml的主要开发者)在他的博客上发布了一些Haml 2.2基准测试 You can see the exact numbers there but in short: 您可以在那里看到确切的数字,但简而言之:

  • Normal (pretty printing) mode = 2.8 times slower than ERB 正常(漂亮打印)模式=比ERB慢2.8倍
  • Ugly mode (no pretty tabs added) = equal to ERB 丑陋的模式(没有添加漂亮的标签)=等于ERB

You can enable ugly mode by placing Haml::Template::options[:ugly] = true in an initializer or environment file. 您可以通过在初始化程序或环境文件中放置Haml::Template::options[:ugly] = true来启用丑陋模式。 Note that ugly mode isn't really that ugly - the resulting HTML is actually much prettier than ERB - it's just not indented nicely. 请注意,丑陋的模式并不是那么难看 - 生成的HTML实际上比ERB更漂亮 - 它只是没有很好地缩进。

If you use Rails, the performance difference between Haml and erubis is negligible: templates get compiled and cached after the first hit, anyway. 如果你使用Rails,Haml和erubis之间的性能差异可以忽略不计:无论如何,模板在第一次命中后被编译和缓存。 Combine this with fragment and page caching and you can rest assured that views are not the performance bottleneck of your application. 将此与片段和页面缓存相结合,您可以放心,视图不是应用程序的性能瓶颈。

The question you should be asking yourself is: do you like writing Haml? 你应该问自己的问题是:你喜欢写汉谟吗? Does it make you more productive? 它会让你更有效率吗? Then you can decide easier. 然后你可以更轻松地决定。

I love HAML since it is a good tool for easily writing structured HTML, and generally it is just a joy to use. 我喜欢HAML,因为它是轻松编写结构化HTML的好工具,通常它只是一种使用的快乐。 But it has very little to do with choosing a tool based on the amount of traffic a site might have. 但它与根据网站可能拥有的流量选择工具几乎没有关系。

If you are worried about traffic, you should worry about using caching properly. 如果您担心流量,则应该担心正确使用缓存。 And then you need to apply the principles of general web-application performance - the result is that you will have super snappy responses to page loads. 然后,您需要应用一般Web应用程序性能的原则 - 结果是您将对页面加载有超级敏捷的响应。 Which is what a high-traffic website really needs. 这是一个高流量网站真正需要的。

A couple of presentations that show how to improve website performance can be found here: 可以在此处找到一些演示如何提高网站性能的演示文稿:

And the best place that I know of to learn how to use rails caching properly is: 我知道如何正确使用rails缓存的最佳位置是:

I think it's entirely a matter of personal preference and maintainability. 我认为这完全取决于个人偏好和可维护性。 For me, Haml makes the templates easier to read and understand, and the performance is very acceptable. 对我来说,Haml使模板更易于阅读和理解,并且性能非常可接受。 In the end, the templating language is unlikely to be the place where you need to optimize -- more likely database queries, view or object caching, etc. 最后,模板语言不太可能是您需要优化的地方 - 更有可能是数据库查询,视图或对象缓存等。

However, in the case of ERb templates, you will get better performance essentially for free if you use erubis. 但是,对于ERb模板,如果使用erubis,您将获得更好的性能。

If you like how haml works from a coding point of view, don't worry about the performance of the templating engine too much. 如果你喜欢haml从编码的角度来看是如何工作的,那么不要太担心模板引擎的性能。 (Though, as you've pointed out, it's now fast.) It can definitely generate any output the other engines can. (尽管如你所指出的那样,它现在很快。)它绝对可以产生其他引擎可以输出的任何输出。

Generally, it's more profitable to put your energy into setting up caching than worrying about your templating engine where you're having performance problems. 一般来说,将精力放在设置缓存上比担心性能问题的模板引擎更有利可图。

I would personally recommend us erubis in precompiled templates. 我个人会在预编译模板中推荐我们的erubis。

Especially if there's no need for dynamic templating. 特别是如果不需要动态模板。 Then your biggest slowdown will be limited by the speed at which ruby can parse ruby. 那么你最大的减速将受到红宝石解析红宝石的速度的限制。

I'd probably set up a small cron job that just monitors for changed source templates and autocompiles them on-change that you can turn off when not in use. 我可能会设置一个小的cron作业,只监视已更改的源模板并自动编译它们的变化,您可以在不使用时关闭它们。

Compile once, use many. 编译一次,使用很多。

Oh, and if you're really concerned about speed, Tenjin may be worth a look too ( same creators as erubis ) 哦,如果你真的关心速度,天神也值得一看(与erubis一样的创造者)

http://www.kuwata-lab.com/tenjin/rbtenjin-examples.html http://www.kuwata-lab.com/tenjin/rbtenjin-examples.html

Well, Haml performance continues to improve with each release. 好吧,每次发布时,Haml的性能都在不断提高。 Is it at an acceptable place at the current time? 它目前在可接受的地方吗? That's for you to decide (I'm inclined to say "Yes", but it's your choice based on your needs). 那是你决定的(我倾向于说“是”,但这是你根据自己的需要选择的)。 If you like the templates and the readability they provide, then the performance drop (however negligible) should really be the final factor in your decision. 如果您喜欢模板和它们提供的可读性,那么性能下降(但可忽略不计)应该是您决定的最终因素。

One of the other tools you should consider using in conjunction with Haml is make_resourceful, another gem by the maintainer of Haml (Nathan Weizenbaum) that simplifies a lot of the RESTful things in a Rails app. 您应该考虑与Haml一起使用的其他工具之一是make_resourceful,这是Haml(Nathan Weizenbaum)维护者的另一个宝石,它简化了Rails应用程序中的许多RESTful内容。

If you have any further, more specific questions about Haml (and m_r), I'm sure Nathan would be more than happy to answer them. 如果你有关于Haml(和m_r)的任何进一步的,更具体的问题,我相信Nathan会非常乐意回答这些问题。 He can be reached via Jabber/XMPP and email. 可以通过Jabber / XMPP和电子邮件联系他。 His contact information can be found here . 他的联系信息可以在这里找到。

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

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