Mailing List Archive

Varnish and failed upstream
Hello. I have one case and I can not find good solution for it.
In varnish3 req.backend was saved during restarts, so I can compare old
backend property and set other backend after first restart.
But in varnish 5 and newer req.backend_hint in vcl_recv is default always.
I can not use retry in vcl_backend_response, because this function did not
called.
How can I fix it?

My bad solution:

sub vcl_init {
new upstream_rr = directors.round_robin();
key_rr.add_backend(srv1);
key_rr.add_backend(srv2);
}

sub vcl_recv {
if (req.restarts == 0) {
set req.backend_hint = upstream_rr.backend();
} else {
if (req.restarts == 1) {
std.syslog(180, "RECV IN PROG: set backend srv1");
set req.backend_hint = srv1;
} elseif (req.restarts == 2) {
std.syslog(180, "RECV IN PROG: set backend srv2");
set req.backend_hint = srv2;
} elseif (req.restarts > 2) {
std.syslog(180, "RECV IN PROG: use other DC backend default");
set req.backend_hint = default;
}
}
return (hash);
}

--
--
??????? ????????
??????? ?? «?????»
http://flant.ru/
+7 (495) 721-10-27, ???. 422
+7 (926) 125-39-69
Re: Varnish and failed upstream [ In reply to ]
On Tue, Jul 9, 2019 at 8:12 AM Nikolay Bogdanov
<nikolay.bogdanov@flant.com> wrote:
>
> Hello. I have one case and I can not find good solution for it.
> In varnish3 req.backend was saved during restarts, so I can compare old backend property and set other backend after first restart.
> But in varnish 5 and newer req.backend_hint in vcl_recv is default always. I can not use retry in vcl_backend_response, because this function did not called.
> How can I fix it?

What you are looking for is probably a circuit breaker, you can
implement one with vmod-saintmod:

https://github.com/varnish/varnish-modules/blob/master/docs/vmod_saintmode.rst#vmod_saintmode

However instead of using it with req, it's probably more efficient to
work on the backend side and retry from vcl_backend_fetch or
vcl_backend_error.

Best,
Dridi
_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc