Other options to "balance source" in haproxy

Solution 1:

Here's how I solved my problem.

frontend name_of_frontend
    bind *:20000-20010
    default_backend     servers

backend servers
    balance roundrobin
    stick-table type integer size 1k expire 3h
    stick on dst_port
    server name ip-address check maxconn 1
    ...
    server name ip-address check maxconn 1

Willy warned in a previous answer's comment that it "will not guarantee that each client will go to a different port".

In my specific case, I have complete control over my 'clients'. The only reason I am pointing them at different ports on the proxy server is so that I can identify them as different clients. This is most definitely not a 'public' system.

Solution 2:

Haproxy does not implement ip:port persistence because in a proxy it doesn't make any sense. Doing this makes a lot of sense in a packet-based load balancer (eg: LVS) because it allows stateless load balancing with round-robin like distribution and persistence. But in a proxy, the connections are necessarily maintained on both ends from the beginning to the end. So I really don't know what you're trying to precisely achieve.

If what you need is just a destination port -> server relation, that looks quite strange, because you need to listen on far more ports than you have servers in order to get a smooth balancing. I'm really not sure you'd want to do that.