为什么使用 -f 时 ping 速度更快

为什么使用 -f 时 ping 速度更快

我同时从同一台机器 ping 同一台主机。当使用 时-f,结果几乎是两倍好:

[root@localhost Desktop]# ping 196.1.6.16
PING 196.1.6.16 (196.1.6.16) 56(84) bytes of data.
64 bytes from 196.1.6.16: icmp_seq=1 ttl=62 time=0.744 ms
64 bytes from 196.1.6.16: icmp_seq=2 ttl=62 time=0.166 ms
64 bytes from 196.1.6.16: icmp_seq=3 ttl=62 time=0.164 ms
64 bytes from 196.1.6.16: icmp_seq=4 ttl=62 time=0.164 ms
64 bytes from 196.1.6.16: icmp_seq=5 ttl=62 time=0.167 ms

[root@localhost Desktop]# ping -f 196.1.6.16
PING 196.1.6.16 (196.1.6.16) 56(84) bytes of data.
.^C
--- 196.1.6.16 ping statistics ---
84226 packets transmitted, 84225 received, 0% packet loss, time 9782ms
rtt min/avg/max/mdev = 0.083/0.091/0.191/0.012 ms, ipg/ewma 0.116/0.090 ms

我只是想知道为什么。据我了解,无论我发送数据包的频率如何,时间都应该是相同的。

由于我有如此不同的结果,这两个中哪一个是“公平的”?

更新#1

当它本身很有趣时,我问这个的另一个原因是 - 因为我想要更好的延迟(我执行高频交易)。因此,如果“洪水”ping 以某种方式改善了延迟,那么我想知道如何以及为什么。如果它将某些缓冲区归零,那么我应该评估以持久的方式将该缓冲区归零是否有意义等。

更新#2

ping 127.0.0.1 时差异更大

[root@localhost Desktop]# ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
....
64 bytes from 127.0.0.1: icmp_seq=17 ttl=64 time=0.067 ms
64 bytes from 127.0.0.1: icmp_seq=18 ttl=64 time=0.058 ms
64 bytes from 127.0.0.1: icmp_seq=19 ttl=64 time=0.064 ms
64 bytes from 127.0.0.1: icmp_seq=20 ttl=64 time=0.067 ms
^C
--- 127.0.0.1 ping statistics ---
20 packets transmitted, 20 received, 0% packet loss, time 18999ms
rtt min/avg/max/mdev = 0.058/0.065/0.069/0.006 ms


[root@localhost Desktop]# ping -f 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
^C 
--- 127.0.0.1 ping statistics ---
92267 packets transmitted, 92267 received, 0% packet loss, time 1273ms
rtt min/avg/max/mdev = 0.005/0.005/0.065/0.003 ms, ipg/ewma 0.013/0.006 ms

更新#3

我稍微调整了我的系统,特别是我已经使用tuned-adm并切换到了network-latency.现在数字降低了,但我仍然遇到同样的问题 - 当洪水 ping 值好多了时,为什么?

[root@localhost]# ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.011 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.010 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.009 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.011 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.011 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.011 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.011 ms
^C
--- 127.0.0.1 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 5999ms
rtt min/avg/max/mdev = 0.009/0.010/0.011/0.003 ms

[root@localhost]# ping -f 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

^C--- 127.0.0.1 ping statistics ---
42294 packets transmitted, 42294 received, 0% packet loss, time 837ms
rtt min/avg/max/mdev = 0.003/0.003/0.025/0.002 ms, ipg/ewma 0.019/0.003 ms

我使用的是 RHEL 7,最新的内核,所有更新。

答案1

回答您的更新:我对高频交易一无所知,但我几乎可以保证它不会发生ICMP(用于 ping 的协议)。由于 ICMP 消息的缓冲和优先级可能与携带实际数据的流量(最有可能使用 TCP 或 UDP)不同,因此 ping 结果与您想要完成的任务没有直接关系。

答案2

根据ping手册页,该f标志是:

  • -f:洪水平。对于每个发送的 ECHO_REQUEST 都会打印一个句点“.”,而对于收到的 ECHO_REPLY 则打印一个退格键。这可以快速显示有多少数据包被丢弃。如果未给出间隔,它将间隔设置为零,并以数据包返回的速度或每秒一百次(以较高者为准)输出数据包。只有超级用户可以以零间隔使用此选项。

因此,通过使用该f标志,我得到:

[support@cloudHA1 exporttool]$ sudo ping -f www.google.com
[sudo] password for support:
PING www.google.com (74.125.228.51) 56(84) bytes of data.
..^C
--- www.google.com ping statistics ---
12502 packets transmitted, 12500 received, 0% packet loss, time 29394ms
rtt min/avg/max/mdev = 1.335/2.194/191.342/6.182 ms, pipe 2, ipg/ewma 2.351/1.524 ms
[support@cloudHA1 exporttool]$

没有标志,我得到:

[support@cloudHA1 ~]$ ping www.google.com
PING www.google.com (74.125.228.50) 56(84) bytes of data.
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=1 ttl=49 time=1.53 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=2 ttl=49 time=1.51 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=3 ttl=49 time=1.72 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=4 ttl=49 time=1.62 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=5 ttl=49 time=1.78 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=6 ttl=49 time=1.66 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=7 ttl=49 time=1.59 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=8 ttl=49 time=1.66 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=9 ttl=49 time=1.43 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=10 ttl=49 time=1.72 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=11 ttl=49 time=1.84 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=12 ttl=49 time=1.80 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=13 ttl=49 time=1.69 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=14 ttl=49 time=1.87 ms
64 bytes from iad23s06-in-f18.1e100.net (74.125.228.50): icmp_seq=15 ttl=49 time=1.84 ms

^C
--- www.google.com ping statistics ---
61 packets transmitted, 61 received, 0% packet loss, time 60530ms
rtt min/avg/max/mdev = 1.438/2.026/12.749/1.548 ms

我将i在下一个示例中添加该标志,根据 ping 手册页,该标志执行以下操作:

  • -i 间隔 发送每个数据包之间的等待间隔秒数。默认情况下,正常情况下每个数据包之间等待一秒,或者在泛洪模式下不等待。只有超级用户可以将间隔设置为小于 0.2 秒的值。

    [support@cloudHA1 ~]$ ping -fi 4 www.google.com PING www.google.com (74.125.29.106) 56(84) bytes of data. ^C --- www.google.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 13875ms rtt min/avg/max/mdev = 9.381/9.531/9.749/0.153 ms, ipg/ewma 4625.308/9.495 ms [support@cloudHA1 ~]$

相关内容