WonderShaper of network card speed limit tool
WonderShaper of network card speed limit tool
1. What is WonderShaper
WonderShaper is a tool used to quickly limit the speed of a specific network card. It is actually a shell script that encapsulates the tc command of Linux, so the cost of use is lower than that of tc, and it is easier to use. The following is used together with the speed measurement tool speedtest
2. How to install WonderShaper
#直接拉取wondershaper,开箱即用
git clone https://github.com/magnific0/wondershaper.git
root@****-5491:/home/soft/wondershaper# ./wondershaper -v
Version 1.4.1
root@****-5491:/home/soft/wondershaper#
#网速测试工具speedtest安装(Ubuntu)
apt install speedtest-cli
--yum install speedtest-cli (centos)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
3.WonderShaper use help
root@****-5491:/home/soft/wondershaper# ./wondershaper -h
USAGE: ./wondershaper [-hcs] [-a <adapter>] [-d <rate>] [-u <rate>]
Limit the bandwidth of an adapter
OPTIONS:
-h Show this message 【帮助信息】
-a <adapter> Set the adapter 【指定网卡接口】
-d <rate> Set maximum download rate (in Kbps) and/or 【限制下载速度(Kbps)】
-u <rate> Set maximum upload rate (in Kbps) 【限制上传速度(Kbps)】
-p Use presets in "/etc/systemd/wondershaper.conf"
-f <file> Use alternative preset file
-c Clear the limits from adapter 【清除指定网卡规则,用于取消限速】
-s Show the current status of adapter 【显示当前网卡的状态】
-v Show the current version 【显示当前版本】
Configure HIPRIODST in "/etc/systemd/wondershaper.conf" for hosts
requiring high priority i.e. in case ssh uses dport 443.
MODES:
wondershaper -a <adapter> -d <rate> -u <rate>
wondershaper -c -a <adapter>
wondershaper -s -a <adapter>
EXAMPLES: 【使用示例】
wondershaper -a eth0 -d 1024 -u 512 【设置网卡eth0的上行速度为512kbps,下行速度为1024kbps】
wondershaper -a eth0 -u 512 【只设置上行速度为512kbps】
wondershaper -c -a eth0 【清除网卡eth0的规则】
wondershaper -p -f foo.conf 【设置指定的配置文件】
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- twenty one.
- twenty two.
- twenty three.
- twenty four.
- 25.
- 26.
- 27.
- 28.
- 29.
4.WonderShaper usage example
4.1 View the status of the network card
root@****-5491:/home/soft/wondershaper# ifconfig eno1
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.5.103 netmask 255.255.255.0 broadcast 192.168.5.255
inet6 fe80::2c93:21f9:1931:304 prefixlen 64 scopeid 0x20<link>
ether c8:f7:50:7e:50:48 txqueuelen 1000 (Ethernet)
RX packets 7748809 bytes 1034513376 (1.0 GB)
RX errors 0 dropped 439 overruns 0 frame 0
TX packets 15528838 bytes 4784318169 (4.7 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0x91500000-91520000
root@****-5491:/home/soft/wondershaper# ./wondershaper -s -a eno1
qdisc fq_codel 0: root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 32Mb ecn
Sent 4528052159 bytes 14890189 pkt (dropped 0, overlimits 0 requeues 4224)
backlog 0b 0p requeues 4224
maxpacket 66616 drop_overlimit 0 new_flow_count 35953 ecn_mark 0
new_flows_len 0 old_flows_len 0
--测试网速
root@****-5491:/home/soft/wondershaper# speedtest
Retrieving speedtest.net configuration...
Testing from China Telecom (120.36.98.11)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Fuzhou China Mobile,Fujian (Fuzhou) [589.19 km]: 14.449 ms
Testing download speed................................................................................
-- 下载网速是171.43 Mbit/s,
Download: 171.43 Mbit/s
Testing upload speed......................................................................................................
-- 上传网速是4.15 Mbit/s
Upload: 4.15 Mbit/s
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- twenty one.
- twenty two.
- twenty three.
- twenty four.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
4.2 Limit network card speed (unit: Kbps)
-- 下行2048kbps=2 Mbit/s,上行 1024kbps=1 Mbit/s
root@****-5491:/home/soft/wondershaper# ./wondershaper -a eno1 -d 2048 -u 1024
--测试网速
root@****e-5491:/home/soft/wondershaper# speedtest
Retrieving speedtest.net configuration...
Testing from China Telecom (120.36.98.11)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Far EasTone Telecom (Miaoli City) [722.10 km]: 174.383 ms
Testing download speed................................................................................
-- 下行速度
Download: 1.80 Mbit/s
Testing upload speed......................................................................................................
--上行速度
Upload: 1.28 Mbit/s
root@****-5491:/home/soft/wondershaper#
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
4.3 Cancel the speed limit
--取消限速
root@****-5491:/home/soft/wondershaper# ./wondershaper -c -a eno1
-- 查看网卡状态
root@****-5491:/home/soft/wondershaper# ./wondershaper -s -a eno1
qdisc fq_codel 0: root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 32Mb ecn
Sent 123022 bytes 471 pkt (dropped 0, overlimits 0 requeues 0)
backlog 0b 0p requeues 0
maxpacket 0 drop_overlimit 0 new_flow_count 0 ecn_mark 0
new_flows_len 0 old_flows_len 0
-- 测试网速
root@****-5491:/home/soft/wondershaper# speedtest
Retrieving speedtest.net configuration...
Testing from China Telecom (120.36.98.11)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Far EasTone Telecom (Miaoli City) [722.10 km]: 173.886 ms
Testing download speed................................................................................
Download: 11.29 Mbit/s
Testing upload speed......................................................................................................
Upload: 2.93 Mbit/s
root@****-5491:/home/soft/wondershaper#
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- twenty one.
- twenty two.
5. Application of WonderShaper in testing
Test project: an internal database migration tool
Test purpose: During data migration, limit the speed of the target end. When the speed limit is canceled, the transmission speed can be restored.
Test steps: Start the migration process and use the WonderShaper tool to limit the speed on the target server:
-- 只限制下行速度
[#22#root@**** ~/wondershaper]22 ./wondershaper -a enp0s3 -d 100
- 1.
- 2.
Test results: After the speed limit, the number of lines written per unit and the number of bytes written per unit of the write target library dropped sharply, as shown in the following figure:
取消限速,恢复网络后,传输速率慢慢恢复:
- 1.
6. Network speed unit conversion
1KB/s = 8kbps = 8kb/s
比如一般100M的宽带,实际是100Mbps=(100/8) MB/s=12.5 MB/s
- 1.
- 2.
7. Summary
Use WonderShaper to limit the speed of the network card. During the test, you can specify the network card, upload speed or download speed. In the test, the upload and download speeds do not affect each other, and only one party can be limited; and the WonderShaper tool is easy to operate. It's a good tool to start with.