网卡限速工具之WonderShaper

守听  论坛元老 | 2022-9-16 17:26:26 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 1014|帖子 1014|积分 3042


  • GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源。
  • GreatSQL是MySQL的国产分支版本,使用上与MySQL一致。


  • 什么是WonderShaper
  • 如何安装WonderShaper
  • WonderShaper使用帮助
  • WonderShaper使用示例

    • 查看网卡状态
    • 限制网卡速度(单位Kbps)
    • 取消限速

  • WonderShaper在测试中的应用
  • 网速单位转换
  • 总结
1.什么是WonderShaper

WonderShaper是用来对特定网卡进行快速限速的工具,它实际是对linux的tc命令进行封装后的shell脚本,所以使用成本比tc更低,更容易上手,以下配合测速工具speedtest一起使用
2.如何安装WonderShaper
  1. #直接拉取WonderShaper,开箱即用
  2. git clone https://github.com/magnific0/wondershaper.git
  3. root@****-5491:/home/soft/wondershaper# ./wondershaper -v
  4. Version 1.4.1
  5. root@****-5491:/home/soft/wondershaper#
  6. #网速测试工具speedtest安装(Ubuntu)
  7. apt install speedtest-cli
  8. --yum install speedtest-cli (centos)
复制代码
3.WonderShaper使用帮助
  1. root@****-5491:/home/soft/wondershaper# ./wondershaper -h
  2. USAGE: ./wondershaper [-hcs] [-a <adapter>] [-d <rate>] [-u <rate>]
  3. Limit the bandwidth of an adapter
  4. OPTIONS:
  5.    -h           Show this message 【帮助信息】
  6.    -a <adapter> Set the adapter  【指定网卡接口】
  7.    -d <rate>    Set maximum download rate (in Kbps) and/or 【限制下载速度(Kbps)】
  8.    -u <rate>    Set maximum upload rate (in Kbps)   【限制上传速度(Kbps)】
  9.    -p           Use presets in "/etc/systemd/wondershaper.conf"
  10.    -f <file>    Use alternative preset file
  11.    -c           Clear the limits from adapter 【清除指定网卡规则,用于取消限速】
  12.    -s           Show the current status of adapter 【显示当前网卡的状态】
  13.    -v           Show the current version  【显示当前版本】
  14.    Configure HIPRIODST in "/etc/systemd/wondershaper.conf" for hosts
  15.    requiring high priority i.e. in case ssh uses dport 443.
  16. MODES:
  17.    wondershaper -a <adapter> -d <rate> -u <rate>
  18.    wondershaper -c -a <adapter>
  19.    wondershaper -s -a <adapter>
  20. EXAMPLES: 【使用示例】
  21.    wondershaper -a eth0 -d 1024 -u 512  【设置网卡eth0的上行速度为512kbps,下行速度为1024kbps】
  22.    wondershaper -a eth0 -u 512 【只设置上行速度为512kbps】
  23.    wondershaper -c -a eth0 【清除网卡eth0的规则】
  24.    wondershaper -p -f foo.conf 【设置指定的配置文件】
  25. root@****-5491:/home/soft/wondershaper#
复制代码
4.WonderShaper使用示例

4.1查看网卡状态
  1. root@****-5491:/home/soft/wondershaper# ifconfig eno1
  2. eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
  3.         inet 192.168.5.103  netmask 255.255.255.0  broadcast 192.168.5.255
  4.         inet6 fe80::2c93:21f9:1931:304  prefixlen 64  scopeid 0x20<link>
  5.         ether c8:f7:50:7e:50:48  txqueuelen 1000  (Ethernet)
  6.         RX packets 7748809  bytes 1034513376 (1.0 GB)
  7.         RX errors 0  dropped 439  overruns 0  frame 0
  8.         TX packets 15528838  bytes 4784318169 (4.7 GB)
  9.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  10.         device interrupt 16  memory 0x91500000-91520000
  11.         
  12. root@****-5491:/home/soft/wondershaper# ./wondershaper -s -a eno1
  13. qdisc fq_codel 0: root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 32Mb ecn
  14. Sent 4528052159 bytes 14890189 pkt (dropped 0, overlimits 0 requeues 4224)
  15. backlog 0b 0p requeues 4224
  16.   maxpacket 66616 drop_overlimit 0 new_flow_count 35953 ecn_mark 0
  17.   new_flows_len 0 old_flows_len 0
  18. --测试网速
  19. root@****-5491:/home/soft/wondershaper# speedtest
  20. Retrieving speedtest.net configuration...
  21. Testing from China Telecom (120.36.98.11)...
  22. Retrieving speedtest.net server list...
  23. Selecting best server based on ping...
  24. Hosted by Fuzhou China Mobile,Fujian (Fuzhou) [589.19 km]: 14.449 ms
  25. Testing download speed................................................................................
  26. -- 下载网速是171.43 Mbit/s,
  27. Download: 171.43 Mbit/s
  28. Testing upload speed......................................................................................................
  29. -- 上传网速是4.15 Mbit/s
  30. Upload: 4.15 Mbit/s
复制代码
4.2限制网卡速度(单位Kbps)
  1. -- 下行2048kbps=2 Mbit/s,上行 1024kbps=1 Mbit/s
  2. root@****-5491:/home/soft/wondershaper# ./wondershaper -a eno1 -d 2048 -u 1024
  3. --测试网速
  4. root@****-5491:/home/soft/wondershaper# speedtest
  5. Retrieving speedtest.net configuration...
  6. Testing from China Telecom (120.36.98.11)...
  7. Retrieving speedtest.net server list...
  8. Selecting best server based on ping...
  9. Hosted by Far EasTone Telecom (Miaoli City) [722.10 km]: 174.383 ms
  10. Testing download speed................................................................................
  11. -- 下行速度
  12. Download: 1.80 Mbit/s
  13. Testing upload speed......................................................................................................
  14. --上行速度
  15. Upload: 1.28 Mbit/s
  16. root@****-5491:/home/soft/wondershaper#
复制代码
4.3取消限速
  1. --取消限速
  2. root@****-5491:/home/soft/wondershaper# ./wondershaper -c -a eno1
  3. -- 查看网卡状态
  4. root@****-5491:/home/soft/wondershaper# ./wondershaper -s -a eno1
  5. qdisc fq_codel 0: root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5.0ms interval 100.0ms memory_limit 32Mb ecn
  6. Sent 123022 bytes 471 pkt (dropped 0, overlimits 0 requeues 0)
  7. backlog 0b 0p requeues 0
  8.   maxpacket 0 drop_overlimit 0 new_flow_count 0 ecn_mark 0
  9.   new_flows_len 0 old_flows_len 0
  10. -- 测试网速
  11. root@****-5491:/home/soft/wondershaper# speedtest
  12. Retrieving speedtest.net configuration...
  13. Testing from China Telecom (120.36.98.11)...
  14. Retrieving speedtest.net server list...
  15. Selecting best server based on ping...
  16. Hosted by Far EasTone Telecom (Miaoli City) [722.10 km]: 173.886 ms
  17. Testing download speed................................................................................
  18. Download: 11.29 Mbit/s
  19. Testing upload speed......................................................................................................
  20. Upload: 2.93 Mbit/s
  21. root@****-5491:/home/soft/wondershaper#
复制代码
5.WonderShaper在测试中的应用


  • 测试项目:某内部数据库迁移工具
  • 测试目的:数据迁移中,对目标端进行限速,当取消限速后,传输速度可以恢复
  • 测试步骤:起迁移进程,在目标端服务器上用WonderShaper工具进行限速:
    1. -- 只限制下行速度
    2. [#22#root@**** ~/wondershaper 14:49:32]22  ./wondershaper -a enp0s3  -d 100
    复制代码
  • 测试结果:
    限速后,写目标库单位写入行数和单位写入字节数都急剧下降,如下图:
  1. 取消限速,恢复网络后,传输速率慢慢恢复:
复制代码


6.网速单位转换
  1. 1KB/s = 8kbps = 8kb/s
  2. 比如一般100M的宽带,实际是100Mbps=(100/8) MB/s=12.5 MB/s
复制代码
7.总结

使用WonderShaper对网卡进行限速,在测试时可以针对性的指定网卡,指定上传速度或者指定下载速度,在测试中上传和下载速度是互不影响的,可以只限制一方;且WonderShaper工具操作简单好入手,是个不错的工具。

Enjoy GreatSQL
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

守听

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表