Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am currently using HAProxy in front of a group if IIS .NET application servers. An unforeseen problem has arisen: I am using cookies for load-balancing, this obviously doesn't work for browser that refuses the use of cookies (given the recent changes in cookie laws in the UK, lets not go into that here tough).

This is my current HAProxy config:

listen backend-servers 127.0.0.1:80

cookie bs insert
balance roundrobin 
option persist
option redispatch
server appserver1 192.168.0.1:80 cookie bs1
server appserver2 192.168.0.2:80 cookie bs2

I don't want to re-design the application so I would like to find a way around this in HAProxy.

There are a couple of options like balancing using source IP, or a string in the URL, but can you use more than one method in HAProxy? Can you configure a fall back method or alternative method like this?

Thank you

share|improve this question

3 Answers 3

up vote 1 down vote accepted

If the cookie doesn't get saved, then haproxy dispatches based on your balance keyword only, which is roundrobin.

share|improve this answer
    
2nd time you have saved me @longneck cheers :) That is exactly what I was looking for, I have been searching the docs so not sure how I missed that! –  jwbensley Nov 2 '12 at 11:10
    
In the existing config above I thought the roundrobin option was used to balancing new connections to servers evenly, then a cookie is assigned to them to keep them persistent. If I change that to source for example all connections from the same IP will go to the same server which isn't as even for spreading the load (multiple clients behind one IP). Is my balance option ignored since I am using a cookie above and requests are balanced randomly so I can change this option without affecting; or is used for all connections whether they have a cookie or not, if so would static-rr be best? –  jwbensley Nov 2 '12 at 11:19

Direct quote from the guidelines:

There is an exception to the requirement to provide information about cookies and obtain consent where the use of the cookie is:

(a) for the sole purpose of carrying out the transmission of a communication over an electronic communications network; or

(b) where such storage or access is strictly necessary for the provision of an information society service requested by the subscriber or user.

If you're talking about a cookie for keeping you on the right server... that 100% falls into category A. If you use that same cookie for other things... then stop it.

For more info: http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/~/media/documents/library/Privacy_and_electronic/Practical_application/cookies_guidance_v3.ashx

share|improve this answer
    
Thanks for the link and snippet, most interesting! I don't run the site so ultimately I'll leave that the web admins, I'm just worried about evenly distributed the load for browser/client that either don't support or allow cookies. Still, some food for thought, thanks! –  jwbensley Nov 2 '12 at 11:22

The balance source algorithm is what you're looking for; change over from using roundrobin.

The source IP address is hashed and divided by the total weight of the running servers to designate which server will receive the request. This ensures that the same client IP address will always reach the same server as long as no server goes down or up.

share|improve this answer
    
Great thanks for the input! I am weary of trying to keep the balancing as even as possible; what do you make of my comment to longneck below about static-rr? –  jwbensley Nov 2 '12 at 11:21
    
@javano static-rr won't help to offer backend persistence to users who don't accept cookies; and you're right about the caveat of all users behind a certain IP hitting one backend. You'll need to decide which is the lesser evil - no persistence if you don't take a cookie, or possible uneven balancing due to multiple users behind a single IP. –  Shane Madden Nov 2 '12 at 16:58
    
I see, so if I set the balance algorithm to source for source IP, does this override my existing use of cookies? So all balancing will be done by source IP and the cookies won't be used anymore? The thing is, I'm after some sort of "backup" balancing method for when browsers don't support/allow cookies –  jwbensley Nov 2 '12 at 18:00
1  
@javano You'll need to select one method or the other, HAProxy won't do the "backup method for client that don't accept cookies". The complexity level of what you're talking about is quite high; even to just detect which clients need the backup behavior requires keeping track of which clients are failing to accept cookies versus which are just making their first request and haven't gotten a cookie yet. –  Shane Madden Nov 2 '12 at 19:19
    
Ah of course, I see now. Thank you! :) –  jwbensley Nov 3 '12 at 11:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.