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

We are working on an HTTP webservice load-balanced using haproxy. The webservice is accessed via SSL. It is a RESTful HTTP service and simply accepts JSON, does some work, and returns JSON. There is no notion of a session.

We have redundant load-balancers set up in front of a pair of redundant webservice servers. Each server sits behind Apache, where Apache is used as a proxy in order to handle SSL and logging. If it matters, our webservice is a Clojure (java) application using compojure (jetty) to handle HTTP.

This is a brief diagram showing the path of a client request through our existing system.

client request -> haproxy (load balancing) -> apache (ssl, logging) -> webservice

We would like any connection to the load-balancer to establish a persistent connection and then be served by the same server for all subsequent requests sent through that persistent connection. In other words, we don't want a persistent connection to haproxy making requests to more than one webservice server.

How would you recommend that we get this working? How can we "pin" a given connection to the load-balancer to a specific webservice server? How could we prevent accidentally loading down a specific webservice server with multiple intensive requests?

share|improve this question
    
I think the general term you are looking for here is "sticky session". –  Jeremy Oct 26 '11 at 18:09

2 Answers 2

You're looking for HAProxy's cookie directive, which will ensure that clients stick to the same backend.

As far as avoiding overloading a given backend, you'll be completely dependent on the initial load balancing - moving clients to a different server mid-session doesn't fit with session persistence being enforced from the load balancer. If the load issue is a big one, then maybe reconsider having HAProxy do session persistence, keeping a centralized session state among the backends instead?

share|improve this answer
    
Hi, thanks. A cookie won't be useful in this case because the webservice does not interact with browsers and is sessionless. –  jkndrkn Nov 14 '11 at 20:30
up vote 0 down vote accepted

Using balance source in the defaults block, along with removing option httpclose entries did the trick.

share|improve this answer

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.