Currently nginx uses all my bandwidth. How do I leave some for rsync?
Best Answer
This is a sketch and you need to figure out all the details yourself, but this is how it should be possible:
What you want can be accomplished by using two Linux specific kernel facilities, namely cgroups and the QoS subsystem with it's scheduling policies.
What you basically need to is to put nginx and it's children into an own cgroup, use the discq scheduler from QoS which then can act on the net_cls controller (See this RedHat document that roughly describes net_cls). What it does is to append a tag to each packet that originates from a socket that was created by a PID coming from the cgroup where nginx sits.
You of course need to create the same cgroup setup for rsync. Take care that you can do all the cgroups machinery before you call rsync or setup rsyncd accordingly.
This 'tag' that is being attached from net_cls then can be used as classid in the filter attached to qdisc to pass the traffic to different classes. You also need to define bandwidth classes that contain the bandwith limits you want to assign to your two cgroups say 500Mbit/s ceiling for nginx and 500Mbit/s for rsync. Please note that the usual caveats about QoS and rate limiting or queuing TCP apply.
I would use rsync as it means that if it is interrupted for any reason, then you can restart it easily with very little cost. And being rsync, it can even restart part way through a large file. As others mention, it can exclude files easily. The simplest way to preserve most things is to use the -a flag – ‘archive.’ So:
rsync -a source dest
Although UID/GID and symlinks are preserved by -a (see -lpgo), your question implies you might want a full copy of the filesystem information; and -a doesn't include hard-links, extended attributes, or ACLs (on Linux) or the above nor resource forks (on OS X.) Thus, for a robust copy of a filesystem, you'll need to include those flags:
rsync -aHAX source dest # Linux
rsync -aHE source dest # OS X
The default cp will start again, though the -u flag will "copy only when the SOURCE file is newer than the destination file or when the destination file is missing". And the -a (archive) flag will be recursive, not recopy files if you have to restart and preserve permissions. So:
Best Answer
This is a sketch and you need to figure out all the details yourself, but this is how it should be possible:
What you want can be accomplished by using two Linux specific kernel facilities, namely
cgroups
and theQoS
subsystem with it's scheduling policies.What you basically need to is to put nginx and it's children into an own cgroup, use the
discq
scheduler from QoS which then can act on thenet_cls
controller (See this RedHat document that roughly describes net_cls). What it does is to append a tag to each packet that originates from a socket that was created by a PID coming from the cgroup where nginx sits.You of course need to create the same cgroup setup for rsync. Take care that you can do all the cgroups machinery before you call rsync or setup rsyncd accordingly.
This 'tag' that is being attached from net_cls then can be used as classid in the filter attached to qdisc to pass the traffic to different classes. You also need to define bandwidth classes that contain the bandwith limits you want to assign to your two cgroups say 500Mbit/s ceiling for nginx and 500Mbit/s for rsync. Please note that the usual caveats about QoS and rate limiting or queuing TCP apply.