Varnish and time out on backend (first_byte_timeout).
Mickaël GERVAIS
mgervais at agaetis.fr
Wed Jan 12 16:08:13 CET 2011
Thanks a lot!! Apparently it works... (I've taken my hearplugs...)
Here is my config is somebody needs it:
backend fake {
.host = "xxxxxxxxx";
.port = "80";
.probe = {
.url = "/fake.html";
.interval = 60s;
.timeout = 0.1s;
.window = 1;
.threshold = 1;
.initial = 1;
}
}
sub vcl_recv {
[...]
if ( req.http.magicmarker && req.http.magicmarker == "fake" ) {
unset req.http.magicmarker;
set req.backend = fake;
} else {
set req.backend = yyyy;
}
[...]
}
sub vcl_error {
log "[Error ] ( ) " req.url "(Status: " obj.status ", Restarts: "
req.restarts ")";
if (obj.status == 503 && req.restarts < 5) {
log "--- Restart url: " req.url "(Status: " obj.status ", Restarts:
" req.restarts ")";
set obj.http.X-Restarts = req.restarts;
if ( req.restarts == 0 ){
log "--- First restart add fake.";
set req.http.magicmarker = "fake";
}
restart;
}
}
On Wed, 12 Jan 2011 14:31:58 +0100, Kristian Lyngstol
<kristian at varnish-software.com> wrote:
> On Wed, Jan 12, 2011 at 11:34:37AM +0100, Mickaël GERVAIS wrote:
>> If a timeout occurs (first_byte_timeout reached) the function vcl_error
>> is
>> called, I'd like to use the saint mode to retreive the response from the
>> cache, but saint mode is only avaliable on beresp.
>>
>> Is there a way to tell varnish use a dirty object from the cache? Maybe
>> is
>> not the correct way to handle this kind of error.
>
> You are correct - that is a weakness. I have a nasty hack, though.
>
> 1. Declare a second, bogus backend which will always be sick.
> 2. In vcl_error if restarts is 0, set a magic marker and restart.
> 3. Look for the magic marker in vcl_recv - if it's present, tell Varnish
to
> use the bogus backend. Grace will then kick in because that backend is
> marked as sick.
> 4. If the object exists in cache (graced) - it will be used. Otherwise,
you
> will hit vcl_error again. (Thus the check of req.restarts in step 2).
>
> It's a nasty, yet brilliant hack, if I might say so myself ;)
>
> It adds latency and doesn't utilize saintmode, but it gets the job done
in
> a way that will also make little children cry.
>
> - Kristian
--
:::::::::::::::::::::::::::::::::::::::::::::::
MICKAL GERVAIS
Agaetis
10 allée Evariste Galois
63 000 Clermont-Ferrand
Courriel : mgervais at agaetis.fr
Téléphone : 04 73 44 56 51
Portable : 06 82 35 52 82
Site : http://www.agaetis.fr
:::::::::::::::::::::::::::::::::::::::::::::::
More information about the varnish-misc
mailing list