Linux高级流量限制tc使用
发布时间:2023-09-26 14:30:38 所属栏目:Linux 来源:
导读: 率是基本在10%的基本范围内,目前是8%。
64 bytes from 192.168.253.129: icmp_seq=421 ttl=64 time=0.486 ms
64 bytes from 192.168.253.129: icmp_seq=422 ttl=64 time=0.413 ms
64
64 bytes from 192.168.253.129: icmp_seq=421 ttl=64 time=0.486 ms
64 bytes from 192.168.253.129: icmp_seq=422 ttl=64 time=0.413 ms
64
率是基本在10%的基本范围内,目前是8%。 64 bytes from 192.168.253.129: icmp_seq=421 ttl=64 time=0.486 ms 64 bytes from 192.168.253.129: icmp_seq=422 ttl=64 time=0.413 ms 64 bytes from 192.168.253.129: icmp_seq=423 ttl=64 time=0.616 ms ^C --- 192.168.253.129 ping statistics --- 426 packets transmitted, 390 received, 8% packet loss, time 425724ms rtt min/avg/max/mdev = 0.144/64.257/120.621/49.069 ms 如果数据包有重复的情况下,该如何处理。比如重复包的比例,我们设置为50%。 >tc qdisc add dev eth2 root netem duplicate 50% 使用ping的结果如下: PING 192.168.253.128 (192.168.253.128) 56(84) bytes of data. 64 bytes from 192.168.253.128: icmp_seq=1 ttl=64 time=0.402 ms 64 bytes from 192.168.253.128: icmp_seq=1 ttl=64 time=0.409 ms (DUP!) 64 bytes from 192.168.253.128: icmp_seq=2 ttl=64 time=0.788 ms 64 bytes from 192.168.253.128: icmp_seq=3 ttl=64 time=0.887 ms 64 bytes from 192.168.253.128: icmp_seq=4 ttl=64 time=0.721 ms 64 bytes from 192.168.253.128: icmp_seq=4 ttl=64 time=0.757 ms (DUP!) 64 bytes from 192.168.253.128: icmp_seq=5 ttl=64 time=1.33 ms 比如产生坏包的情况。 tc qdisc add dev eth2 root netem corrupt 50% ping的结果如下: 64 bytes from 192.168.253.128: icmp_seq=51 ttl=64 time=0.468 ms 64 bytes from 192.168.253.128: icmp_seq=52 ttl=64 time=0.822 ms wrong data byte #23 should be 0x17 but was 0x15 #16 10 11 12 13 14 15 16 15 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f #48 30 31 32 33 34 35 36 37 64 bytes from 192.168.253.128: icmp_seq=53 ttl=64 time=1.71 ms wrong data byte #53 should be 0x35 but was 0x37 #16 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f #48 30 31 32 33 34 37 36 37 64 bytes from 192.168.253.128: icmp_seq=54 ttl=64 time=0.000 ms 64 bytes from 192.168.253.128: icmp_seq=56 ttl=64 time=0.000 ms 如果包是乱序的,我们可以加入随机性,25%的包立即发送,其他的包延时10毫秒,系数为50% [root@oel641 ~]# tc qdisc change dev eth2 root netem delay 10ms reorder 25% 50% ping的结果如下所示: 64 bytes from 192.168.253.128: icmp_seq=200 ttl=64 time=1.24 ms 64 bytes from 192.168.253.128: icmp_seq=201 ttl=64 time=0.587 ms 64 bytes from 192.168.253.128: icmp_seq=202 ttl=64 time=1.01 ms 64 bytes from 192.168.253.128: icmp_seq=203 ttl=64 time=0.790 ms 64 bytes from 192.168.253.128: icmp_seq=204 ttl=64 time=0.998 ms 64 bytes from 192.168.253.128: icmp_seq=205 ttl=64 time=0.285 ms 64 bytes from 192.168.253.128: icmp_seq=206 ttl=64 time=0.882 ms 如果更复杂的场景呢,比如我们可以考虑加入流量的限制,网速控制在256k,最大延迟为50ms [root@oel641 ~]# tc qdisc add dev eth2 root handle 1:0 netem delay 100ms [root@oel641 ~]# tc qdisc add dev eth2 parent 1:1 handle 10: tbf rate 256kbit burst 10000 latency 50ms 速率 256kbit 突发传输 10k 最大延迟 50ms 如果不做流量控制,默认的情况下,传输可以达到90M美妙。 [root@oel642 ~]# scp 192.168.253.128:~/Percona-Server-5.6.14-rel62.0-483.Linux.x86_64.tar.gz . Percona-Server-5.6.14-rel62.0-483.Linux.x86_64.tar.gz 100% 93MB 92.9MB/s 00:01 而如果设置了流量控制的场景,就绝对保持在一个指定范围内。 [root@oel642 ~]# scp 192.168.253.128:~/Percona-Server-5.6.14-rel62.0-483.Linux.x86_64.tar.gz . Percona-Server-5.6.14-rel62.0-483.Linux.x86_64.tar.gz 0% 208KB 16.8KB/s 1:34:05 ETA 当然上面的场景都需要在测试环境先模拟一下,要不出现意料之外的问题就得不偿失了。 (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐