0

I'm trying to make a simple load balancing using haProxy. My config:

global
log /dev/log   local0
log 127.0.0.1   local1 notice
maxconn 200000
user haproxy
group haproxy
daemon

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    option redispatch
    maxconn 200000
    timeout connect     5000
    timeout client     50000
    timeout server     50000
frontend front
    bind *:80
    mode http
    default_backend back

backend back
    mode http
    balance roundrobin
    option httpclose
    option forwardfor
    server webserver01 127.0.0.1:5001 check
    server webserver02 127.0.0.1:5002 check
    server webserver03 127.0.0.1:5003 check
    server webserver04 127.0.0.1:5004 check
    server webserver05 127.0.0.1:5005 check
    server webserver06 127.0.0.1:5006 check

listen sts *:1936
    mode http
    stats enable
    stats uri /

And I have a six instances of Flask, each on diffrent port according to config.

In Flask function is only time.sleep(5) and return.

When I opening the haproxy IP in browser - it's working - I have the roundrobin strategy working.

But when I opening 3 or more pages with this IP I received strange situation. I think that haProxy should redirect traffic to one of my Flask instances but when I open first time this IP in browser and I'm waiting for response (sleep in Flask) and open second page, the second page will be loaded when first is loaded + 5 seconds (time.sleep). And the third page is similar - it will be loaded when second is loaded + 5 seconds.

I think that this is not valid beacuse when haProxy redirect traffic from one request to one instance of Flask and second request to second instance - this requests should be seperated from each other.. I should have response from each request in 5 second. Not in 5, 10, 15, 20..

Could someone help me with it?

Best regards, Matt.

user3025978
  • 477
  • 2
  • 8
  • 27
  • Have you looked into [this one](http://serverfault.com/questions/580142/haproxy-tcp-roundrobin-loadbalancing-not-working-as-expected)? – Hang Mar 25 '16 at 20:36
  • @Hang I have changed the strategy to leastconn but it's still not working as expected – user3025978 Mar 25 '16 at 21:03
  • I think that the haProxy is waiting for response from last request.. But it's not good.. – user3025978 Mar 25 '16 at 21:07
  • I copied your haproxy config, running 6 tornado backend (I'm not familiar with flask), with time.sleep(5) in the response. Then I launched requests simultaneously, it took 5 seconds to finish all requests if total number of requests are 6 or less, and once I added 7th request the overall time reach to 10s. How did you do the test? If you are doing that through browser, I got impression most browsers will allow at most 2 concurrent request to the same server. – Hang Mar 25 '16 at 21:37
  • Yes, I was using browser.. I test it with curl and all is working like a charm! I would be very grateful if you could write an answer and give some more information about this request limiting in browsers. I will accept it – user3025978 Mar 25 '16 at 21:49

1 Answers1

2

Most browsers limit number of parallel connection to the same server, if you are testing through a browser that may be the case.

More details can be found in this question: Max parallel http connections in a browser?

Community
  • 1
  • 1
Hang
  • 387
  • 1
  • 6