I have a web page that works in 1 server. We are in progress to migrate to a new plattform that has 3 servers.

In first step in the migration plan we need to pass make a percent, say 10%, to the new cluster and 90% to the old server. The new plattform not needs to have sticky sessions (shares the sessions with memcached).

Is there a way to do that with haproxy?


This can be achieved by having haproxy connect to itself, giving you two tiers of load balancing.

The first listen uses the balance source option and server weights to split the traffic between your existing server and the cluster. The second tier uses balance roundrobin with no persistence to rotate incoming connection among cluster members.

    Balance source
    Server oldserver weight 90
    Server newcluster weight 10

    Balance roundrobin
    Server cluster1
    Server cluster2
    Server cluster3
  • I was looking for something similar and this seems good. I have a question, assuming there are no downtimes on backends once a client gets routed to oldserver will it continue to be routed to oldserve?. Should I configure stickiness in this setup to get that? – Fabio Jul 10 '15 at 9:25
  • You need to understand what balance source does. Once you read up on that, you will understand that a stick table is unnecessary. – longneck Jul 10 '15 at 10:41

You define weights in haproxy to spread the load according to your needs.

From the official haproxy 1.4 documentation:

weight <weight>
  The "weight" parameter is used to adjust the server's weight relative to
  other servers. All servers will receive a load proportional to their weight
  relative to the sum of all weights, so the higher the weight, the higher the
  load. The default weight is 1, and the maximal value is 256. A value of 0
  means the server will not participate in load-balancing but will still accept
  persistent connections. If this parameter is used to distribute the load
  according to server's capacity, it is recommended to start with values which
  can both grow and shrink, for instance between 10 and 100 to leave enough
  room above and below for later adjustments.

Use weight in the haproxy server section. "Weight 1 represents the lowest frequency and 256 the highest"

server newserver1 weight 3
server newserver2 weight 3
server newserver3 weight 3
server oldserver1 weight 90
  • Yup, but a session from the old server can't be share to the newserver and with this conf a user can be in the two platform in the same session. – David Sedeño Jul 4 '13 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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