How to use thousands of backends in haproxy? Is the new map feature useful for this?

I want to use haproxy as a proxy and load balancer for thousands of backends. Thus, the request must be proxied to the correct backend depending on the host name, and then balance the load in the backend. I am using haproxy-1.5dev21.

The configuration file is as follows:

frontend public bind :80 mode http acl host1 hdr_reg(host) host1.com use_backend be_host1 if host1 acl host4000 hdr_reg(host) host4000.com use_backend be_host4000 if host4000 backend be_host[n] server hostn_1 server hostn_2 

The problem is that I get an additional 30 ms delay per request if there are 5,000 hosts. And for 20k backends, haproxy takes a lot of time to load, not to mention the latency crash for each request.

Can I do something better than consecutive acl rules? I did not find an example for the new map function - the release notes say that it can be used for mass forwarding rules. I tried this:

 use_backend %[hdr(host), map(host_to_backend_map.file)] 

Something is clearly stupidly higher when using maps, but any guidance would be helpful. Thanks!

+8
reverse-proxy load-balancing haproxy
source share
2 answers

Some flaws were removed from the configuration file after entering the expert, and I listed them here, in case someone else might be useful.

  • Use hdr (host) instead of hdr_reg () . This greatly improves the time spent evaluating ACLs. Better yet, avoid acl and use the built-in evaluation, for example.

    use_backend host1 if { req.fhdr(host,1) -m str host1.domain.com }

  • Use nbproc> 1 . In the case of simultaneous connections, this helps. Although this makes debugging difficult.

  • For the backend, use the IP address directly, not "server hostn_1 dns_of_server: port_number"

  • Put ' fullconn 1000 ' in the default section. This significantly increases boot time.

Finally, use the latest version of haproxy git and watch for increased load times. This has been greatly reduced. Its now an order of seconds compared to the minutes before.

In addition, with regard to the map function, a new dynamic use_backend scheme will be used in the work, which should remove the need to write as many ACLs as possible.

+12
source share

I had the same problem. I am currently experimenting with Nginx + Lua with all the backends stored on Redis.

The flow of requests is as follows.

  • Request received at Nginx.
  • Based on the request host, Redis is requested. Lua is available for Redis.
  • Backend information is retrieved from Redis and Nginx proxies the request for the corresponding backend.
  • Backend (HAProxy), then loading aligns the request.

The motivation for this is http://openresty.org/#DynamicRoutingBasedOnRedis

Hope this helps.

+1
source share

All Articles