grace and backend faults

Alex Mizrahi alex.mizrahi at gmail.com
Sun May 24 19:41:29 CEST 2009


hi

serving stale content during grace period works fine if backend polling can 
detect that server is down. however in some cases polling thinks that server 
is fine, but it returns 50x error for some requests (e.g. when database 
server is overloaded), and it might be better if stale content would be 
served. (by the way, that's how grace works in nginx web server's cache.)

as i understand, varnish does not support this case now.
nevertheless, i've tried to hack something with vcl, using example with 
restarts as inspiration. i've made a nonexistant backend for this purposes, 
with polling enabled:

backend nonexistant {
        .host = "localhost";
        .port = "31337";
        .probe = {
           .interval = 10s;
           .timeout = 0.3 s;
           .window = 2;
           .threshold = 1;
        }
}

then it vcl_fetch, when it sees status 500, it
calls restart:

sub vcl_fetch {
        if (obj.status == 500) {
                restart;
        }
}

and vcl_recv sets backend to nonexistant in case of restart:

sub vcl_recv {
        if (req.restarts == 0) {
                set req.grace = 2m;
                set req.backend = apache;
        } else {
                set req.grace = 2m;
                set req.backend = nonexistant;
        }
}

to my surprise, it worked and stale content was served instead of error.
but it tries to use backend each time in this case. i've tried to work
this out adjusting obj.ttl in vcl_fetch:

sub vcl_fetch {
        if (obj.status == 500) {
                restart;
        }
        if (req.restarts == 1) {
            set obj.ttl = 120s;
        }
}

it did not help, though. is it because ttl can be adjusted only when
object is fetched from backend, or something is wrong here?

also, if there is no cached version of this page, i'd like it to show
error from backend rather than error from varnish, but it is not trivial
to do this. i think it can be made via one more restart, but then backend
will have two requests instead of one, which is not good.

so, this hack in vcl is not very usable, in my situation, at least.

are there plans to implement it? i've found this feature requested in
ticket #369, but this ticket was last modified 4 monthes ago.. 




More information about the varnish-misc mailing list