如何减少服务器“等待"时间? [英] How to reduce server "Wait" time?

查看:37
本文介绍了如何减少服务器“等待"时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试优化我网站的速度,我正在使用 pingdom.com.现在,加载页面所需的时间超过 50% 是等待"时间,如下面的屏幕截图所示.我能做些什么来减少这种情况?另外,这个数字有多典型?有这方面的基准吗?谢谢!

I am trying to optimize my site's speed and I'm using the great tool at pingdom.com. Right now, over 50% of the time it takes to load the page is "Wait" time as shown in the screenshot below. What can I do to reduce this? Also, how typical is this figure? are there benchmarks on this? Thanks!

好吧..让我澄清一些事情.没有服务器端脚本或数据库调用正在进行.只是 HTML、CSS、JS 和图像.我已经做了一些事情,比如将 js 推送到 body 标签的末尾以获得并行下载.我知道 main.html 和 templates.html 通过在 js.js 下载后同步完成而增加了整体等待时间,这不是问题.我只是对每个请求有多少等待"时间感到惊讶.服务器距离会影响这个吗?在共享服务器上怎么样,这会影响等待时间吗?有没有什么容易解决的问题来解决这些问题?

Ok.. let me clarify a few things. There are no server side scripts or database calls going on. Just HTML, CSS, JS, and images. I have already done some things like push js to the end of the body tag to get parallel downloads. I am aware that the main.html and templates.html are adding to the overall wait time by being done synchronously after js.js downloads, that's not the problem. I am just surprised at how much "wait" time there is for each request. Does server distance affect this? what about being on a shared server, does that affect the wait time? Is there any low-hanging fruit to remedy those issues?

推荐答案

在 Apache 的情况下,最常见的原因是 DNS 反向查找的使用.这意味着每次您发出请求时,服务器都会尝试找出您机器的名称.这可能需要几秒钟的时间,这就解释了为什么您的等待时间很长,然后加载速度很快,因为问题与带宽无关.

The most common reason for this in the case of Apache is the usage of DNS Reversal Lookup. What this means is that the server tries to figure out what the name of your machine is, each time you make a request. This can take several seconds, and that explains why you have a long WAIT time and then a very quick load, because the matter is not about bandwidth.

显而易见的解决方案是在/etc/httpd/conf/httpd.conf 中禁用主机名查找

The obvious solution for this is to disable hostnamelookup in /etc/httpd/conf/httpd.conf

HostnameLookups Off

然而……这通常是不够的.事实是,在许多情况下,即使您禁用了主机名查找,apache 仍然会执行反向查找,因此您需要仔细查看 apache 配置的每一行.特别是,最常见的原因之一是日志.默认情况下,在许多 red hat - centos 安装中,日志格式包括 %h 代表主机名",并且需要 apache 进行反向查找.你可以在这里看到:

However...this is usually NOT enough. The fact is that in many cases, apache still does a reversal lookup even when you have disabled host name lookup, so you need to take a careful look at each line of your apache config. In particular, one of the most common reasons for this are LOGS. By default on many red hat - centos installations, the log format includes %h which stands for "hostname", and requires apache to do a reverse lookup. You can see this here:

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

您应该将那些 %h 更改为 %a 以解决此问题.

You should change those %h for %a to solve this problem.

这篇关于如何减少服务器“等待"时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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