Roadblock for Varnish 4 vmod_saintmode

Dag Haavi Finstad daghf at
Mon May 26 17:04:08 CEST 2014

On Mon, May 26, 2014 at 11:04 AM, Poul-Henning Kamp <phk at> wrote:
> In message <CAEh05VZpyTZq2pT5dAnmwEc5AZLurAfxSeznQ4BsWxWa=ie_DQ at>
> , Dag Haavi Finstad writes:
>>The way I envisioned it is purely on the fetch side. So 'saintmode' in
>>this case will be a tool that helps us avoid picking a backend for
>>certain URLs.
> So how exactly does that work ?
> Once you havn't picked the backend, what backend do you then use ?
> Does the saint director pick another one ?  (by what algorithm ?)

The saintmode director is only a simple decorator around a single
backend. It will not pick a different backend by itself, it will
merely report as sick. If an object is found to be on its trouble list
in be->healthy(), it will be reported as sick. Likewise, be->getfd()
will return NULL and it will be a 503 if it ends up getting selected

The policy of how a different backend is picked is left up to
whichever other director is in use, or by a vcl decision. I'll revisit
the previous example, with a few more comments added:

sub vcl_init {
    # sm0 and sm1 represent separate backends, with each their
    # separate trouble lists.
    new sm0 = saintmode.saintmode(b0, 10);
    new sm1 = saintmode.saintmode(b1, 10);

    new rr = directors.round_robin();

    # .backend() here returns a pointer to a 'struct director'
    # representing that specific saintmode director

sub vcl_backend_fetch {
    set bereq.backend = rr.backend();

    # the round-robin director will evaluate be->healthy() upon
    # picking a backend. The healthy() function in the selected saint
    # mode dir will then report as sick in the case that the specific
    # object is on its trouble list. The choice is then left to the
    # r-r director to pick the next healthy backend.


sub vcl_backend_response {
    if (beresp.status == 500) {
        saintmode.blacklist(20s); # equivalent of 3.0's set
beresp.saintmode = 20s
        return (retry);

    # upon retry, the offending backend (saintmode dir) will
    # report as sick.

    # .blacklist() should be a function and not an object method,
    # since when saintmode objects are used in a nested fashion like
    # here, we wouldn't be able to tell which 'sm' object to invoke
    # the .blacklist() method on.  The .blacklist() function will be able to
    # figure out which backend and hence saintmode object to use.



Dag Haavi Finstad
Software Developer | Varnish Software AS
Mobile: +47 476 64 134
We Make Websites Fly!

More information about the varnish-dev mailing list