Linux – rsync server side limit bandwidth/connection

linuxrsyncscriptingsynchronization

In a VOIP application, I have upto 3000 clients rsync audio files from there linux server in a daily, server is placed at a data center (10Mbps in/out bound), the server works as a VOIP sip server running FreeSWITCH (low ping latency should be ensured.)

Therefore I would like to have server side control of rsync which controls:

  1. Limit total outbound bandwidth.
  2. Limit total number of connections. (Reject clients while at max number of connection and let it retry after a specific time frame.)
  3. OPTIONAL: list/kill individual connections.

Normally I would use ssh + rsync + pem_keys with some extra options, but above requirements are not feasible by simple command lines. Can anyone point me some direction. or show some scripts/tools? I would also probably integrate them and release on github. Thanks!

Best Answer

If I were in your situation, I would continue using stock tools purely because you can always keep them up-to-date and get all the newest bugfixes/features without having to patch them with your own code.

As a result, I would achieve what you wanted with this:

  1. Use tc for traffic shaping - OpenVZ has quite a nice article on it.
  2. Use iptables - Cyberciti to the rescue for this one. You would reject new connections over the threshold, so you would need to wrap rsync client-side to ensure it retries if it fails fast.
  3. Probably the easiest way to achieve this is to have all your files under a single group, and a bunch of users part of that group. Then give every client their own user to connect as. From here, it should be relatively straightforward to kill the PIDs of the clients connected (I'm sure there are other ways you could identify the users uniquely though, this is just a suggestion.)