提高网站性能
我设计了一个新网站。我已经在网上托管了。我希望它具有最佳性能并更快地加载页面。
该网站是使用 codeigniter 在 php 5.0+ 中设计的。这是使用mysql作为数据库。我上面有图像。我正在使用 Nitobi 网格在页面上显示记录集。剩下的就是正常页面控制的一切。
由于我对网站性能因素不太有经验,因此我想获得有关可以提高网站性能的因素的建议和详细信息。请让我知道如何提高我的表现。
另外,请告诉我是否有任何方法来衡量网站的性能以及任何帮助测试性能的网站或工具。
I have designed a new web site. I have hosted it online. I want it to be of the best performance and load pages faster.
This website is designed in php 5.0+ using codeigniter. This is using mysql as DB. I have images on it. I am using Nitobi grid for displaying set of records on page. The rest is everything normal page controls.
As i am not so very experienced with website performance factors i would like to get suggestions and details on factors that can improve performance of website. Please let me know how i can improve my performance.
Also please let me know if there are any ways to measure the performance of website and also any websites or tools to help test the performance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
首先,获取 Firefox 和 Firebug,然后安装 YSlow。 YSlow 提供了有关相关网站的客户端性能的大量信息。这是用户指南。
对于服务器端性能,请查看 Apache JMeter。
To start, get Firefox and Firebug and then install YSlow. YSlow gives great information about the client-side performance of the website in question. Here's an User Guide.
For the server-side performance, have a look at Apache JMeter.
您研究过操作码缓存、APC、内存缓存等吗?正如另一个人所说,您需要计算页面加载的时间,并尝试找到潜在的 SQL 瓶颈和/或可以重构的脚本。您可能还想安装像 webgrind 这样的东西,这样您就可以看到页面加载时发生的情况以及每个进程需要多长时间。
Have you looked into opcode caching, APC, memcache etc? As another has said, you need to time the loading of your pages and try to find potential SQL bottlenecks and/or scripts that can be refactored. You may also want to look at getting something like webgrind installed so you can see what happens on a page load and how long each process takes.
您可以通过前面提到的 Firefox Firebug 插件中的“网络”选项卡查看主页及其包含的组件的加载时间。在那里,您可以看到页面速度缓慢是由于具有大量外部内容(例如用户添加的图像等)还是由于其本身。
在第一种情况下,除了删除花费最多时间的内容之外,您无能为力,在第二种情况下,考虑到 PHP 应用程序中的大多数性能问题取决于不完善的数据库这一事实,您将需要查看您的 PHP 代码交互(写得不好的查询、只要一个就足够的重复查询等)。
You can see loading times of the main page and the components it contains with the Net tab in the already mentioned Firebug addon for Firefox. There you can see if a page is slow due to having a lot of external content (like user added images or so) or because of itself.
In the first case not much you can do except removing the content that takes most time, in the second case you will need to take a look at your PHP code considering the fact that most of the times performance issues in PHP applications depend on imperfect database interaction (badly written queries, repeated queries when one would suffice, etc.).
分析是性能优化领域的关键词。
要分析您的网站,您必须测量 2 个不同的区域:php 脚本运行时间和整个页面加载时间(包括图片、javascript、样式表等)。测量 PHP 脚本非常容易。最简单的方法是将此行放在页面顶部,
并将此行放在底部:
如果它保持在 0.1 秒以下,那就没问题。现在到整个页面加载。不知道是否有一些带有响应时间记录的http嗅探器。
编辑:看起来上面提到的 Firebug 的 Net 选项卡是正确的工具
Profiling is the key word in the world of performance optimization.
To profile your site you have to measure 2 different areas: php scripts running time and whole page load time (including pictures, javascripts, style sheets etc). To measure PHP scripts is quite easy. The easiest way is to place this line at the top of your page
and this line at the bottom:
if it stays below 0,1 sec, it's ok. Now to the whole page loading. Dunno if there are some http sniffer with response time recording.
Edit: Looks like Firebug's Net tab mentioned above is the right tool for this
就像 Kevin 所说的,我建议尝试使用 PHP 进行操作码缓存。我不确定目前哪个最好,但当我一年前查找时,我决定使用 [eAccelerator][1],它效果很好。我还在另一台服务器上使用过 APC,但我更喜欢 eAccelerator。
您可能应该采纳 Shrpnel 上校的建议并进行一些分析。
[1]: http://en.wikipedia.org/wiki/EAccelerator eAccelerator
Like what Kevin said, I suggest trying opcode caching with PHP. I'm not sure which is currently best, but when I looked it up a year ago, I decided to go with [eAccelerator][1] and it works great. I've also used APC on another server but I prefer eAccelerator.
You should probable go with Col. Shrpnel's advice and do some profiling as well.
[1]: http://en.wikipedia.org/wiki/EAccelerator eAccelerator
从服务器的角度来看:
应该成为 php 的标准)
有很大影响,从浏览器的角度来看:
(每个都是理想的),将 css 放在 head 中,将 js 放在下面,
这些的影响可能是巨大的,cfr。 我在我的(基于 WordPress 的)网站上运行的测试。
from the server-perspective:
supposed to become standard in php)
and from a browser-perspective:
(one of each is ideal), put css in head, js below
impact of these can be huge, cfr. tests I ran on my (wordpress-based) site.
如果您有时间,请尝试一下 HipHop 开发和使用的Facebook
If you have time to play try HipHop developed and used by Facebook
页面在 0.0074 秒内生成。
使用 1 次数据库查询、7 次数据库缓存获取、3 次 RSS 缓存获取和 61.88 K 内存,数据库运行时间为 0.0006 秒 (7.87 %)。
http://i42.tinypic.com/2m31frp.jpg
哎呀!
不要碰撞——这是他的基准;)
Page generated in 0.0074 secs.
DB runtime 0.0006 secs (7.87 %) using 1 DB queries, 7 DB cache fetches, 3 RSS cache fetches and 61.88 K memory.
http://i42.tinypic.com/2m31frp.jpg
ouch !!
dont bump - this is his benchmark ;)
此网站将衡量您网站的综合性能分数,并为您提供一些相关的信息建议。您所要做的就是输入 URL。
This site will measure integrated performance mark for your site, as well as give you some relevant advice. All you have to do is to type in the URL.
我建议尝试一下 Clicktale。我已经使用它两个月了,很高兴观察你的用户做了什么,我学到了很多东西。
I would suggest give Clicktale a try. I’ve been using it for 2 months and it is neat to watch what your users do, I learned a lot.