In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use Trickle in Linux to limit application bandwidth usage". In daily operation, I believe many people have doubts about how to use Trickle in Linux to limit application bandwidth occupancy. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to use Trickle in Linux to limit application bandwidth occupation". Next, please follow the editor to study!
Have you ever encountered a situation in which an application in the system monopolizes all of your network bandwidth? If you have had this experience, then you will feel the value of Trickle as a bandwidth adjustment application. Whether you are a system administrator or an ordinary Linux user, you need to learn how to control the uplink and downlink speed of your application to ensure that your network bandwidth is not taken up by a certain program.
What is Trickle?
Trickle is a network bandwidth adjustment tool that allows us to manage the network uplink and uplink speed of applications, so that one of the applications can avoid occupying all or most of the available bandwidth. In other words, Trickle allows you to control the rate of network traffic based on a single application, not just with a single user-a classic bandwidth adjustment in a client network environment.
How does Trickle work?
In addition, trickle can help us define priorities based on applications, so when global limits are set for the entire system, high-priority applications will still automatically get more bandwidth. In order to achieve this goal, trickle sets traffic restrictions on the sending and receiving of data from sockets on TCP connections. We must note that apart from affecting the transmission rate, trickle will not change the data in any way at any time in this process.
What can't Trickle do?
To put it this way, the only limitation is that trickle does not support statically linked applications or binaries with SUID or SGID bit settings because it uses dynamic linking to load it between the process that needs to be adjusted and its associated network socket. Trickle now acts as an agent between the two software components.
Since trickle does not require superuser privileges to run, users can set their own traffic limits. Maybe this is not what you want, and we will explore how to use global settings to limit the traffic limits of all users in the system. That is to say, each user in the system has their own traffic rate to manage, but in any case, it will be subject to the overall limit set by the system administrator.
In this article, we will describe how to manage the network bandwidth used by applications on the linux platform through trickle. To generate the required traffic, use ncftpput and ncftpget on the client (CentOS 7 server-dev1: 192.168.0.17) and vsftpd on the server (Debian Wheezy 7.5-dev2: 192.168.0.15) to demonstrate. The same instructions can also be used in systems such as RedHat,Fedora and Ubuntu.
prerequisite
For RHEL/CentOS 7 + 6, open the EPEL warehouse. These additional packages for Enterprise Linux are a high-quality, open source software repository maintained by the Fedora project and are 100% compatible with their derivatives, such as the enterprise versions Linux and CentOS. Both trickle and ncftp are available in this repository.
Install ncftp as follows:
The code is as follows:
# yum update & & sudo yum install ncftp [RedHat-based system]
# aptitude update & & aptitude install ncftp [Debian-based system]
Set up a FTP server on a separate server. It is important to note that although FTP is inherently insecure, it is still widely used in file uploads and downloads where security is irrelevant. In this article, we use it to demonstrate the advantages of trickle, and it also displays the transfer rate in the client's standard output stream. We will put aside the discussion whether to use it at other times.
The code is as follows:
# yum update & & yum install vsftpd [RedHat-based system]
# aptitude update & & aptitude install vsftpd [Debian-based system]
Now, on the FTP server, edit the / etc/vsftpd/vsftpd.conf file as follows.
The code is as follows:
Anonymous_enable=NO
Local_enable=YES
Chroot_local_user=YES
Allow_writeable_chroot=YES
After that, make sure that vsftpd is started in your current session and let it start automatically at a later startup.
The code is as follows:
# systemctl start vsftpd [systemd-based system]
# systemctl enable vsftpd
# service vsftpd start [init-based system]
# chkconfig vsftpd on
If you choose to build a FTP server in CentOS/RHEL 7 that uses SSH keys for remote access, you need a password-protected user account that can access a directory outside the root directory and has permission to upload and download files from it.
You can browse your home directory by typing the following URL in your browser. A login window will pop up to prompt you to enter a valid user name and password from the FTP server.
Ftp://192.168.0.15
If the verification is successful, you will see the contents of your home directory. Later in the tutorial, you will be able to refresh the page to display the files you uploaded before.
How to install trickle in Linux
Install trickle. Exe via yum or aptitude.
To ensure a successful installation, it is best to make sure that the current installation package is the latest version before installing the tool.
The code is as follows:
# yum-y update & & yum install trickle [RedHat-based system]
# aptitude-y update & & aptitude install trickle [Debian-based system]
Confirm that trickle is useful for a specific binary package.
As we explained earlier, trickle is only useful for binaries that use dynamic or shared libraries. To confirm whether we can use trickle for a particular application, we can use the famous ldd (list dynamic Dependencies) tool. In particular, we will look at the glibc currently used in the dynamic dependencies of any given program because it accurately defines the system calls used to communicate over sockets.
Execute the following command for a given binary package to see if it can be adjusted using trickle:
The code is as follows:
# ldd $(which [binary]) | grep libc.so
For example,
The code is as follows:
# ldd $(which ncftp) | grep libc.so
Its output is:
The code is as follows:
# libc.so.6 = > / lib64/libc.so.6 (0x00007efff2e6c000)
The characters in parentheses in the output may be different on different system platforms, and even the same command will run differently at different times, because it represents the address where the package is loaded into physical memory.
If the above command does not return any results, it means that the binary package does not use the libc package, so trickle does not play the role of bandwidth adjustment.
Learn how to use Trickle
The most basic use is to use its stand-alone mode, in which trickle is used to explicitly define the upload and download rate of a given application. As mentioned earlier, for simplicity, we will use the same application for upload and download testing.
Run trickle in stand-alone mode
We compare the upload and download rates with or without trickle, the'- d' option indicates the download rate (in KB/s units), and the'- u 'option indicates the upload rate of the same unit. In addition, we will use the'- s' option to specify that trickle should run in stand-alone mode.
The basic syntax for running trickle in stand-alone mode is as follows:
The code is as follows:
# trickle-s-d [download rate, KB/s]-u [upload rate, KB/s]
In order for you to run the following example yourself, make sure you have trickle and ncftp installed on your client (mine is 192.168.0.17).
Example 1: upload a 2.8MB PDF file with or without trickle.
We use a freely released LInux fundamentals PDF file for the following tests.
You can first download this file to your current working directory using the following command:
The code is as follows:
# wget http://linux-training.be/files/books/LinuxFun.pdf
Here is the syntax for uploading a file to our FTP server without trickle:
The code is as follows:
# ncftpput-u username-p password 192.168.0.15 / remote_directory local-filename
The / remote_directory is the upload path relative to the user's home directory, and local-filename is a file in your current working directory.
In particular, in the absence of trickle, we can get the peak upload rate 52.02MB/s (note that this is not the real average upload rate, but the instantaneous value at the beginning of the peak), and the file is uploaded almost instantly.
The code is as follows:
# ncftpput-u username-p password 192.168.0.15 / testdir LinuxFun.pdf
Output:
The code is as follows:
LinuxFun.pdf: 2.79 MB 52.02 MB/s
In the case of using trickle, we will limit the upload rate to 5KB/s. Before uploading the file the second time, we need to delete the file in the target directory, otherwise ncftp will inform us that the same file already exists in the target directory as the uploaded file, so the file transfer will not be performed:
The code is as follows:
# rm / absolute/path/to/destination/directory/LinuxFun.pdf
Then:
The code is as follows:
# trickle-s-u 5 ncftpput-u username-p password 111.111.111.111 / testdir LinuxFun.pdf
Output:
The code is as follows:
LinuxFun.pdf: 2.79 MB 4.94 kB/s
In the above example, we see that the average upload rate has dropped to 5KB/s.
Example 2: download the PDF file of the same 2.8MB with or without trickle
First, remember to delete the PDF from the original source directory:
The code is as follows:
# rm / absolute/path/to/source/directory/LinuxFun.pdf
Note that in the following example, the remote file is downloaded to the current directory on the client machine by the "." after the IP address of the FTP server. It was decided.
Without trickle:
The code is as follows:
# ncftpget-u username-p password 111.111.111.111. / testdir/LinuxFun.pdf
Output:
The code is as follows:
LinuxFun.pdf: 2.79 MB 260.53 MB/s
If trickle is available, limit the download rate to 20KB/s:
The code is as follows:
# trickle-s-d 30 ncftpget-u username-p password 111.111.111.111. / testdir/LinuxFun.pdf
Output:
The code is as follows:
LinuxFun.pdf: 2.79 MB 17.76 kB/s
Run Trickle in supervised [unmanaged] mode
Trickle can also run in unmanaged mode according to a series of parameters defined in the / etc/trickled.conf file. This file defines the behavior of the daemon thread trickled and how to manage trickle.
In addition, if you want the global settings to be used by all applications, we will need to use the trickle command. This command runs the daemon and allows us to define upload and download limits shared by all applications through trickle, without the need for us to specify them each time.
For example, run:
The code is as follows:
# trickled-d 50-u 10
It will cause any application running through trickle to be limited to 30kb/s and 10kb/s, respectively.
Note that you can confirm whether the daemon thread trickled is running and its running parameters at any time:
The code is as follows:
# ps-ef | grep trickled | grep-v grep
Output:
The code is as follows:
Root 16475 10 Dec24? 00:00:04 trickled-d 50-u 10
Example 3: upload a 19MB mp4 file to our FTP server with / without trickle.
In this example, we will use the free distribution video of "He is the gift", which can be downloaded from this link.
We will start by downloading this file to your current working directory with the following command:
The code is as follows:
# wget http://media2.ldscdn.org/assets/missionary/our-people-2014/2014-00-1460-he-is-the-gift-360p-eng.mp4
First, we will use the commands listed earlier to open the daemon trickled:
The code is as follows:
# trickled-d 30-u 10
When not using trickle:
The code is as follows:
# ncftpput-u username-p password 192.168.0.15 / testdir 2014-00-1460-he-is-the-gift-360p-eng.mp4
Output:
The code is as follows:
2014-00-1460-he-is-the-gift-360p-eng.mp4: 18.53 MB 36.31 MB/s
When using trickle:
The code is as follows:
# trickle ncftpput-u username-p password 192.168.0.15 / testdir 2014-00-1460-he-is-the-gift-360p-eng.mp4
Output:
The code is as follows:
2014-00-1460-he-is-the-gift-360p-eng.mp4: 18.53 MB 9.51 kB/s
We can see the output above, and the upload rate has dropped to about 10KB/s.
* * sample 4: download this same video with / without trickle * *
As in sample 2, we will download this file to the current working directory.
When there is no trickle:
The code is as follows:
# ncftpget-u username-p password 192.168.0.15. / testdir/2014-00-1460-he-is-the-gift-360p-eng.mp4
Output:
The code is as follows:
2014-00-1460-he-is-the-gift-360p-eng.mp4: 18.53 MB 108.34 MB/s
When there is a trickle:
The code is as follows:
# trickle ncftpget-u username-p password 111.111.111.111. / testdir/2014-00-1460-he-is-the-gift-360p-eng.mp4
Output:
The code is as follows:
2014-00-1460-he-is-the-gift-360p-eng.mp4: 18.53 MB 29.28 kB/s
The above results correspond to the download speed limit we set earlier (30KB/s).
Note: once the daemon is turned on, it is not necessary to use trickle to set limits individually for each application.
As mentioned earlier, one can further customize the bandwidth rate adjustment of trickle through trickled.conf, and a typical segment of this file consists of the following parts:
The code is as follows:
[service]
Priority =
Time-Smoothing =
Length-Smoothing =
Among them
[service] is used to indicate the name of the application for which we want to adjust bandwidth usage
Priority is used to let us set a high priority for one service over other services, so that a single application in daemon management is not allowed to consume all the bandwidth. A smaller number represents a higher priority.
Time-Smoothing [in seconds]: defines the time interval at which trickled allows individual applications to transmit or receive data. A small interval value (0.1-1 second) is ideal for interactive applications because it has a smoother session experience, while a relatively large interval value (1-10 seconds) is better for applications that need to bulk transfer. If this value is not specified, the default is 5 seconds.
Length-smoothing [KB units]: this idea is the same as that of Time-Smoothing, but based on the ILength-smoothing O operation. If no value is specified, the default 10KB is used.
The above smooth value (Time-Smoothing, Length-smoothing) changes are translated to use an interval value instead of a fixed value for the specified service. Unfortunately, there is no specific formula to calculate the upper and lower limits of interval values, which mainly depends on specific application scenarios.
The following is a sample trickled.conf file (192.168.0.17) in the CentOS 7 client:
The code is as follows:
[ssh]
Priority = 1
Time-Smoothing = 0.1
Length-Smoothing = 2
[ftp]
Priority = 2
Time-Smoothing = 1
Length-Smoothing = 3
With this setting, trickled gives SSH a higher transport priority than FTP. It is worth noting that an interactive process, such as SSH, uses a small interval value, while a service that handles bulk data transfer, such as FTP, uses a larger interval to control the upload and download rate in the previous sample, which is not 100% specified by trickled, but is very close.
At this point, the study on "how to use Trickle in Linux to limit application bandwidth usage" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.