I've got a little problem to solve:
I need to find a way to load balance, bandwidth-wise, the incoming RTMP streams on my servers.
I have 2 RTMP servers (nginx-rtmp), let's call them S1 and S2.
The RTMP servers are listening on the 1936 port, with HAProxy on the same machine as S1 to load-balance the streams, and as of the moment it works well, except that it uses the bandwidth on BOTH servers.
With the current configuration, the client sends a RTMP stream, HAProxy on S1 receives it and chooses S2 as the receiving server, and finally redirects the stream to it. So, for a 1Mbps stream, S1 uses 1Mbbs to receive the stream and 1Mbps to forward it to the second server, which is also using 1Mbps on S2.
Here's the configuration of HAProxy:
global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy #user haproxy #group haproxy daemon defaults log global mode http option httplog option dontlognull contimeout 5000 clitimeout 50000 srvtimeout 50000 errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http frontend ft_rtpm bind :1935 mode tcp maxconn 400 default_backend bk_rtmp backend bk_rtmp mode tcp server media01 127.0.0.1:1936 check maxconn 200 weight 1 server media02 ip.address.of.S2:1936 check maxconn 200 weight 1
I need to find a way to pass the requests directly to the server the load-balancer has chosen, without using the bandwidth of the load-balancer.
I know it's called HAProxy but I hoped it would be possible, so meanwhile I've also searched about other solutions like DNS round-robin, Anycast, DNS's SRV records (which are great, only if they were used...), but it doesn't seem as effective as HAProxy (no weights, health checks, max connections...), as it is very close to the final result, as there's "only" the bandwidth problem.