Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Varnish: Misc

Trying multiple backends for a resource

 

 

Varnish misc RSS feed   Index | Next | Previous | View Threaded


oddur at ccpgames

Aug 1, 2012, 12:04 PM

Post #1 of 5 (1186 views)
Permalink
Trying multiple backends for a resource

I´ve got multiple backends which each might have the file I´m requesting.

Would it be possible to configure varnish in such a way that is tries multiple backends and uses the first one it finds with a 200 response ?

Best regards,

Oddur Snær Magnússon
Senior Programmer | Reykjavík | Iceland

[Description: Description: Description: Description: cid:DB5C0F43-387B-4CF8-BC6F-B17512BB8251 [at] ccp]

:wq
Attachments: image001.png (10.1 KB)


hugo.cisneiros at gmail

Aug 1, 2012, 1:04 PM

Post #2 of 5 (1159 views)
Permalink
Re: Trying multiple backends for a resource [In reply to]

On Wed, Aug 1, 2012 at 4:04 PM, Oddur Snær Magnússon <oddur [at] ccpgames> wrote:
> I´ve got multiple backends which each might have the file I´m requesting.
>
> Would it be possible to configure varnish in such a way that is tries multiple backends and uses the first one it finds with a 200 response ?

Maybe using restarts...

sub vcl_recv {
if (req.http.fallbackmarker) {
if (req.restarts == 1) {
set req.backend = backend_one;
} elsif (req.restarts == 2) {
set req.backend = backend_two;
} elsif (req.restarts == 3) {
set req.backend = backend_two;
}
[...]
}
}

sub vcl_fetch {
if (req.url == "/file.ext" && beresp.status != 200) {
set req.http.fallbackmarker = 1;
return (restart);
}
}

And setting option max_restarts to the number of backends you may use.

--
[]'s
Hugo
www.devin.com.br

_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc


oddur at ccpgames

Aug 2, 2012, 4:55 AM

Post #3 of 5 (1159 views)
Permalink
RE: Trying multiple backends for a resource [In reply to]

Seems like the fallback director is what I want, if I can get it to try to continue trying on 404.
I could possibly map 404 to 503(temp unavailable)

https://www.varnish-cache.org/docs/trunk/reference/vcl.html#the-fallback-director

From: rzuidhof [at] gmail [mailto:rzuidhof [at] gmail] On Behalf Of Richard Zuidhof
Sent: Wednesday, August 01, 2012 7:26 PM
To: Oddur Snær Magnússon
Subject: Re: Trying multiple backends for a resource


No problem at all.
Op 1 aug. 2012 21:06 schreef "Oddur Snær Magnússon" <oddur [at] ccpgames<mailto:oddur [at] ccpgames>> het volgende:
I´ve got multiple backends which each might have the file I´m requesting.

Would it be possible to configure varnish in such a way that is tries multiple backends and uses the first one it finds with a 200 response ?

Best regards,

Oddur Snær Magnússon
Senior Programmer | Reykjavík | Iceland

[Description: Description: Description: Description: cid:DB5C0F43-387B-4CF8-BC6F-B17512BB8251 [at] ccp]

:wq


_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache<mailto:varnish-misc [at] varnish-cache>
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Attachments: image001.png (10.1 KB)


enno at tty

Aug 2, 2012, 6:37 AM

Post #4 of 5 (1155 views)
Permalink
Re: Trying multiple backends for a resource [In reply to]

On 08/02/2012 01:55 PM, Oddur Snær Magnússon wrote:
>
> Seems like the fallback director is what I want, if I can get it to
> try to continue trying on 404.
>
> I could possibly map 404 to 503(temp unavailable)
>
> https://www.varnish-cache.org/docs/trunk/reference/vcl.html#the-fallback-director
>
>
the fallback director means that your secondairy backends don't get any
requests, unless the first backend is unhealthy. I'm not sure if that's
what you want.

I'm using the following setup to allow retries on different backends:

director cluster1 random {
{ .backend = backend1; .weight = 10; }
{ .backend = backend2; .weight = 10; }
...
}

sub vcl_recv {
...
set req.backend = cluster1;
...
}

sub vcl_fetch {
if (! beresp.cacheable) {
if (beresp.status == 404 || beresp.status == 500 ||
beresp.status == 503) {
if (req.restarts < 3) {
return (restart);
}
}
return (pass);
}

return (deliver);
}

Enno


apj at mutt

Aug 2, 2012, 6:45 AM

Post #5 of 5 (1153 views)
Permalink
Re: Trying multiple backends for a resource [In reply to]

On Wed, Aug 01, 2012 at 07:04:50PM +0000, Oddur Snær Magnússon wrote:
>
> Would it be possible to configure varnish in such a way that is tries
> multiple backends and uses the first one it finds with a 200 response ?

Use saint mode and restarts.
Remember to set saintmode_threshold to something appropriate though.

--
Andreas

_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc

Varnish misc RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.