varnish as traffic director

Robert Shilston rtshilston at gmail.com
Thu Mar 31 14:53:49 CEST 2011


> 
> On 30.03.11 04:52, "AD" <straightflush at gmail.com> wrote:
> 
>> sub vcl_recv { 
>> if (req.url ~ "^/search") {
>>   set req.backend = search-backend;
>> }
>> elseif (req.url ~ "^/items") {
>>   set req.backend = items-backend;
>> }
>> 
>> }
> 
> By the way, would it also be okay to write it like that?
> 
> sub vcl_recv {
> 
> set req.backend =  catchall-backend;
> 
> 
> if (req.url ~ "^/search") {
>    set req.backend = search-backend;
>  }
> if (req.url ~ "^/items") {
>    set req.backend = items-backend;
>  }
> 
> }


Logically it's ok.  But, it's probably slightly better in terms of efficiency to use an elseif pattern.  This is you'll do the first pattern match (/search) on every request, and then you'll also do the pattern match for items, even if you'd already matched to /search.  Two pattern matches rather than one is undesirable, and even more so if you ended up having lots and lots of matches to do.


Rob




More information about the varnish-misc mailing list