Recently, in my research, I want to throttle the I/O and network bandwidth of my program so as to show my program is robust in different senarios. In practice, we may also want to limit the resources used by certain programs (rsync, wget, …). Fortunately, this is possible in Linux. Next, I will show how to do it on Ubuntu 14.04. I believe it’s doable on any Linux distributions.

For network bandwidth limiting, we will use a program called trickle.

  1. Install trickle:
  2. Usage of trickle:

  3. Example: limit the bandwidth for scp under 10MB/s

An alternative for network bandwidth limiting is wondershaper. But I found that tirckle works better.

For disk bandwidth limiting, you can use the cgroup mechanism and its blkio controller.

  1. Install cgroup-bin:
  2. Create a cgroup named limit under blkio:
  3. Set the read/write limit to 1 MB/s (see below for explanation)

    Here, the format of blkio.throttle.read_bps_device and blkio.throttle.write_bps_device is

    To find out <major>:<minor> for a certain disk like /dev/sda, we just run

    Then the output disk 8, 0 means <major>:<minor> should be 8:0.
  4. Finally, we can limit the disk bandwidth for scp with cgexec (suppose the source file is stored on disk /dev/sda):

Leave a Reply

Your email address will not be published. Required fields are marked *