performance - 为什么提供缓存页面需要一秒钟?

标签 performance drupal ubuntu nginx varnish

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

我正在建立一个 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

这是 Firebug 中的时间线(翻译自荷兰语)
Block:              123ms
Dns, Connect, Send: 0
Wait:               1.29s
Receive:            22ms
  • 根据响应 header ,我可以断定该页面确实是从缓存中提供的吗?
  • 为什么可以花这么长时间?有没有办法分解 nginx 和 Varnish 为页面提供服务所采取的任何步骤?

  • 更新:

    打开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
    ....
    

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

    最佳答案

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

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

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

    关于performance - 为什么提供缓存页面需要一秒钟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19863980/

    相关文章:

    drupal - Drupal规则+一次性登录重定向问题

    drupal - Drupal 可以与 PostGIS 一起使用以进行空间查询吗?

    ubuntu - 在选项卡或终端之间轻松复制/粘贴 vim

    linux - 在 ubuntu 上运行 cron 作业

    html - 屏幕外的 "hiding"个对象是否会导致性能损失达到荒谬的程度?

    java - 为什么单线程使我的 Java 程序速度如此之快?

    C++ 性能,for 与 while

    Drupal 7 新用户以编程方式创建?

    javascript - 检测在不可见和在视口(viewport)外时是否对canvas/css3动画进行了优化

    python - 在 Ubuntu 中安装 OwlReady2 (Python lib) 时出现问题