0
votes

I would like to choose a backend based on custom hash function that hashes the client ip (I know this is not ideal but I am trying this approach out).

A pseudo config would look like,

frontend myserver
    bind *:80 
    acl  MyHash(clientIP) %2 
    use_backend backend0 if {MyHash(clientIP)%2 -m int 0}
    default_backend backend1

backend backend0
    balance leastconn
    server server-1 <ip>:port check 
    server server-2 <ip>:port check 

backend backend1
    balance leastconn
    server server-3 <ip>:port check 
    server server-4 <ip>:port check 

The reason I am doing this instead of the following alternate, is that, I don't want connect a client to a server all the time, instead distribute the load among the servers that belong to same cluster. server-[1-2] form a cluster and so do server-[3-4].

frontend myserver
    bind *:80 
    default_backend mybackend



backend mybackend
    balance source
    hash-type consistent 
    server server-1 <ip>:port check 
    server server-2 <ip>:port check 
    server server-3 <ip>:port check 
    server server-4 <ip>:port check