HAProxy Session affinity for PHP web application
Hi, I've setup HAProxy to loadbalance the traffic across two web servers that runs some PHP website (based on JOOMLA, OSCommerce and some other solution) However I've noticed that the session affinity is not working Out Of The BOX (which after 2sec of think is quite logical ;)) Does anybody have some pointers to configure HAProxy (and if necessary PHP) to make this work ? Thanks, Thomas.
Re: HAProxy Session affinity for PHP web application
this is not an HAProxy related problem What you need is to share the session across all webservers. You have several ways to do it: memcache, redis, db, filesystem. We currently are using memcache for this check your php.ini for session.save_handler we have something like: session.save_handler = memcache session.save_path = tcp://mmc-server-01:11211,tcp://mmc-server-02:11211 some more info: http://php.net/manual/en/session.configuration.php Once you do this, haproxy will keep using the same algorithm to balance but webservers will be able to find/reuse the session users were on. Saludos On Fri, Mar 11, 2011 at 11:37 AM, Thomas Manson dev.mansontho...@gmail.comwrote: Hi, I've setup HAProxy to loadbalance the traffic across two web servers that runs some PHP website (based on JOOMLA, OSCommerce and some other solution) However I've noticed that the session affinity is not working Out Of The BOX (which after 2sec of think is quite logical ;)) Does anybody have some pointers to configure HAProxy (and if necessary PHP) to make this work ? Thanks, Thomas. -- Gabriel Sosa Si buscas resultados distintos, no hagas siempre lo mismo. - Einstein
Re: HAProxy Session affinity for PHP web application
Hi Gabriel, I've read that HAProxy is capable of keeping a set of http request directed to the same webserver. (I think the feature is called 'Sticky Session' on Websphere Cluster) I've seen this in the documentation : appsession cookie len length timeout holdtime [request-learn] [prefix] [mode path-parameters|query-string] * Define session stickiness on an existing application cookie.* I'm just looking for some howto/best practices on this subject. Also the shared session with memcache can be a valid option. (I've to dig this subject). So, can anyone confirm that it's possible or not possible to have a sticky session feature with HAProxy ? If possible : howto/best practice? If not : well I'll try the memcache solution ;) Thanks for your help, Regards, Thomas. On Fri, Mar 11, 2011 at 16:19, Gabriel Sosa sosagabr...@gmail.com wrote: this is not an HAProxy related problem What you need is to share the session across all webservers. You have several ways to do it: memcache, redis, db, filesystem. We currently are using memcache for this check your php.ini for session.save_handler we have something like: session.save_handler = memcache session.save_path = tcp://mmc-server-01:11211,tcp://mmc-server-02:11211 some more info: http://php.net/manual/en/session.configuration.php Once you do this, haproxy will keep using the same algorithm to balance but webservers will be able to find/reuse the session users were on. Saludos On Fri, Mar 11, 2011 at 11:37 AM, Thomas Manson dev.mansontho...@gmail.com wrote: Hi, I've setup HAProxy to loadbalance the traffic across two web servers that runs some PHP website (based on JOOMLA, OSCommerce and some other solution) However I've noticed that the session affinity is not working Out Of The BOX (which after 2sec of think is quite logical ;)) Does anybody have some pointers to configure HAProxy (and if necessary PHP) to make this work ? Thanks, Thomas. -- Gabriel Sosa Si buscas resultados distintos, no hagas siempre lo mismo. - Einstein
Re: HAProxy Session affinity for PHP web application
Hi Thomas, We do it like this, haproxy add a cookie, and base on the cookie it will send it to teh same web server I'm no haproxy expert but it work for us with a very basic php application. here are the related config in our haproxy backend bk-prod balanceroundrobin cookie SERVERID insert indirect nocache server lb10-3w-101 172.21.11.101:80 cookie lb11-3w-101 check inter 5s fall 3 maxconn 200 weight 20 server lb10-3w-102 172.21.11.102:80 cookie lb11-3w-102 check inter 5s fall 3 maxconn 200 weight 20 This will load balance in a round robin way but a second pass from the same visitor will end up on the same server which will do what you want. Good luck ! 2011/3/11 Thomas Manson dev.mansontho...@gmail.com Hi Gabriel, I've read that HAProxy is capable of keeping a set of http request directed to the same webserver. (I think the feature is called 'Sticky Session' on Websphere Cluster) I've seen this in the documentation : appsession cookie len length timeout holdtime [request-learn] [prefix] [mode path-parameters|query-string] * Define session stickiness on an existing application cookie.* I'm just looking for some howto/best practices on this subject. Also the shared session with memcache can be a valid option. (I've to dig this subject). So, can anyone confirm that it's possible or not possible to have a sticky session feature with HAProxy ? If possible : howto/best practice? If not : well I'll try the memcache solution ;) Thanks for your help, Regards, Thomas. On Fri, Mar 11, 2011 at 16:19, Gabriel Sosa sosagabr...@gmail.com wrote: this is not an HAProxy related problem What you need is to share the session across all webservers. You have several ways to do it: memcache, redis, db, filesystem. We currently are using memcache for this check your php.ini for session.save_handler we have something like: session.save_handler = memcache session.save_path = tcp://mmc-server-01:11211,tcp://mmc-server-02:11211 some more info: http://php.net/manual/en/session.configuration.php Once you do this, haproxy will keep using the same algorithm to balance but webservers will be able to find/reuse the session users were on. Saludos On Fri, Mar 11, 2011 at 11:37 AM, Thomas Manson dev.mansontho...@gmail.com wrote: Hi, I've setup HAProxy to loadbalance the traffic across two web servers that runs some PHP website (based on JOOMLA, OSCommerce and some other solution) However I've noticed that the session affinity is not working Out Of The BOX (which after 2sec of think is quite logical ;)) Does anybody have some pointers to configure HAProxy (and if necessary PHP) to make this work ? Thanks, Thomas. -- Gabriel Sosa Si buscas resultados distintos, no hagas siempre lo mismo. - Einstein -- Guillaume Bourque, B.Sc., consultant, infrastructures technologiques libres Logisoft Technologies inc. http://www.logisoftech.com 514 576-7638, http://ca.linkedin.com/in/GuillaumeBourque/fr
Re: HAProxy Session affinity for PHP web application
Ok that's exactly what I wanted to do. The default cookie name in PHP is session.name = PHPSESSID Is it this cookie name that I should set in HAProxy config ? Thomas. On Fri, Mar 11, 2011 at 4:55 PM, Guillaume Bourque guillaume.bour...@gmail.com wrote: Hi Thomas, We do it like this, haproxy add a cookie, and base on the cookie it will send it to teh same web server I'm no haproxy expert but it work for us with a very basic php application. here are the related config in our haproxy backend bk-prod balanceroundrobin cookie SERVERID insert indirect nocache server lb10-3w-101 172.21.11.101:80 cookie lb11-3w-101 check inter 5s fall 3 maxconn 200 weight 20 server lb10-3w-102 172.21.11.102:80 cookie lb11-3w-102 check inter 5s fall 3 maxconn 200 weight 20 This will load balance in a round robin way but a second pass from the same visitor will end up on the same server which will do what you want. Good luck ! 2011/3/11 Thomas Manson dev.mansontho...@gmail.com Hi Gabriel, I've read that HAProxy is capable of keeping a set of http request directed to the same webserver. (I think the feature is called 'Sticky Session' on Websphere Cluster) I've seen this in the documentation : appsession cookie len length timeout holdtime [request-learn] [prefix] [mode path-parameters|query-string] * Define session stickiness on an existing application cookie.* I'm just looking for some howto/best practices on this subject. Also the shared session with memcache can be a valid option. (I've to dig this subject). So, can anyone confirm that it's possible or not possible to have a sticky session feature with HAProxy ? If possible : howto/best practice? If not : well I'll try the memcache solution ;) Thanks for your help, Regards, Thomas. On Fri, Mar 11, 2011 at 16:19, Gabriel Sosa sosagabr...@gmail.comwrote: this is not an HAProxy related problem What you need is to share the session across all webservers. You have several ways to do it: memcache, redis, db, filesystem. We currently are using memcache for this check your php.ini for session.save_handler we have something like: session.save_handler = memcache session.save_path = tcp://mmc-server-01:11211,tcp://mmc-server-02:11211 some more info: http://php.net/manual/en/session.configuration.php Once you do this, haproxy will keep using the same algorithm to balance but webservers will be able to find/reuse the session users were on. Saludos On Fri, Mar 11, 2011 at 11:37 AM, Thomas Manson dev.mansontho...@gmail.com wrote: Hi, I've setup HAProxy to loadbalance the traffic across two web servers that runs some PHP website (based on JOOMLA, OSCommerce and some other solution) However I've noticed that the session affinity is not working Out Of The BOX (which after 2sec of think is quite logical ;)) Does anybody have some pointers to configure HAProxy (and if necessary PHP) to make this work ? Thanks, Thomas. -- Gabriel Sosa Si buscas resultados distintos, no hagas siempre lo mismo. - Einstein -- Guillaume Bourque, B.Sc., consultant, infrastructures technologiques libres Logisoft Technologies inc. http://www.logisoftech.com 514 576-7638, http://ca.linkedin.com/in/GuillaumeBourque/fr
Re: HAProxy Session affinity for PHP web application
Thomas, This post really made me smile :-). HAProxy allows: non-sticky Source IP Hash Source IP Stick table Cookie (self managed self inserted transparent etc.) Cookie (based on reading the web servers session cookie) If your web server(s) are scalable i.e. handles their own sessions in a SHARED backend database or memcache then you don't need ANY sticky on the load balancer. Any form of sticky on the load balancer means that a single server failure will break your users session (which may not be a major problem) If your app handles its own state then any server failure doesn't really matter. For your case I would go with: Cookie (self managed self inserted transparent etc.) As suggested by the previous example config. On 11 March 2011 15:44, Thomas Manson dev.mansontho...@gmail.com wrote: Hi Gabriel, I've read that HAProxy is capable of keeping a set of http request directed to the same webserver. (I think the feature is called 'Sticky Session' on Websphere Cluster) So, can anyone confirm that it's possible or not possible to have a sticky session feature with HAProxy ? If possible : howto/best practice? If not : well I'll try the memcache solution ;) -- Regards, Malcolm Turnbull. Loadbalancer.org Ltd. Phone: +44 (0)870 443 8779 http://www.loadbalancer.org/
Re: HAProxy Session affinity for PHP web application
Thomas, I'm no expert here and In our case we don't truss the application ;-) So the proposed config will insert a cookie base on the name of the web server for us (put anything you want) and a returning visitor will end on the same backend base on the haproxy cookie previously inserted. Now I'm sure haproxy can intercept the application cookie and send it to the same server, but you will have to test that and look at the doc ;-) Also in haproxy log you will have all the info for each session, where it was balance and if a cookie was present or inserted ... From the doc in the log section search for this: the third character tells whether the persistence cookie was provided by the client (only in HTTP mode) Good luck 2011/3/11 Manson Thomas mansontho...@gmail.com Ok that's exactly what I wanted to do. The default cookie name in PHP is session.name = PHPSESSID Is it this cookie name that I should set in HAProxy config ? Thomas. On Fri, Mar 11, 2011 at 4:55 PM, Guillaume Bourque guillaume.bour...@gmail.com wrote: Hi Thomas, We do it like this, haproxy add a cookie, and base on the cookie it will send it to teh same web server I'm no haproxy expert but it work for us with a very basic php application. here are the related config in our haproxy backend bk-prod balanceroundrobin cookie SERVERID insert indirect nocache server lb10-3w-101 172.21.11.101:80 cookie lb11-3w-101 check inter 5s fall 3 maxconn 200 weight 20 server lb10-3w-102 172.21.11.102:80 cookie lb11-3w-102 check inter 5s fall 3 maxconn 200 weight 20 This will load balance in a round robin way but a second pass from the same visitor will end up on the same server which will do what you want. Good luck ! 2011/3/11 Thomas Manson dev.mansontho...@gmail.com Hi Gabriel, I've read that HAProxy is capable of keeping a set of http request directed to the same webserver. (I think the feature is called 'Sticky Session' on Websphere Cluster) I've seen this in the documentation : appsession cookie len length timeout holdtime [request-learn] [prefix] [mode path-parameters|query-string] * Define session stickiness on an existing application cookie.* I'm just looking for some howto/best practices on this subject. Also the shared session with memcache can be a valid option. (I've to dig this subject). So, can anyone confirm that it's possible or not possible to have a sticky session feature with HAProxy ? If possible : howto/best practice? If not : well I'll try the memcache solution ;) Thanks for your help, Regards, Thomas. On Fri, Mar 11, 2011 at 16:19, Gabriel Sosa sosagabr...@gmail.comwrote: this is not an HAProxy related problem What you need is to share the session across all webservers. You have several ways to do it: memcache, redis, db, filesystem. We currently are using memcache for this check your php.ini for session.save_handler we have something like: session.save_handler = memcache session.save_path = tcp://mmc-server-01:11211,tcp://mmc-server-02:11211 some more info: http://php.net/manual/en/session.configuration.php Once you do this, haproxy will keep using the same algorithm to balance but webservers will be able to find/reuse the session users were on. Saludos On Fri, Mar 11, 2011 at 11:37 AM, Thomas Manson dev.mansontho...@gmail.com wrote: Hi, I've setup HAProxy to loadbalance the traffic across two web servers that runs some PHP website (based on JOOMLA, OSCommerce and some other solution) However I've noticed that the session affinity is not working Out Of The BOX (which after 2sec of think is quite logical ;)) Does anybody have some pointers to configure HAProxy (and if necessary PHP) to make this work ? Thanks, Thomas. -- Gabriel Sosa Si buscas resultados distintos, no hagas siempre lo mismo. - Einstein -- Guillaume Bourque, B.Sc., consultant, infrastructures technologiques libres Logisoft Technologies inc. http://www.logisoftech.com 514 576-7638, http://ca.linkedin.com/in/GuillaumeBourque/fr -- Guillaume Bourque, B.Sc., consultant, infrastructures technologiques libres Logisoft Technologies inc. http://www.logisoftech.com 514 576-7638, http://ca.linkedin.com/in/GuillaumeBourque/fr