Sometimes, you’ll want to download something but you don’t want it to completely saturate your Internet connection. Perhaps you’re already downloading something more important, or you simply don’t want to get in the way of other people that are sharing the same Internet connection. Some programs, such as gFTP, wget and bittorrent, offer built-in up/download rate limiting. Other programs, such as apt-get and associates, don’t. Enter Trickle.
Trickle is a user space bandwidth shaper. It allows you to limit the bandwidth consumption of a program without requiring all kinds of kernel patches, firewall configurations or root access to the machine on which you wish to use it. Trickle can run in collaborative and stand alone mode. In collaborative mode, trickle can limit the bandwidth used by a bunch of programs at the same time. In stand alone mode, trickle simply limits the program you specify.
Trickle is easiest to use in stand-alone mode. Simply run trickle with a download and/or upload limit and a program you want to limit. For example:
[todsah@jib]~$ trickle -d 20 -u 20 wget http://www.electricmonk.nl/bigfile trickle: Could not reach trickled, working independently: No such file or directory –12:19:18– http://www.electricmonk.nl/bigfile => `bigfile’ Resolving www.electricmonk.nl… 18.104.22.168 Connecting to www.electricmonk.nl|22.214.171.124|:80… connected. HTTP request sent, awaiting response… 200 OK Length: 51,200,000 (49M) [text/plain] 0% [ ] 180,224 21.83K/s ETA 38:03
In the example above we use wget for demonstrative purposes, even though it has built-in bandwidth shaping. As you can see, the download rate is 21.83K/s. Of course, this is not exactly 20 K/s, but the download rate will vary between 19 and 21 K/s giving an average of 20 K/s. You can use the -w and -t command-line options to fine-tune this behaviour. The longer trickle runs, the closer it will get to 20 K/s. For more information, check out the manual page.
In daemon mode, trickle can limit a group of programs to a fixed limit of bandwidth. To start the daemon, run the trickled command:
[todsah@jib]~$ trickled -d 20 -u 20
This will start the trickle daemon that will limit the total bandwidth available to all programs run via trickle to 20 K/s both up and down. So if you run a single program via trickle, it can consume 20 K/s. Two programs can each consume 10 K/s, etc. As an example, we start three wget sessions:
[todsah@jib]~/temp$ trickle wget http://www.electricmonk.nl/bigfile 1% [ ] 933,888 6.66K/s ETA 1:47:17 [todsah@jib]~/download$ trickle wget http://www.electricmonk.nl/bigfile 1% [ ] 720,896 6.65K/s ETA 1:56:59 [todsah@jib]~$ trickle wget http://www.electricmonk.nl/bigfile 2% [ ] 1,228,800 6.64K/s ETA 1:45:00
The download rate is limited to about 6.6 K/s per session, making a total of 19.8 K/s. As is usually the case with bandwidth shapers, it may take a couple of seconds before all sessions are correctly limited. This is because of the algorithm used by shapers to determine how much they should delay the sending and receiving of traffic.
Trickle has been available in Debian at least since v3.1 (’Sarge’) and in Ubuntu since Warty.
apt-get install trickle should do the trick.