5

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?

6

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.

Listen 10.0.1.1:80
    Balance source
    Server oldserver 10.0.1.10 weight 90
    Server newcluster 10.0.1.20 weight 10

Listen 10.0.1.20:80
    Balance roundrobin
    Server cluster1 10.0.1.31
    Server cluster2 10.0.1.32
    Server cluster3 10.0.1.33
  • 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
0

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.
0

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

server newserver1 192.168.1.1:80 weight 3
server newserver2 192.168.1.2:80 weight 3
server newserver3 192.168.1.3:80 weight 3
server oldserver1 192.168.2.1:80 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.