gpt4 book ai didi

Varnish 缓存由 vcl_backend_error 生成的响应

转载 作者:行者123 更新时间:2023-12-03 17:46:00 26 4
gpt4 key购买 nike

我们正在运行一个安装程序,其中Varnish将后端请求缓存到多个后端实例。这是使用Director VMOD处理的。在后端服务器上完成新代码的新部署后,它们将脱机几秒钟(可能一分钟),但这是一个交错部署,因此首先将代码部署到一个实例上,然后将该实例重新联机,到下一个,等等。

部署实例时,它将关闭其Web服务器,以确保在部署期间不会处理任何请求。为了解决这个问题,Varnish VCL内置了一个重启循环:

sub vcl_deliver {
# Restart specifically to catch timeouts on deploy
if (resp.status >= 500) {
# Restart goes to vcl_req and the director should choose another backend from the pool
return(restart);
}

强制重新启动将导致Director VMOD抢占一个未部署的下一个实例(因为只有一个同时部署)并得到有效答案。这很好。

但是,当后端获取导致产生 FetchError HTC status -1(输入错误的输入端,由网络服务器关闭midrequest导致)时,将调用vcl_backend_error子例程。发生这种情况时,将按预期触发重新启动,但Varnish不会转到vcl_backend_fetch,而是将生成的响应明显地缓存在VCL_backend_error中,并返回该响应。在原始响应和重新启动的响应的相关部分下面:
    VCL_call       RECV
- VCL_return hash
- ReqUnset Accept-Encoding: gzip, deflate
- ReqHeader Accept-Encoding: gzip
- VCL_call HASH
- VCL_return lookup
- VCL_call MISS
- VCL_return fetch
- Link bereq 101974384 fetch
- Timestamp Fetch: 1545038546.336891 8.103600 8.103600
- RespProtocol HTTP/1.1
- RespStatus 503
- RespReason Backend fetch failed
- RespHeader Date: Mon, 17 Dec 2018 09:22:26 GMT
- RespHeader Server: Varnish
- RespHeader Content-Type: text/html; charset=utf-8
- RespHeader Retry-After: 5
- RespHeader X-Varnish: 101974383
- RespHeader Age: 0
- RespHeader Via: 1.1 varnish (Varnish/5.0)
- VCL_call DELIVER
- VCL_return restart
- Timestamp Process: 1545038546.336900 8.103608 0.000008
- Timestamp Restart: 1545038546.336902 8.103611 0.000003
- Link req 101974385 restart
- End

VCL_call RECV
- VCL_return hash
- VCL_call HASH
- VCL_return lookup
- Hit 101974384
- VCL_call HIT
- VCL_return deliver
- RespProtocol HTTP/1.1
- RespStatus 503
- RespReason Backend fetch failed
- RespHeader Date: Mon, 17 Dec 2018 09:22:26 GMT
- RespHeader Server: Varnish
- RespHeader Content-Type: text/html; charset=utf-8
- RespHeader Retry-After: 5
- RespHeader X-Varnish: 101974385 101974384
- RespHeader Age: 0
- RespHeader Via: 1.1 varnish (Varnish/5.0)
- VCL_call DELIVER
- VCL_return restart
- Timestamp Process: 1545038546.336929 8.103637 0.000027
- Timestamp Restart: 1545038546.336932 8.103640 0.000003
- Link req 101974386 restart
- End

然后它将继续重新启动,从缓存中获取503错误,重新启动等,直到达到重新启动限制为止。

这种行为是故意的吗?有谁知道为什么会这样以及如何预防呢?

最佳答案

是的,这就是预期的行为。从文档中:

A vcl_synth defined object is never stored in cache, contrary to a vcl_backend_error defined object, which may end up in cache. vcl_synth and vcl_backend_error replace vcl_error from Varnish 3.



像往常一样,您可以避免在 set beresp.uncacheable = true;期间仅执行 vcl_backend_error

关于Varnish 缓存由 vcl_backend_error 生成的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53817089/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com