Rails如何优化我的网站? [英] Rails how to optimize my website?

查看:74
本文介绍了Rails如何优化我的网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的网站更快.我知道我可以制作CSS精灵并压缩HTML和CSS.

I want to make my website faster. I know I can make CSS sprites and compress my HTML and CSS.

我还有其他方法可以优化页面速度吗?

Are there other ways I can optimize my page speed?

此页面为示例: http://www.vinderhimlen.dk/konkurrencer/vind- Elektronik

加载共享按钮,给星级评分和Facebook点赞需要花费几秒钟的时间.我真的很想对其进行优化.我只是认为最小化HTML和CSS是不够的.

It takes several seconds to load the share buttons, rating stars and Facebook likes. I would really want to optimize it. I just don't think that minimizing the HTML and CSS is enough.

推荐答案

无论您要扩展还是提高Rails的性能,您都需要在基准前后进行基准测试.安装最新的性能增强插件或复制其他人的技术很容易,但是如果不测量执行时间,您将永远不知道自己所做的事情会提高性能还是降低性能.

No matter what you do to scale or increase performance of Rails you will want to take benchmarks before and after. It is easy to install the latest performance-enhancing plugin or copy someone else's technique, but without measuring execution times you will never know whether the things you are doing increase performance or degrade it.

性能是相对的,可能会因许多因素而异.性能的两个方面对于扩展Rails都很重要:

Performance is relative and can vary based on many factors. There are two aspects of performance that are important for scaling Rails:

  • 延迟-我们能以多快的速度答复请求?这是根据请求和响应之间经过的时间来衡量的.
  • 吞吐量–在给定的时间内我们可以处理多少个请求?衡量为每秒的响应.

进行一般的性能测试后,我们很容易看到瓶颈开始出现.在这一点上,我们可以进一步使用打包工具将焦点范围缩小到以下一种或多种,​​以最常见到最不常见的顺序进行

After we do our general performance testing we can easily see bottlenecks begin to appear. At that point we can further use packaged tools to narrow the field of focus to one or more of the following, which are in order of most common to least common:

  • 数据库问题:自定义SQL不良,联接和关联不正确或不理想,数据库表过大等.
  • 模型问题:业务规则过于复杂或设计错误.
  • 前端视图问题:HTML或CSS选择不当,庞大的javascript库,未优化的图像等.
  • 交易问题:运行的Mongrel(或其他应用服务器)实例太少,硬件不足,控制器编写不佳或控制器不是最佳的,应用程序架构错误等.
  • Database problems: Poor custom SQL, incorrect or non-optimal joins and associations, overly large database tables, etc.
  • Model problems: Business rules are overly complex or incorrectly designed.
  • Front-end view problems: Poor HTML or CSS choices, extremely large javascript libraries, un-optimized images, etc.
  • Transactional problems: Too few Mongrel (or other app server) instances running, not enough hardware, poorly written or non-optimal controllers, incorrectly architected application, etc.

通常,人们将交易问题视为绩效不佳的原因,而其他情况下,交易问题往往是由其他类型的问题引起的.

Often people think of transactional problems as the cause of poor performance, when more often it is caused by the other types of problems.

如果您的自定义SQL设计不良,数据库表过大,联接或关联不理想,那么无论您投入多少硬件,都可能永远不会提高性能.您的Rails应用程序将无法扩展.同样的事情也适用于某些交易问题.当在开发的设计和编码阶段遵循不良做法时,就会发生大多数可伸缩性问题.

If you have poorly-designed custom SQL, extremely large database tables, or non-optimal joins or associations, no matter how much hardware you throw into the mix you may never increase performance. Your Rails application just won't scale. The same thing applies for some transactional problems. Most scalability problems occur when bad practices were followed during design and coding phases of development.

以下工具将有助于确定瓶颈所在...

The following tools will be helpful in determining where your bottlenecks live...

  • " query_analyzer "-Bob Silva的MySQL工具,用于自动解释每个查询.
  • " ruby​​-prof "-用C语言编写的快速Ruby代码分析器.
  • " pl_analyze "-由Eric Hodel撰写,它分析了SysLogLogger的记录器输出. /li>
  • " yslow "-一个Firebug插件,用于测量和确定特定页面运行缓慢的原因.
  • " YUI压缩器"-来自Yahoo性能团队的Javascript/CSS压缩工具
  • "query_analyzer" - Bob Silva's MySQL tool for automatically EXPLAINing each query.
  • "ruby-prof" - A fast Ruby code profiler written in C.
  • "pl_analyze" - Written by Eric Hodel, this analyzes logger output from SysLogLogger.
  • "yslow" - A Firebug plugin to measure and determine why a particular page is slow.
  • "YUI compressor" - A Javascript/CSS compression tool from the performance team at Yahoo.

一旦确定了问题所在,就可以更轻松地进行归零并解决每个问题.

Once you determine where the problems exist it is much easier to zero-in and address each issue.

这篇关于Rails如何优化我的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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