4

I want to load balance web requests with HAProxy. The catch is that I want particular groups of users to always go to the same server. (This is a multiplayer system, and users in the same group need to be on the same server). The users can go to any server, as long as the users with the same group id are on the same server. The server can even change (for example if a server goes down) but then all users of that group must switch to a new server. The app server will identify the user's grouping with a cookie.

As a specific example, suppose my application has a cookie GROUP_ID numbered 1..10000. There might be 3 different users with GROUP_ID=1, a different 3 users with GROUP_ID=2, etc. And let's assume I set up load balancing on servers: app1, app2, app3.

What I'd like to see is something similar to this:

  • all GROUP_ID=1 users go to app1
  • all GROUP_ID=2 users go to app2
  • all GROUP_ID=3 users go to app3
  • all GROUP_ID=4 users go to app1
  • all GROUP_ID=5 users go to app2

etc.

If server app1 becomes unresponse, then I want to see the app1 users redistributed among app2 and app3. (It'd be ok if all groups were reshuffled). All users from a particular group should still be on a common server.

Obviously the initial request to the site will not have a cookie, but once the user authenticates they will be assigned the cookie.

Is this kind of custom load balancing supported by HAProxy?

1 Answer 1

2
+150

1) Setup a HAPROXY frontend, with:

  • a dedicated backend for your authentication (login into the game). When you authenticate, you set a cookie called 'GROUPID'. (ie: GROUPID=GID3) for that http connection. (note: you can also pass that 'groupid' as an argument to an URL and/or set expiry time, etc..)

  • a dedicated backend for your game servers, with the following directive:

    cookie GROUPID insert indirect nocache

2) setup your servers (in the backend) as (note: check section can be removed):

server APP01 10.0.0.5:80 cookie GID3 check inter 5000 rise 2 fall 3 maxconn 2048

server APP02 10.0.0.6:80 cookie GID4 check inter 5000 rise 2 fall 3 maxconn 2048

(...)

For further reference, the documentation of HAPROXY is quite explicit (http://haproxy.1wt.eu/download/1.4/doc/configuration.txt)

1
  • 2
    so I ended up using the new "stick-table" features in 1.5 which is much more powerful. This hashes the cookie and always keeps the users with the same cookie together. You can use the "show table" command to see all the mappings.
    – Will Glass
    Apr 1, 2013 at 8:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .