Howtos / Articles

Sticky Session Load Balancing with HAProxy

HAProxy provides a number of methods for maintaining a record of which backend server should handle a specific connection. This is known as creating a ‘sticky’ connection (other terms for this are ‘connection persistence’ and ‘connection affinity’). HAProxy can use the source ip address, url hash, cookies, sessions (checks cookies and url parameter), headers, and more, to determine which backend server to pass the connection to.

Add one of the following lines to the HAProxy config file, in the section containing your backend servers.

Load balancing PHP sessions:

appsession PHPSESSID len 64 timeout 3h request-learn prefix

Load balancing ASP.Net sessions:

appsession ASP.NET_SessionId len 64 timeout 3h request-learn prefix

Load balancing ASP sessions:

appsession ASPSESSIONID len 64 timeout 3h request-learn prefix

Load balancing Java Server Pages sessions:

appsession JSESSIONID len 52 timeout 3h request-learn prefix

Note: You may need to modify slightly to suit your environment. I haven’t tested all of these.

For more info on sticky sessions with HAProxy, check out the HAProxy help page for the ‘appsession’ keyword:

http://code.google.com/p/haproxy-docs/wiki/appsession

See http://en.wikipedia.org/wiki/Session_ID for more details on session ID’s



Share this howto article!
  • Facebook
  • Twitter
  • Reddit
  • email

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>