gpt4 book ai didi

varnish - 在后端生病时增加 Varnish 宽限时间

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

我们将Varnish Cache用作许多客户的前端,并在任何后端出现问题时通过宽限期处理过时的内容。

我们现在确实有一个失败的后端,并且我们想增加宽限期(在生病的时候),这可能吗?我尝试在文档中进行挖掘,但一无所获。

Varnish 4

最佳答案

当后端出现故障时,在 Varnish Cache 4.x 中提供过时的内容是常用的缓存。您只需要实现自己的 vcl_hit 子例程。这个想法是使用高宽限值(例如 24 小时)缓存内容,但当您的后端健康时将宽限限制在一个小的时间窗口(例如 10 秒):

sub vcl_hit {
if (obj.ttl >= 0s) {
# Normal hit.
return (deliver);
}

# We have no fresh fish. Lets look at the stale ones.
if (std.healthy(req.backend_hint)) {
# Backend is healthy. Limit age to 10s.
if (obj.ttl + 10s > 0s) {
return (deliver);
} else {
# No candidate for grace. Fetch a fresh object.
return(fetch);
}
} else {
# Backend is sick. Use full grace.
if (obj.ttl + obj.grace > 0s) {
return (deliver);
} else {
# No graced object.
return (fetch);
}
}
}

欲了解更多信息,请检查:
  • Deliver stale content after error fetch in Varnish 4 before "probe" marks the server unhealth
  • https://info.varnish-software.com/blog/grace-varnish-4-stale-while-revalidate-semantics-varnish
  • 关于varnish - 在后端生病时增加 Varnish 宽限时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38585486/

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