HAProxy appsession vs cookie precedence

haproxy

I am trying to find the best solution for balancing and keeping persistence on our application behind HAProxy.

Here is our basic configuration: https://gist.github.com/endzyme/1804046b23c37beba520

After playing around with taking members down and up and also reloading the haproxy (with -sf) I have noticed that appsession isn't 100% effective, it would appear that sometimes it doesn't always 'request-learn'. I also tried to add a cookie JSESSION prefix to balance in case request-learn didn't take.

Unfortunately it would present scenarios where the prefix would list svr2 but it was balanced to a different server. I am assuming it's because the appsession table takes first then sticks on that before using the cookie parameter. I have not tested with using cookie as an inserted option (not prefix on existing cookie) but I am thinking it would yield similar results.

My question is:
Which one is checked first, appsession or cookie, and is it an immediate catch after it reads the first one, or a fall through? Also as a follow up – is it not recommended to use both in the same backend?

Cookie as I understand takes less memory resources, is agnostic to reloads and has way better reliability of persistence. Appsession I assume takes less cpu resource, since it's reading not writing.

(Bonus Question: is there a way to inspect appsession/cookie table map? socket> show table doesn't show anything except stick-tables)

Many thanks in advance,

-Nick

Best Answer

After meeting with Exceliance guys (who help develop HAProxy), I have some more information.

Didn't get a clear answer on which is checked first, but it was made clear that you should either use the cookie or use stick-tables. Both of these have methods to persist through reloads of HAProxy. They also let us know that appsession is marked for deprication and to use cookie or stick-tables with cookies. Appsession uses a hashmap in memory that isn't persisted through reloads and has some discovery mechanisms but aren't reliable.

Exceliance also mentioned that resources wouldn't be too much with cookie vs appsession. There isn't a way to inspect the map of appsession to server hash. It's more effective to use cookie and inspect the logging or cookies themselves or if you use stick-tables - socket> show tables will work for checking persistence.

Related Topic