vcl_error restart

Darryl Dixon - Winterhouse Consulting darryl.dixon at
Mon Jun 22 23:41:27 CEST 2009

Hi Le Roux,

I investigated doing something similar with Varnish a little while ago
when the backend health checks were first included. I decided at the time
that it couldn't achieve what I wanted, so I left that functionality
inside the Pound config one layer down. The way we do this is with Pound's
HAPort directive plus its Emergency Backend.

Thus, Varnish sends all traffic regularly to Pound, and then Pound onwards
to your regular Django webapp. Pound monitors the health of your Django
webapp with connections to an 'HAPort' that you control (all it has to do
is accept connections and close them straight away to indicate that the
Django webapp is working). When you want to restart Django, you first shut
down the HAPort, then afterward shut down/restart Django. Once it's up
again the HAPort is restarted. You can probably automate this (we did with

The key is that when Pound detects that the HAPort goes down, it wants to
send the traffic somewhere, so you specify an 'Emergency' backend (backend
of last resort) which points to your custom cache server. While the HAPort
is down, all traffic will go there.

Hope this helps or gives you some ideas anyway.

Darryl Dixon
Winterhouse Consulting Ltd

> I'm trying to setup varnish so that it will try one backend and then
> if there's an error (for example - the backend isn't up at all - not
> even throwing 500 errors), it tries a fallback backend. I'm trying to
> get varnish to immediately try another backend if I restart my app. So
> the first backend is my django powered web app and the second one is a
> smaller, dumb one that just tries to read from a cache that I manage.
> I only want to use this cache as a fallback - it isn't a max-age based
> thing.
> I think backend polling isn't perfect here - I don't want requests to
> die for seconds before health polling figures it out - the app will be
> restarted within seconds already anyway. I also don't want to use the
> grace functionality here - this is only for non-cacheable (not by
> varnish, anyway) web app urls that need to be re-evaluated all the
> time. (I'm thinking of sending static, cacheable urls to a third
> backend - a traditional webserver)
> So basically, I want to do something like this:
> backend b1 {
>     .host = "localhost";
>     .port = "8000";
> }
> backend b2 {
>     .host = "localhost";
>     .port = "8001";
> }
> sub vcl_recv {
>     if (req.restarts == 0) {
>         set req.backend = b1;
>     } else {
>         set req.backend = b2;
>     }
> }
> sub vcl_error {
>     if (req.restarts == 0) {
>         set req.backend = b2;
>         restart;
>     }
> }
> But my second backend never gets a request. Is this possible? Has
> anyone done something like this before?
> Le Roux
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at

More information about the varnish-misc mailing list