I want to use haproxy as a proxy and load balancer for thousands of backends. So a request needs to be proxied to the correct backend depending on hostname and then load balanced within the backend. I am using haproxy-1.5dev21.
The config file looks like this :
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
Problem is that I get an added latency of 30ms per request if there are 5000 hosts. And for 20k backends, haproxy takes long time to load, not to mention the disaster on latency per request.
Can I do something better than sequential acl rules? I have not found an example for the new map feature - the release notes say it can be used for massive redirect rules. I tried this :
use_backend %[hdr(host), map(host_to_backend_map.file)]
Something obviously stupid above in using maps, but any guidance would be helpful. Thanks!
use_backend bk_%[hdr(host),map(host_to_backend_map.file)] if TRUE
– Monegasque