netem and tc: netem is a network simulation module provided by Linux kernel versions 2.6 and above. This functional module can be used to simulate complex Internet transmission performance, such as low bandwidth, transmission delay, packet loss, etc., in a local area network with good performance. Many Linux distributions using Linux 2.6 (or above) kernel version have enabled this kernel feature, such as Fedora, Ubuntu, Redhat, OpenSuse, CentOS, Debian, etc. tc is a tool in the Linux system, and its full name is traffic control. tc can be used to control the working mode of netem. That is to say, if you want to use netem, at least two conditions are required. One is that the netem function in the kernel is included, and the other is that tc is required. It should be noted that the flow control introduced in this article can only control the packet sending action, but not the packet receiving action. At the same time, it takes effect directly on the physical interface. If the physical eth0 is controlled, the logical network card (such as eth0:1) will also be affected. Conversely, if you control the logical network card, the control may be invalid. (Note: Multiple network cards in a virtual machine can be regarded as multiple physical network cards in the virtual machine). Linux has a tc tool, namely traffic control, which can be used to simulate network packet loss and delay. When developing a backend server, if we want to know whether the server can perform well under a specific network packet loss condition, we can use tc to simulate the packet loss rate. Simulating packet loss The following command can simulate packet loss, and 10% of the packets going out of the eth0 network port will be randomly lost: sudo tc qdisc add dev eth0 root netem loss 10% Analog Delay The following command will delay the packets sent out of the eth0 network port by 40ms: sudo tc qdisc add dev eth0 root netem delay 40ms Packet loss and latency in specific scenarios Note that the commands introduced above are effective for the entire eth0 network port, that is, all packets going out from eth0 will experience random packet loss or delay. But sometimes, we only want packet loss and delay to affect a certain destination address. What should we do? sudo tc qdisc add dev eth0 root handle 1: prio sudo tc qdisc add dev eth0 parent 1:3 handle 30: netem loss 13% delay 40ms sudo tc filter add dev eth0 protocol ip parent 1:0 u32 match ip dst 199.91.72.192 match ip dport 36000 0xffff flowid 1:3 In the above command, we tell tc to generate 13% packet loss and 40ms delay for network packets sent to 199.91.72.192:36000, while network packets sent to other destination addresses will not be affected. Deleting a rule OK, after simulating packet loss and latency, remember to delete the rule: sudo tc qdisc del dev eth0 root Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: React Hook usage examples (6 common hooks)
>>: MySQL exposes Riddle vulnerability that can cause username and password leakage
MySQL is a relational database management system....
Sending emails using PHP's mail function The ...
illustrate: There are two main types of nginx log...
Conversion between rgba and filter values under...
Table of contents 0. Background 1. Installation 2...
Table of contents principle Network environment p...
Preface In the previous article Detailed Explanat...
Tencent QQ’s homepage has been redesigned, and Web...
1. System environment The system version after yu...
Suddenly when I logged into MySQL, it said that a...
Table of contents 1. How to represent the current...
Table of contents Preface keep-avlive hook functi...
This article mainly records the problems and solu...
Mac latest version of MySQL 8.0.22 password recov...
# contains a location information. The default anc...