0

**您可能想先阅读下面的更新**

我正在建立一个 Drupal 站点。我已经用 nginx 和 varnish 配置了它。我什至没有在服务器上安装 apache。

我正在努力提高性能。一个主要的事情是第一个请求(在单个页面加载中;比如说,按 F5 后的第一个请求)比其他请求花费更多的时间。

回复:

Accept-Ranges       bytes
Age                 0
Cache-Control       no-cache, must-revalidate, post-check=0, pre-check=0
Connection          keep-alive
Content-Encoding    gzip
Content-Language    en
Content-Length      7541
Content-Type        text/html; charset=utf-8
Date                Fri, 08 Nov 2013 15:55:07 GMT
Etag                "1383926106"
Expires             Sun, 19 Nov 1978 05:00:00 GMT
Last-Modified       Fri, 08 Nov 2013 15:55:06 +0000
Server              nginx/1.1.19
Via                 1.1 varnish
X-Powered-By        PHP/5.3.10-1ubuntu3.8
X-Varnish           1319371045

要求:

Accept              text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding     gzip, deflate
Accept-Language     nl,en-us;q=0.7,en;q=0.3
Connection          keep-alive
Cookie              has_js=1
Host                _____________________ (removed by me)
Referer             _____________________ (removed by me)
User-Agent          Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0

这是萤火虫中的时间线(翻译自荷兰语)

Block:              123ms
Dns, Connect, Send: 0
Wait:               1.29s
Receive:            22ms
  1. 根据响应标头,我可以断定该页面确实是从缓存中提供的吗?
  2. 为什么可以花这么长时间?有没有办法分解 nginx 和清漆为页面提供服务所采取的任何步骤?

更新:

打开nginx的调试日志后,我发现:

....
2013/11/08 17:23:05 [debug] 4992#0: *3786 http run request: "/index.php?"
2013/11/08 17:23:05 [debug] 4992#0: *3786 http upstream check client, write event:1, "/index.php"
2013/11/08 17:23:05 [debug] 4992#0: *3786 http upstream recv(): -1 (11: Resource     temporarily unavailable)
2013/11/08 17:23:06 [debug] 4992#0: *3786 post event 00000000021FFD78
2013/11/08 17:23:06 [debug] 4992#0: *3786 post event 000000000221CEB8
....

第二个更改应该不是巧合(所以我假设“资源暂时不可用”需要一秒钟)。

4

2 回答 2

1

您可以看到这不是缓存命中,因为 X-Varnish 标头中只有一个数字 (xid)。任何缓存命中都将引用当前 xid 和最初执行后端获取的 xid。

您的 Expires 标头是过去的,这意味着 Varnish(默认情况下)不会缓存它。

这是您的后端需要很长时间才能回答,并且在完成后会发送不可缓存的响应。

于 2013-11-11T08:56:02.103 回答
0

您必须启用 Drupal 页面缓存以避免Cache-Control : no-cache, must-revalidate, post-check=0, pre-check=0,这会阻止 Varnish 缓存响应。

于 2013-11-20T09:44:36.750 回答