Hi,

I have 3 backend servers, each accepting different form of HTTP queries:

http://backend1.server.tld/service1.php?q=...
http://backend1.server.tld/service2.php?q=...

http://backend2.server.tld/index.php?query=...&subquery=...

http://backend3.server.tld/image/49b8c0d9ff

Each backend server returns a different response based on either:
- the URI path (the left part of the URI before the question mark)
- the query string (the right part of the URI after the question mark)
- or the combination of both

I wanted to set up a common caching cluster (using 6 Squid servers, each
configured as reverse proxy for those 3 backends) and have HAProxy balance
the queries among the Squid servers based on URL. I also wanted to achieve
hight cache hit ration on each Squid server and send the same queries to
the same Squid servers. Initially I was considering using the 'balance uri'
algorithm, but that would not work as in case of backend2 all queries would
go to only one Squid server. The 'balance url_param' would not work either
as it would send the backend3 queries to only one Squid server.

So I thought the simplest solution would be to use 'balance uri', but to
calculate the hash based on the whole URI (URI path + query string),
instead of just the URI path. So I added a new "withquerystring" parameter
for the 'balance uri' algorithm which does exactly what I just described.

My configuration looks like this:

frontend proxy *:8080
    default_backend proxy

backend proxy
    balance     uri includequerystring
    server      squid1 192.168.1.1 check
    server      squid2 192.168.1.2 check
    server      squid3 192.168.1.3 check
    server      squid4 192.168.1.4 check
    server      squid5 192.168.1.5 check
    server      squid6 192.168.1.6 check


The patch enabling this includequerystring "feature" is very simple and is
attached to this email. It is backwards compatible, without the
'includequerystring' it still behaves as before. With 'includequerystring'
parameter it uses the whole URI instead.

Is this something other people could benefit from? If so, please review the
pach and include it into HAProxy source base. The patch is based on 1.4.20
source base.

Thank you,
Happy server load balancing,
Oskar

Attachment: 0001-MINOR-balance-uri-include-query-string-to-hash-calcu.patch
Description: Binary data

Reply via email to