Nice rsync on remote machine

When using rsync+ssh to access a remote machine, is there a way to "nice" the rsync process on the remote machine (to lower its priority)?

Editing the question to clarify:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
backups  16651 86.2  0.1   3576  1636 ?        Rs   11:06   0:06 rsync --ser...

(rsync line snipped)

This is a backup cron job that normally runs at 4am, but when I happen to be awake (and committing, or using Bugzilla hosted on that same machine), it kills server performance, so I wanted a quick "hack" to try and fix it a bit.


You can use the --rsync-path option, eg.

rsync --rsync-path="nice rsync" foo remotebox:/tmp/

  • Taking the --rsync-path option you have rsync --rsync-path="ionice -c 3 nice -n 12 rsync" localDirectory remoteHost:/tmp/
  • Taking the configuration file option you can change or uncomment in file /etc/default/rsync the RSYNC_NICE='17' value and the RSYNC_IONICE='-c3' value

For both the ionice value will be for hard disc priority

  • 1 -> Real time
  • 2 -> Best effort
  • 3 -> Ildle (when any other process is not using the HD)

Note that for Linux only cfq scheduler really implements IO classes and priorities. If the remote system administrator has opted to IO scheduler noop, deadline or some more exotic variant you may find that ionice really does nothing. One should be able to get high performance from cfq and still be able to use IO classes and priorities by tuning cfq correctly.

for nice value for processor priority

  • -20 (most favorable to the process)
  • (default 10) if -n is not specified
  • 19 (least favorable to the process)

You could disable the compression along the network, by not including the -z argument, that might save some CPU time on either side. Or change how rsync uses checksums, look at --checksum


Quick and dirty solution would be to create a small wrapper script called 'rsync' that shadows the $PATH before real rsync binary like:

#!/bin/sh
nice -10 /path/to/proper/rsync $*

Or setup the authorized_keys file so that it performs nicing of rsync. (Assuming you are using ssh keys).

example:

command=”/home/user/bin/nice-rsync.sh" ssh-dss asdf....

Now in your /home/user/bin/nice-rsync.sh

#!/bin/sh
case $SSH_ORIGINAL_COMMAND in
  rsync\ --server*)
    nice -10 $SSH_ORIGINAL_COMMAND
    ;;
  *)
    $SSH_ORIGINAL_COMMAND
    ;;
esac

HTH