Varnish load balancer & (keep session)

Reinis Rozitis r at roze.lv
Mon Feb 8 16:12:09 CET 2010


While this might be somewhat "hammering" backends (in case something goes totally wrong) we have ironed out a lot (if not all) 503 
errors just by rerequesting the objects (in our case usually a static image) which get the 503 response by adding this:

sub vcl_error {
        if (obj.status == 503 && req.restarts < 4) {
                restart;
        }
}



rr


----- Original Message ----- 
From: "Rob S"

> Just to copy in the list... the problem Axel was seeing is one that
> troubled us for a bit - getting unexpected 503 responses.
>
> Solution: Make sure the top of "sub vcl_recv" has a default backend:
>
> set req.backend = xxx;
>
> You can override this later with conditional statements, or whatever,
> but having a default helps prevent 503s.
>
>
> Rob
>
>
> Axel DEAU wrote:
>> Hi,
>>
>> It seems that with this method it works very well I thanks you a lot for your help and wich you have a nice day
>>
>> Best regard
>>
>> Axel DEAU | NOVACTIVE SYTEME
>>
>> Administrateur Systeme et Reseaux
>> mail : a.deau at novactive-systemes.com
>> Tel : + 33 1 48 24 33 60
>> Fax : + 33 1 48 24 33 54
>> www.novactive.com
>>
>>
>> -----Message d'origine-----
>> De : Rob S [mailto:rtshilston at gmail.com]
>> Envoyé : lundi 8 février 2010 11:50
>> À : Axel DEAU
>> Cc : Sacha MILADINOVIC
>> Objet : Re: Varnish load balancer & (keep session)
>>
>> At the very top of "sub vcl_recv", please add:
>>
>> set req.backend = b1;
>>
>> This will set the default backend.
>>
>> Can you also send me the output of
>>
>> # varnishlog |grep Backend_health
>>     0 Backend_health - server7 Still healthy 4--X-S-RH 10 8 10 0.007498
>> 0.009539 HTTP/1.1 200 OK
>>     0 Backend_health - server2 Still healthy 4--X-S-RH 10 8 10 0.006767
>> 0.013814 HTTP/1.1 200 OK
>>     0 Backend_health - server3 Still healthy 4--X-S-RH 10 8 10 0.012027
>> 0.010841 HTTP/1.1 200 OK
>>
>> from before and after you stop apache on the first and second backends.
>>
>>
>> Rob
>>
>>
>> Axel DEAU wrote:
>>
>>> Hi,
>>>
>>> Absolutely
>>>
>>> Axel DEAU | NOVACTIVE SYTEME
>>>
>>> Administrateur Systeme et Reseaux
>>> mail : a.deau at novactive-systemes.com
>>> Tel : + 33 1 48 24 33 60
>>> Fax : + 33 1 48 24 33 54
>>> www.novactive.com
>>>
>>>
>>> -----Message d'origine-----
>>> De : Rob S [mailto:rtshilston at gmail.com]
>>> Envoyé : lundi 8 février 2010 10:24
>>> À : Axel DEAU
>>> Cc : Sacha MILADINOVIC
>>> Objet : Re: Varnish load balancer & (keep session)
>>>
>>> Axel,
>>>
>>> Can you post your entire VCL, and I'll see why this is happening.
>>>
>>> Rob
>>>
>>> Axel DEAU wrote:
>>>
>>>
>>>> Hi Rob,
>>>>
>>>> Thanks for the reply, for 1) when I shut down the second backend all the traffic goes to the first backend but,
>>>> When I shut down the first backend even if the second backend mark "Still healthy" the error 503 appears.
>>>>
>>>> For the other point I'm agreed with you...
>>>>
>>>> -----Message d'origine-----
>>>> De : Rob S [mailto:rtshilston at gmail.com]
>>>> Envoyé : dimanche 7 février 2010 13:33
>>>> À : Axel DEAU
>>>> Cc : varnish-misc at projects.linpro.no
>>>> Objet : Re: Varnish load balancer & (keep session)
>>>>
>>>> Hi,
>>>>
>>>> To answer some of your questions:
>>>>
>>>> 1) 503 error when shutting down a backend:  When you shutdown the
>>>> backend, do you see varnishlog say that the backend is healthy or sick?
>>>> If one is sick, then the other should get the traffic if your VCL
>>>> contains set req.backend = b1;
>>>>
>>>> 2) Vanish load balanced does not keep e-commerce sessions for PHP.  The
>>>> simplest solution to this is to install memcache, and put the following
>>>> lines in your php.ini file:
>>>>
>>>> [Session]
>>>> session.save_handler = memcached
>>>> session.save_path = "memcache-server1:11211,memcache-server2:11211"
>>>>
>>>> instead of session.save_handler = files
>>>>
>>>> However, I can't say for certain that this will definitely work - it
>>>> depends on how your ecommerce application operates.
>>>>
>>>> 3) S-flag: I'm not sure about this, but my gut feeling is that it's not
>>>> causing the problems you're seeing.
>>>>
>>>>
>>>>
>>>> Rob
>>>>
>>>>
>>>> Axel DEAU wrote:
>>>>
>>>>
>>>>
>>>>> Version: 2.0.6-1
>>>>>
>>>>> Insall: .deb
>>>>>
>>>>> Os: Debian 5.0.3
>>>>>
>>>>> Hi,
>>>>>
>>>>> I've got two backends running apache2: front1.domain.com &
>>>>> front2.domain.com, set with the load balancing configuration
>>>>> from http://varnish-cache.org/wiki/LoadBalancing.
>>>>>
>>>>> _The issue is, when I shutdown apache2 of the first backend varnish
>>>>> don't switch to the second and display "Error 503 Service
>>>>> Unavailable", is that a normal answer from varnish?_
>>>>>
>>>>> Other question, _does varnish load balancer keep php sessions, if yes
>>>>> how will I do?_
>>>>>
>>>>> Varnishlog :
>>>>>
>>>>> 0 Backend_health - front1 Still healthy 4--X-RH 10 8 10 0.040008
>>>>> 0.039814 HTTP/1.1 200 OK
>>>>>
>>>>> 0 Backend_health - front2 Still healthy 4--X-RH 10 8 10 0.066948
>>>>> 0.066591 HTTP/1.1 200 OK
>>>>>
>>>>> The S flag is missing in my log, is that an issue…
>>>>>
>>>>> "4--X-S-RH" to notify that TCP socket shutdown succeeded
>>>>> from http://varnish-cache.org/wiki/BackendPolling
>>>>>
>>>>> Part of default.vcl
>>>>>
>>>>> backend front1 {
>>>>>
>>>>>   .host = "front1.domain.com";
>>>>>
>>>>>   .port = "80";
>>>>>
>>>>>   .probe = { .url = "/";
>>>>>
>>>>>              .interval = 10s;
>>>>>
>>>>>              .timeout = 5s;
>>>>>
>>>>>              .window = 10;
>>>>>
>>>>>              .threshold = 8;
>>>>>
>>>>>  }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> backend front2 {
>>>>>
>>>>>   .host = "front2.domain.com";
>>>>>
>>>>>   .port = "80";
>>>>>
>>>>>   .probe = { .url = "/";
>>>>>
>>>>>              .interval = 10s;
>>>>>
>>>>>              .timeout = 5s;
>>>>>
>>>>>              .window = 10;
>>>>>
>>>>>              .threshold = 8;
>>>>>
>>>>>  }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> director b1 random
>>>>>
>>>>> {
>>>>>
>>>>>    { .backend = front1; .weight = 5; }
>>>>>
>>>>>    { .backend = front2; .weight = 1; }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> #director b1 round-robin {
>>>>>
>>>>> #    { .backend = front1; }
>>>>>
>>>>> #    { .backend = front2; }
>>>>>
>>>>> #}
>>>>>
>>>>> Thanks for your help...
>>>>>
>>>>> ------------------------------------------------------------------------
>>>>>
>>>>> _______________________________________________
>>>>> varnish-misc mailing list
>>>>> varnish-misc at projects.linpro.no
>>>>> http://projects.linpro.no/mailman/listinfo/varnish-misc
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at projects.linpro.no
> http://projects.linpro.no/mailman/listinfo/varnish-misc
> 



More information about the varnish-misc mailing list