[LINUX] I tried to control the network bandwidth and delay with the tc command

■ Purpose

The tc command (Traffic Control) can control the Latency and Throughput of the Network. The delay and bandwidth may change depending on the distance of the computer, and the time for data transfer may change. So, let's check if the delay and bandwidth can be controlled with the tc command.

■ Composition

構成-non.png Install two Compute instances on Oracle Cloud and try to control the network performance between them with TC commands.

■ Check the current environment

Check Latency, Throughput, TPS to Client-> Server

● Delay (RTT) confirmation

Ping to check RTT This time, confirm that the average is 0.166ms

[opc@client-inst01 ~]$ sudo ping 10.0.0.2 -c 5
	PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
	64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.178 ms
	64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.182 ms
	64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.135 ms
	64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=0.177 ms
	64 bytes from 10.0.0.2: icmp_seq=5 ttl=64 time=0.160 ms

	--- 10.0.0.2 ping statistics ---
	5 packets transmitted, 5 received, 0% packet loss, time 4110ms
	rtt min/avg/max/mdev = 0.135/0.166/0.182/0.020 ms

● Bandwidth check

Run iperf3 to check throughput This time, we confirmed that it was about 2 Gbits / sec.

[opc@client-inst01 ~]$ sudo iperf3 -c 10.0.0.2
	Connecting to host 10.0.0.2, port 5201
	[  4] local 10.0.0.5 port 33750 connected to 10.0.0.2 port 5201
	[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
	[  4]   0.00-1.00   sec   377 MBytes  3.17 Gbits/sec  1165   2.06 MBytes
	[  4]   1.00-2.00   sec   254 MBytes  2.13 Gbits/sec  2338    323 KBytes
	[  4]   2.00-3.00   sec   231 MBytes  1.94 Gbits/sec  1480   1.31 MBytes
	[  4]   3.00-4.00   sec   244 MBytes  2.04 Gbits/sec  2127   61.2 KBytes
	[  4]   4.00-5.00   sec   229 MBytes  1.92 Gbits/sec  953    166 KBytes
	[  4]   5.00-6.00   sec   239 MBytes  2.00 Gbits/sec  2055    629 KBytes
	[  4]   6.00-7.00   sec   205 MBytes  1.72 Gbits/sec  1336   1.77 MBytes
	[  4]   7.00-8.00   sec   274 MBytes  2.30 Gbits/sec  2216   96.1 KBytes
	[  4]   8.00-9.00   sec   238 MBytes  1.99 Gbits/sec  1198    891 KBytes
	[  4]   9.00-10.00  sec   232 MBytes  1.95 Gbits/sec  1486    638 KBytes
	- - - - - - - - - - - - - - - - - - - - - - - - -
	[ ID] Interval           Transfer     Bandwidth       Retr
	[  4]   0.00-10.00  sec  2.46 GBytes  2.12 Gbits/sec  16354             sender
	[  4]   0.00-10.00  sec  2.46 GBytes  2.11 Gbits/sec                  receiver

	iperf Done.

■ Delay and bandwidth control with tc command

Since the packet is sent from the client side, try controlling the delay and bandwidth on the client computer.

① Check the Network Interface to be set

Network Interfece name confirmation to connect to Server with Client Confirm that the Interface name is ens3 this time

[root@client-inst01 ~]# ifconfig
	ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9000
			inet 10.0.0.5  netmask 255.255.255.0  broadcast 10.0.0.255
			ether 02:00:23:17:3a  txqueuelen 1000  (Ethernet)
			RX packets 454466  bytes 165785003 (158.1 MiB)
			RX errors 0  dropped 0  overruns 0  frame 0
			TX packets 503382  bytes 277089862 (264.2 MiB)
			TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

(2) 100ms delay control tc command execution

This time, I will try to control it to 100ms 100ms is about the distance from Japan to the United States

[opc@client-inst01 ~]$ sudo tc qdisc add dev ens3 root handle 1:0 netem delay 100ms

③ 50Mbps bandwidth control tc command execution

This time, I will try to control it to 50 Mbps At that time, try using the following values

・ Rate = 50mbit ・ CONFIG_HZ = 1000 ・ Burst = rate / CONFIG_HZ = 50kb ・ Limit = burst x 10 = 500kb

[opc@client-inst01 ~]$ sudo cat /boot/config-`uname -r` | grep CONFIG_HZ=
	CONFIG_HZ=1000

・ 50Mbps bandwidth control tc command execution

[opc@client-inst01 ~]$ sudo tc qdisc add dev ens3 parent 1:1 handle 10:0 tbf rate 50mbit burst 50kb limit 500kb

④ Check tc command settings

[opc@client-inst01 ~]$ sudo tc -s qdisc show dev ens3
	qdisc netem 1: root refcnt 17 limit 1000 delay 100.0ms
	Sent 288635914 bytes 38521 pkt (dropped 0, overlimits 0 requeues 14)
	backlog 102b 1p requeues 14
	qdisc tbf 10: parent 1:1 rate 50Mbit burst 25Kb lat 36.9ms
	Sent 35582 bytes 73 pkt (dropped 0, overlimits 0 requeues 0)
	backlog 0b 0p requeues 0

⑤ Delay (RTT) confirmation

Ping to check RTT Confirm that it can be controlled to 100 ms on average

[opc@client-inst01 ~]$ ping 10.0.0.2 -c 5
	PING 10.0.0.101 (10.0.0.101) 56(84) bytes of data.
	64 bytes from 10.0.0.101: icmp_seq=1 ttl=64 time=100 ms
	64 bytes from 10.0.0.101: icmp_seq=2 ttl=64 time=100 ms
	64 bytes from 10.0.0.101: icmp_seq=3 ttl=64 time=100 ms
	64 bytes from 10.0.0.101: icmp_seq=4 ttl=64 time=100 ms
	64 bytes from 10.0.0.101: icmp_seq=5 ttl=64 time=100 ms

	--- 10.0.0.101 ping statistics ---
	5 packets transmitted, 5 received, 0% packet loss, time 4004ms
	rtt min/avg/max/mdev = 100.160/100.192/100.218/0.283 ms

⑥ Bandwidth check

Run iperf3 to check RTT Confirm that control is possible to 50Mbits / sec

[opc@client-inst01 ~]$ sudo iperf3 -c 10.0.0.2
	Connecting to host 10.0.0.2, port 5201
	[  4] local 10.0.0.5 port 44108 connected to 10.0.0.2 port 5201
	[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
	[  4]   0.00-1.00   sec  6.18 MBytes  51.8 Mbits/sec   44    743 KBytes
	[  4]   1.00-2.00   sec  6.25 MBytes  52.4 Mbits/sec    5    638 KBytes
	[  4]   2.00-3.00   sec  5.00 MBytes  41.9 Mbits/sec    0    725 KBytes
	[  4]   3.00-4.00   sec  6.25 MBytes  52.4 Mbits/sec    0    751 KBytes
	[  4]   4.00-5.00   sec  6.25 MBytes  52.4 Mbits/sec    0    751 KBytes
	[  4]   5.00-6.00   sec  6.25 MBytes  52.4 Mbits/sec    0    778 KBytes
	[  4]   6.00-7.00   sec  5.00 MBytes  41.9 Mbits/sec    0    813 KBytes
	[  4]   7.00-8.00   sec  6.25 MBytes  52.4 Mbits/sec    0    848 KBytes
	[  4]   8.00-9.00   sec  6.25 MBytes  52.4 Mbits/sec    3    664 KBytes
	[  4]   9.00-10.00  sec  6.25 MBytes  52.4 Mbits/sec    0    786 KBytes
	- - - - - - - - - - - - - - - - - - - - - - - - -
	[ ID] Interval           Transfer     Bandwidth       Retr
	[  4]   0.00-10.00  sec  59.9 MBytes  50.3 Mbits/sec   52             sender
	[  4]   0.00-10.00  sec  56.9 MBytes  47.7 Mbits/sec                  receiver

	iperf Done.



	--- 10.0.0.2 ping statistics ---
	5 packets transmitted, 5 received, 0% packet loss, time 4004ms
	rtt min/avg/max/mdev = 100.160/100.192/100.218/0.283 ms

⑦ Cancel tc command setting

[opc@tokyo-inst01 ~]$ sudo tc qdisc del dev ens3 root

Recommended Posts

I tried to control the network bandwidth and delay with the tc command
I tried to notify the train delay information with LINE Notify
I tried to express sadness and joy with the stable marriage problem.
I tried to save the data with discord
I tried to learn the angle from sin and cos with chainer
[Introduction to PID] I tried to control and play ♬
[Introduction to AWS] I tried porting the conversation app and playing with text2speech @ AWS ♪
I tried to learn the sin function with chainer
I tried to read and save automatically with VOICEROID2 2
I tried to implement and learn DCGAN with PyTorch
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
I tried to automatically read and save with VOICEROID2
I tried to implement Grad-CAM with keras and tensorflow
I tried to automate the article update of Livedoor blog with Python and selenium.
sphinx-quickstart got messy and I tried to create an alternative command and the stress disappeared
I tried to compare the processing speed with dplyr of R and pandas of Python
I tried to predict and submit Titanic survivors with Kaggle
I tried to find the entropy of the image with python
I tried to simulate how the infection spreads with Python
I tried to analyze the whole novel "Weathering with You" ☔️
I tried to find the average of the sequence with TensorFlow
I tried to illustrate the time and time in C language
I tried to display the time and today's weather w
I tried to divide the file into folders with Python
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
I tried to estimate the interval.
I tried to describe the traffic in real time with WebSocket
I tried to solve the ant book beginner's edition with python
[Linux] I tried to summarize the command of resource confirmation system
I tried to automate the watering of the planter with Raspberry Pi
I tried to visualize bookmarks flying to Slack with Doc2Vec and PCA
I tried to make a periodical process with Selenium and Python
I tried to get started with Bitcoin Systre on the weekend
I tried to process the image in "pencil style" with OpenCV
I tried to expand the size of the logical volume with LVM
I want to connect remotely to another computer, and the nautilus command
I tried to easily detect facial landmarks with python and dlib
I tried to make a mechanism of exclusive control with Go
I made my own 3-layer forward propagation neural network and tried to understand the calculation deeply.
I tried to create serverless batch processing for the first time with DynamoDB and Step Functions
I tried to visualize AutoEncoder with TensorFlow
I tried to recognize the wake word
I tried to get started with Hy
I tried to summarize the graphical modeling.
I tried to estimate the pi stochastically
I tried to implement CVAE with PyTorch
I tried playing with the image with Pillow
I tried to solve TSP with QAOA
[Python] I tried to visualize the night on the Galactic Railroad with WordCloud!
I tried to refer to the fun rock-paper-scissors poi for beginners with Python
I tried to summarize until I quit the bank and became an engineer
I tried to visualize the age group and rate distribution of Atcoder
I tried how to improve the accuracy of my own Neural Network
765 I tried to identify the three professional families by CNN (with Chainer 2.0.0)
I tried to get the authentication code of Qiita API with Python.
I tried to convert datetime <-> string with tzinfo using strftime () and strptime ()
I tried to automatically extract the movements of PES players with software
I tried to extract and illustrate the stage of the story using COTOHA
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python