Example 3: Uploading a 19 MB mp4 file to our FTP server using with and without trickle.
In this example we will use the freely-distributable “He is the gift” video, available for download from this link.
We will initially download this file to your current working directory with the following command:
# wget http://media2.ldscdn.org/assets/missionary/our-people-2014/2014-00-1460-he-is-the-gift-360p-eng.mp4
First off, we will start the trickled daemon with the command listed above:
# trickled -d 30 -u 10
Without trickle:
# ncftpput -u username -p password 192.168.0.15 /testdir 2014-00-1460-he-is-the-gift-360p-eng.mp4
Output:
2014-00-1460-he-is-the-gift-360p-eng.mp4: 18.53 MB 36.31 MB/s
With trickle:
# trickle ncftpput -u username -p password 192.168.0.15 /testdir 2014-00-1460-he-is-the-gift-360p-eng.mp4
Output:
2014-00-1460-he-is-the-gift-360p-eng.mp4: 18.53 MB 9.51 kB/s
As we can see in the output above, the upload transfer rate dropped to ~10 KB/s.
Example 4: Downloading the same video with and without trickle
As in Example 2, we will be downloading the file to the current working directory.
Without trickle:
# ncftpget -u username -p password 192.168.0.15 . /testdir/2014-00-1460-he-is-the-gift-360p-eng.mp4
Output:
2014-00-1460-he-is-the-gift-360p-eng.mp4: 18.53 MB 108.34 MB/s
With trickle:
# trickle ncftpget -u username -p password 111.111.111.111 . /testdir/2014-00-1460-he-is-the-gift-360p-eng.mp4
Output:
2014-00-1460-he-is-the-gift-360p-eng.mp4: 18.53 MB 29.28 kB/s
Which is in accordance with the download limit set earlier (30 KB/s).
Note: That once the daemon has been started, there is no need to set individual limits for each application that uses trickle.
As we mentioned earlier, one can further customize trickle’s bandwidth shaping through trickled.conf. A typical section in this file consists of the following:
[service] Priority = <value> Time-Smoothing = <value> Length-Smoothing = <value>
Where,
- [service] indicates the name of the application whose bandwidth usage we intend to shape.
- Priority allows us to specify a service to have a higher priority relative to another, thus not allowing a single application to hog all the bandwidth which the daemon is managing. The lower the number, the more bandwidth that is assigned to [service].
- Time-Smoothing [in seconds]: defines with what time intervals trickled will try to let the application transfer and / or receive data. Smaller values (something between the range of 0.1 – 1s) are ideal for interactive applications and will result in a more continuous (smooth) session while slightly larger values (1 – 10 s) are better for applications that need bulk transfer. If no value is specified, the default (5 s) is used.
- Length-Smoothing [in KB]: the idea is the same as in Time-Smoothing, but based on the length of an I/O operation. If no value is specified, the default (10 KB) is used.
Changing the smoothing values will translate into the application specified by [service] using transfer rates within an interval instead of a fixed value. Unfortunately, there is no formula to calculate the lower and upper limits of this interval as it mainly depends of each specific case scenario.
The following is a trickled.conf sample file in the CentOS 7 client (192.168.0.17):
[ssh] Priority = 1 Time-Smoothing = 0.1 Length-Smoothing = 2 [ftp] Priority = 2 Time-Smoothing = 1 Length-Smoothing = 3
Using this setup, trickled will prioritize SSH connections over FTP transfers. Note that an interactive process, such as SSH, uses smaller time-smoothing values, whereas a service that performs bulk data transfers (FTP) uses a greater value. The smoothing values are responsible for the download and upload speeds in our previous example not matching the exact value specified by the trickled daemon but moving in an interval close to it.
Conclusion
In this article we have explored how to limit the bandwidth used by applications using trickle on Fedora-based distributions and Debian / derivatives. Other possible use cases include, but are not limited to:
- Limiting the download speed via a system utility such as wget, or a torrent client, for example.
- Limiting the speed at which your system can be updated via `yum` (or `aptitude`, if you’re in a Debian-based system), the package management system.
- If your server happens to be behind a proxy or firewall (or is the proxy or firewall itself), you can use trickle to set limits on both the download and upload, or communication speed with the clients or the outside.
Questions and comments are most welcome. Feel free to use the form below to send them our way.
can i use this in cpanel server to throttled a specific user ?
@Abu,
Yes you can, just follow the instructions as shown in this article and setup bandwidth throttling per user.
Hi,
How to limite bandwidth only when needed.
Ex: I want use app1 to download on a system with total bandwidth of 800 ko/s
# trickle -d 600 foo_app1
To let 200 ko/s to other apps.
How call ‘trickle’ to tell it to use all Bandwidth when other app are finish to use bandwidth remaining ?
I haven’t see no options in man page.
Perhaps another app do that?
Thanks
Hi,
How can i change the transfer rate if ftp? please reply to my mail id.
Sandip Singh
If any user figures out how to run your app without trickle your bandwidth management no longer works. You need method that are part of the kernel for proper bandwidth management.
@cybernard,
Would you be as kind as to share a specific example of how an user would be able to do that? Please notice that we covered this possibility near the bottom of the article. If you make an experiment and are able to fool trickle, please report back with the specifics so we can edit the article accordingly. Thank you!
This is very interesting but a bit redundant. Cgroups (control groups) is built into the kernel and provides awesome control over an application’s usage of not only network but mem, CPU, disk I/o and more. This is taken to the next level by containers and docker which provide better tooling and automation to make more easily use cgroups and other plumbing built into the os.
I highly recommend spending your time learning docker and the other container tooling as this is the future for better designed apps and this skill set is in VERY high demand right now.
@Terry,
Thanks for taking the time to share such a well-supported and informative comment. You are SO right about docker. The reason why we published this article is because it outlines the basics of network bandwidth shaping. We will consider writing and publishing a docker series in the near future once we’re done with the RHCSA and RHCE series.
Hello
Trickled can work along side Default TC-HTB-QoS class rules ?
@Chetan,
I must admit that I don’t know. Feel free to give it a try and post back your findings. We will all appreciate that.
You can use force_bind to set a mark per application, and then you can use HTB to do the matching.
Check http://kernel.embedromix.ro/us/ – see examples 13 and 14.
Thanks for sharing your thoughts on bandwidth
limit in linux. Regards
@logbook,
Thank you for taking the time to comment on this article. Feel free to share it through your social network profiles.
Will it control smtp or postfix ?
Yes it can because smtp and postfix works TCP. So, it should work
Can i used trickle in server / router so i can control download rate for all my client ?
@Edward,
Unfortunately, trickle was not intended to work in a client-server architecture. In other words, it will only shape traffic on the host where it is installed.