Serve stale content if backend is healthy but "not too healthy"
Guillaume Quintard
guillaume.quintard at gmail.com
Tue Sep 21 15:35:57 UTC 2021
Hi,
As Dridi said, what you are looking for is exactly vmod_stale, but I wanted
to point out that part:
> We have a backend that actually proxies different services
In that case, it might be good to actually have a Varnish backend for each
type of backend behind the proxies. The backend definition would be exactly
the same, but the probe definitions would be different, with a specific
URL/host. this way, Varnish would be aware of who is actually unhealthy and
you don't have to deal with the stale thing.
If you need an open-source approach, I reckon the best you can do is
restart with a zero TTL if you detect a bad response. It does have a couple
of race conditions baked-in that vmod_stale sidesteps, but that's usually
good enough:
sub vcl_recv {
# be hopeful that the backend will send us something good, ignore grace
if (req.restarts == 0) {
set req.grace = 0s;
}
}
sub vcl_deliver {
# welp, that didn't go well, try again without limiting the grace
if (req.restarts == 0 && resp.status >= 500) {
set req.ttl = 10y;
return (restart);
}
}
Main issue is that you restart, so you are going to spend a lil bit more
time/resources processing the request, and the object in cache may have
expired by the time you realize you need it.
Hope that helps,
--
Guillaume Quintard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20210921/a0e8a58f/attachment.html>
More information about the varnish-misc
mailing list