Jay Taylor's notes
back to listing indexload balancing - How to use thousands of backends in haproxy? Is the new map feature useful for this? - Stack Overflow
[web search]-
-
Home
-
Questions
-
-
Tags
-
Saves
-
Users
-
Companies
-
Labs
-
Jobs
-
Discussions
-
Communities for your favorite technologies. Explore all Collectives
-
-
Teams
Now available on Stack Overflow for Teams! AI features where you work: search, IDE, and chat.
Learn more Explore Teams -
Looking for
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!
2 Answers
Some shortcomings were removed from the config file after expert input, and I list them here in case anyone else may find it useful.
Use hdr(Host) instead of hdr_reg(). This vastly improves the time consumed to evaluate the ACLs. Even better, avoid acl and use the inline evaluation e.g.
use_backend host1 if { req.fhdr(host,1) -m str host1.domain.com }
Use nbproc>1. In case of concurrent connections, this helps. Though it makes it difficult to debug.
For the backends, use IP address directly instead of 'server hostn_1 dns_of_server:port_number'
Put 'fullconn 1000' in the defaults section. This improves the load time immensely.
Finally, use the latest haproxy git checkout and observe the enhancement in load time. It has come down considerably. Its now order of seconds compared to minutes before.
Also, regarding the 'map' feature, a new dynamic use_backend scheme is in the works that should remove the need to write as many ACLs.
-
Update - the new feature for dynamically routing to backends is in:
use_backend bk_%[hdr(host),map(host_to_backend_map.file)] if TRUE
– rcrcCommented Apr 17, 2014 at 19:13
I was having the same problem. I am currently experimenting with Nginx + Lua with all the backends stored on Redis.
Request flow looks as below.
- Request is received at Nginx.
- Based on the request host, Redis is queried. A Lua module is available for Redis.
- Backend info is retrieved from Redis and Nginx proxies the request to appropriate backend.
- Backend(HAProxy), then load balances the request.
Motivation for this is from http://openresty.org/#DynamicRoutingBasedOnRedis
Hope this helps.
-
Sudhir, I do have exact same idea, but haven't done coding yet, can you share results of your experiments? Commented Mar 8, 2017 at 17:47
-
@abovesun, Nginx+Lua does work out. Wanted to experiment and use it in a high scale scenario, but the project scope was changed. So I have not much to share with you. Currently this is being used in a low traffic scenario.– sudhirCommented Mar 16, 2017 at 17:05
Your Answer
Not the answer you're looking for? Browse other questions tagged or ask your own question.
- Featured on Meta
-
-
Related
Hot Network Questions
- adjective as a noun
- Estimate of a trigonometric product
- When I attach a sensitive pdf encrypted by Adobe with a password, and send it through Gmail with password included, does it make any difference?
- Is the writer or artist liable for a copyright violation?
- How do manganese nodules in the ocean sustain oxygen production without depleting over geological time scales?
- Schengen visa (Indian passport) for Cruise Ship - Italy or Greece?
- Does forgetful functor commute with limits?
- Why is this pipe in my garage filled with concrete?
- What are the not-winglet wingtips on the CL-415?
- What did Rohan and Gondor think Sauron was?
- Existence of functorial (K-)flat resolutions?
- Are elements above 137 possible?
- Do amateurs still search for supernovae?
- When is Normal force 0?
- Bicolor/double-sided feathers as part of a thermoregulatory apparatus?
- Which Jesus died or in what sense did Jesus ("God") die for our sins
- I found these wild prickly plants on a trip in Cambridge, what are they?
- Is this 1-line proof of Cayley–Hamilton incomplete?
- Is it dangerous if an LED lightbulb fails to light up?
- Type vs. Set Theory: Expressive Ability
- SDD drive unknown dropped from 500GB to 2GB capacity
- How to tell if a state written in second quantization is a Slater determinant?
- Looking for a book I read pre-1990. Possibly called "The Wells of Yutan". A group of people go on a journey up a river
- Unable to compile upgrade parachain node after running `psvm v1.13.0`