How to Limit the Network Bandwidth Used by Applications in a Linux System with Trickle
Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators | 4 Free Shell Scripting eBooks
How to Install Trickle in Linux
1. Install trickle via yum or aptitude.
To ensure a successful installation, it is considered good practice to make sure the currently installed packages are up-to-date (using yum update) before installing the tool itself.
2. Verify whether trickle will work with the desired binary.
As we explained earlier, trickle will only work with binaries using dynamic, or shared, libraries. To verify whether we can use this tool with a certain application, we can use the well-known ldd utility, where ldd stands for list dynamic dependencies. Specifically, we will look for the presence of glibc (the GNU C library) in the list of dynamic dependencies of any given program because it is precisely that library which defines the system calls involved in communication through sockets.
Run the following command against a given binary to see if trickle can be used to shape its bandwidth:
For example,
whose output is:
The string between brackets in the output may change from system to system and even between subsequent runs of the same command, since it represents the load address of the library in physical memory.
If the above command does not return any results, it means that the binary it was run against does not use libcand thus trickle cannot be used as bandwidth shaper in that case.
Learn How to Use Trickle
The most basic usage of trickle is in standalone mode. Using this approach, trickle is used to explicitly define the download and upload speeds of a given application. As we explained earlier, for the sake of brevity, we will use the same application for download and upload tests.
Running Trickle in Standalone Mode
We will compare the download and upload speeds with and without using trickle. The -d option indicates the download speed in KB/s, while the -u flag tells trickle to limit the upload speed by the same unit. In addition, we will use the -s flag, which specifies that trickle should run in standalone mode.
The basic syntax to run trickle in standalone mode is as follows:
In order to perform the following examples on your own, make sure to have trickle and ncftp installed on the client machine (192.168.0.17 in my case).
Example 1: Uploading a 2.8 MB PDF file with and without trickle.
We are using the freely-distributable Linux Fundamentals PDF file (available from here) for the following tests.
You can initially download this file to your current working directory with the following command:
The syntax to upload a file to our FTP server without trickle is as follows:
Where /remote_directory is the path of the upload directory relative to username’s home, and local-filename is a file in your current working directory.
Specifically, without trickle we get a peak upload speed of 52.02 MB/s (please note that this is not the real average upload speed, but an instant starting peak), and the file gets uploaded almost instantly:
Output:
With trickle, we will limit the upload transfer rate at 5 KB/s. Before uploading the file for the second time, we need to delete it from the destination directory; otherwise, ncftp will inform us that the file at the destination directory is the same that we are trying to upload, and will not perform the transfer:
Then:
Output:
In the example above, we can see that the average upload speed dropped to ~5 KB/s.
Example 2: Downloading the same 2.8 MB PDF file with and without trickle
First, remember to delete the PDF from the original source directory:
Please note that the following cases will download the remote file to the current directory in the client machine. This fact is indicated by the period (‘.‘) that appears after the IP address of the FTP server.
Without trickle:
Output:
With trickle, limiting the download speed at 20 KB/s:
Output:
Running Trickle in Supervised [unmanaged] Mode
Trickle can also run in unmanaged mode, following a series of parameters defined in /etc/trickled.conf. This file defines how trickled (the daemon) behaves and manages trickle.
In addition, if we want to set global settings to be used, overall, by all applications, we will need to use the trickled command. This command runs the daemon and allows us to define download and upload limits that will be shared by all the applications run through trickle without us needing to specify limits each time.
For example, running:
Will cause that the download and upload speeds of any application run through trickle be limited to 30 KB/s and10 KB/s, respectively.
Please note that you can check at any time whether trickled is running and with what arguments:
Output:
Comentarios
Publicar un comentario