未调用清漆 vcl_backend_response

Varnish vcl_backend_response not called

我发现 Varnish 4.x 文档不一致。 根据文档 vcl_backend_response 每次从后端获取对象时都会调用 return 并且后端没有 return 错误(并且还活着并且健康)。

但是,我注意到许多 'fetch' 请求(由未命中引起)根本没有通过此函数。 这是一个示例输出:

-   VCL_call       HASH
-   VCL_return     lookup
-   VCL_call       MISS
-   VCL_return     fetch
-   Link           bereq 294915 fetch
-   Timestamp      Fetch: 1504198046.101306 0.003644 0.003644
-   RespProtocol   HTTP/1.1
-   RespStatus     200
-   RespReason     OK
-   RespHeader     Server: nginx/1.10.3 (Ubuntu)
-   RespHeader     Date: Thu, 31 Aug 2017 16:47:26 GMT
-   RespHeader     Vary: Accept-Encoding
-   RespHeader     Last-Modified: Thu, 31 Aug 2017 16:42:58 GMT
-   RespHeader     Expires: Thu, 31 Aug 2017 16:47:26 GMT
-   RespHeader     Cache-Control: public, max-age=90, s-maxage=332
-   RespHeader     Pragma: cache
-   RespHeader     X-Lift-Version: 2.6.3
-   RespHeader     X-Frame-Options: SAMEORIGIN
-   RespHeader     Content-Encoding: gzip
-   RespHeader     Content-Type: application/json; charset=utf-8
-   RespHeader     X-Varnish: 294914
-   RespHeader     Age: 0
-   RespHeader     Via: 1.1 varnish-v4
-   VCL_call       DELIVER
-   RespHeader     grace: none
-   VCL_return     deliver

与遵循文档的流程相反:

-   VCL_call       BACKEND_FETCH
-   VCL_return     fetch
-   BackendOpen    22 boot.default 127.0.0.1 9919 127.0.0.1 22536
-   Timestamp      Bereq: 1504198040.603601 0.000222 0.000222
-   Timestamp      Beresp: 1504198040.659723 0.056345 0.056123
-   BerespProtocol HTTP/1.1
-   BerespStatus   200
-   BerespReason   OK
-   BerespHeader   Server: nginx/1.10.3 (Ubuntu)
-   BerespHeader   Date: Thu, 31 Aug 2017 16:47:20 GMT
-   BerespHeader   Content-Type: text/html;charset=utf-8
-   BerespHeader   Transfer-Encoding: chunked
-   BerespHeader   Connection: keep-alive
-   BerespHeader   Vary: Accept-Encoding
-   BerespHeader   Last-Modified: Thu, 31 Aug 2017 16:42:58 GMT
-   BerespHeader   Expires: Thu, 31 Aug 2017 16:47:20 GMT
-   BerespHeader   Cache-Control: public, max-age=21600, s-maxage=21600
-   BerespHeader   Pragma: cache
-   BerespHeader   X-Lift-Version: 2.6.3
-   BerespHeader   X-Frame-Options: SAMEORIGIN
-   BerespHeader   Content-Encoding: gzip
-   TTL            RFC 21600 10 -1 1504198041 1504198041 1504198040 1504198040 21600
-   VCL_call       BACKEND_RESPONSE

因此 - 根据 Varnish 日志 - 当出现未命中并且从支持的 vcl_backend_response 中获取对象时,不会调用。 除非我遗漏了什么 - 这与文档相矛盾。

文档中没有不一致之处。您看到的是自 Varnish 4.0 以来的正常行为。在缓存未命中期间,您会(至少)在 varnishlog 中看到两个事务:(1) 处理客户端请求的事务(通常的流程是 vcl_recvvcl_hashvcl_missvcl_deliver; 即您问题中的第一个日志摘录); (2) 处理请求到后端的那个(通常的流程是 vcl_backend_fetchvcl_backend_response;即你问题中的第二个日志摘录)。这就是为什么您在客户端交易中看不到对 vcl_backend_response 的引用。

很明显,两笔交易都有关联。在某个时候,客户端事务创建并等待后端事务的完成。这显示在客户端事务的日志中:

-   ...
-   Link           bereq 294915 fetch
-   ...

这意味着已创建后端事务 (VXID 294915) 以便从源获取对象。