linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Why ping latency is smaller with shorter send interval?
@ 2020-10-02  8:51 叶小龙
  2020-10-02  9:26 ` Eric Dumazet
  0 siblings, 1 reply; 5+ messages in thread
From: 叶小龙 @ 2020-10-02  8:51 UTC (permalink / raw)
  To: linux-kernel, netdev

Hi, net experts,

Hope this is the right place to ask the question :)

Recently I've tried to measure the network latency between two
machines by using ping, one interesting observation I found is that
ping latency will be smaller if I use a shorter interval with -i
option. For example,

when I use default ping (interval is 1s), then the ping result is as
below with avg latency 0.062ms

# ping 9.9.9.2 -c 10
PING 9.9.9.2 (9.9.9.2) 56(84) bytes of data.
64 bytes from 9.9.9.2: icmp_seq=1 ttl=64 time=0.059 ms
64 bytes from 9.9.9.2: icmp_seq=2 ttl=64 time=0.079 ms
64 bytes from 9.9.9.2: icmp_seq=3 ttl=64 time=0.060 ms
64 bytes from 9.9.9.2: icmp_seq=4 ttl=64 time=0.072 ms
64 bytes from 9.9.9.2: icmp_seq=5 ttl=64 time=0.048 ms
64 bytes from 9.9.9.2: icmp_seq=6 ttl=64 time=0.069 ms
64 bytes from 9.9.9.2: icmp_seq=7 ttl=64 time=0.067 ms
64 bytes from 9.9.9.2: icmp_seq=8 ttl=64 time=0.055 ms
64 bytes from 9.9.9.2: icmp_seq=9 ttl=64 time=0.058 ms
64 bytes from 9.9.9.2: icmp_seq=10 ttl=64 time=0.055 ms

--- 9.9.9.2 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9001ms
rtt min/avg/max/mdev = 0.048/0.062/0.079/0.010 ms

Then I use "-i 0.001", the lateny (0.038) is way better than defaut ping

# ping 9.9.9.2 -i 0.001 -c 10
PING 9.9.9.2 (9.9.9.2) 56(84) bytes of data.
64 bytes from 9.9.9.2: icmp_seq=1 ttl=64 time=0.069 ms
64 bytes from 9.9.9.2: icmp_seq=2 ttl=64 time=0.039 ms
64 bytes from 9.9.9.2: icmp_seq=3 ttl=64 time=0.034 ms
64 bytes from 9.9.9.2: icmp_seq=4 ttl=64 time=0.033 ms
64 bytes from 9.9.9.2: icmp_seq=5 ttl=64 time=0.033 ms
64 bytes from 9.9.9.2: icmp_seq=6 ttl=64 time=0.033 ms
64 bytes from 9.9.9.2: icmp_seq=7 ttl=64 time=0.034 ms
64 bytes from 9.9.9.2: icmp_seq=8 ttl=64 time=0.036 ms
64 bytes from 9.9.9.2: icmp_seq=9 ttl=64 time=0.037 ms
64 bytes from 9.9.9.2: icmp_seq=10 ttl=64 time=0.038 ms

--- 9.9.9.2 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9ms
rtt min/avg/max/mdev = 0.033/0.038/0.069/0.012 ms


ping loopback shows the similar result.

Default ping avg latency is 0.049ms

# ping 127.0.0.1 -c 10
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.032 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.049 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.054 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.058 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.049 ms
64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.042 ms
64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.052 ms
64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.052 ms
64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.053 ms
64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.055 ms

--- 127.0.0.1 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9001ms
rtt min/avg/max/mdev = 0.032/0.049/0.058/0.010 ms

ping with "-i 0.001" shows 0.014ms avg latency.

# ping 127.0.0.1 -i 0.001 -c 10
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.040 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.014 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.012 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
64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.010 ms
64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.010 ms
64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.011 ms

--- 127.0.0.1 ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9ms
rtt min/avg/max/mdev = 0.010/0.014/0.040/0.008 ms

I'm using centos 7.2 with kernel 3.10.

I am very confused about the result. As I understand it, it doesn't
matter how frequently I send packets, each packet's latency should be
the same. So How can I understand it from network stack point of view?

Any thoughts or suggestions would be highly appreciated.


Thanks,
Xiaolong

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Why ping latency is smaller with shorter send interval?
  2020-10-02  8:51 Why ping latency is smaller with shorter send interval? 叶小龙
@ 2020-10-02  9:26 ` Eric Dumazet
  2020-10-02  9:56   ` Willy Tarreau
  2020-10-02 19:46   ` Vinicius Costa Gomes
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2020-10-02  9:26 UTC (permalink / raw)
  To: 叶小龙, linux-kernel, netdev



On 10/2/20 10:51 AM, 叶小龙 wrote:
> Hi, net experts,
> 
> Hope this is the right place to ask the question :)
> 
> Recently I've tried to measure the network latency between two
> machines by using ping, one interesting observation I found is that
> ping latency will be smaller if I use a shorter interval with -i
> option. For example,
> 
> when I use default ping (interval is 1s), then the ping result is as
> below with avg latency 0.062ms
> 
> # ping 9.9.9.2 -c 10
> PING 9.9.9.2 (9.9.9.2) 56(84) bytes of data.
> 64 bytes from 9.9.9.2: icmp_seq=1 ttl=64 time=0.059 ms
> 64 bytes from 9.9.9.2: icmp_seq=2 ttl=64 time=0.079 ms
> 64 bytes from 9.9.9.2: icmp_seq=3 ttl=64 time=0.060 ms
> 64 bytes from 9.9.9.2: icmp_seq=4 ttl=64 time=0.072 ms
> 64 bytes from 9.9.9.2: icmp_seq=5 ttl=64 time=0.048 ms
> 64 bytes from 9.9.9.2: icmp_seq=6 ttl=64 time=0.069 ms
> 64 bytes from 9.9.9.2: icmp_seq=7 ttl=64 time=0.067 ms
> 64 bytes from 9.9.9.2: icmp_seq=8 ttl=64 time=0.055 ms
> 64 bytes from 9.9.9.2: icmp_seq=9 ttl=64 time=0.058 ms
> 64 bytes from 9.9.9.2: icmp_seq=10 ttl=64 time=0.055 ms
> 
> --- 9.9.9.2 ping statistics ---
> 10 packets transmitted, 10 received, 0% packet loss, time 9001ms
> rtt min/avg/max/mdev = 0.048/0.062/0.079/0.010 ms
> 
> Then I use "-i 0.001", the lateny (0.038) is way better than defaut ping
> 
> # ping 9.9.9.2 -i 0.001 -c 10
> PING 9.9.9.2 (9.9.9.2) 56(84) bytes of data.
> 64 bytes from 9.9.9.2: icmp_seq=1 ttl=64 time=0.069 ms
> 64 bytes from 9.9.9.2: icmp_seq=2 ttl=64 time=0.039 ms
> 64 bytes from 9.9.9.2: icmp_seq=3 ttl=64 time=0.034 ms
> 64 bytes from 9.9.9.2: icmp_seq=4 ttl=64 time=0.033 ms
> 64 bytes from 9.9.9.2: icmp_seq=5 ttl=64 time=0.033 ms
> 64 bytes from 9.9.9.2: icmp_seq=6 ttl=64 time=0.033 ms
> 64 bytes from 9.9.9.2: icmp_seq=7 ttl=64 time=0.034 ms
> 64 bytes from 9.9.9.2: icmp_seq=8 ttl=64 time=0.036 ms
> 64 bytes from 9.9.9.2: icmp_seq=9 ttl=64 time=0.037 ms
> 64 bytes from 9.9.9.2: icmp_seq=10 ttl=64 time=0.038 ms
> 
> --- 9.9.9.2 ping statistics ---
> 10 packets transmitted, 10 received, 0% packet loss, time 9ms
> rtt min/avg/max/mdev = 0.033/0.038/0.069/0.012 ms
> 
> 
> ping loopback shows the similar result.
> 
> Default ping avg latency is 0.049ms
> 
> # ping 127.0.0.1 -c 10
> 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.032 ms
> 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.049 ms
> 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.054 ms
> 64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.058 ms
> 64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.049 ms
> 64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.042 ms
> 64 bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.052 ms
> 64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.052 ms
> 64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.053 ms
> 64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.055 ms
> 
> --- 127.0.0.1 ping statistics ---
> 10 packets transmitted, 10 received, 0% packet loss, time 9001ms
> rtt min/avg/max/mdev = 0.032/0.049/0.058/0.010 ms
> 
> ping with "-i 0.001" shows 0.014ms avg latency.
> 
> # ping 127.0.0.1 -i 0.001 -c 10
> 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.040 ms
> 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.014 ms
> 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.012 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
> 64 bytes from 127.0.0.1: icmp_seq=8 ttl=64 time=0.010 ms
> 64 bytes from 127.0.0.1: icmp_seq=9 ttl=64 time=0.010 ms
> 64 bytes from 127.0.0.1: icmp_seq=10 ttl=64 time=0.011 ms
> 
> --- 127.0.0.1 ping statistics ---
> 10 packets transmitted, 10 received, 0% packet loss, time 9ms
> rtt min/avg/max/mdev = 0.010/0.014/0.040/0.008 ms
> 
> I'm using centos 7.2 with kernel 3.10.
> 
> I am very confused about the result. As I understand it, it doesn't
> matter how frequently I send packets, each packet's latency should be
> the same. So How can I understand it from network stack point of view?
> 
> Any thoughts or suggestions would be highly appreciated.
> 
> 
> Thanks,
> Xiaolong
> 

Many factors in play here.

1) if you keep cpus busy enough, they tend to keep in their caches
the data needed to serve your requests. In your case, time taken to
process an ICMP packet can be very different depending on how hot
cpu caches are.

2) Idle cpus can be put in a power conserving state.
  It takes time to exit from these states, as you noticed.
  These delays can typically be around 50 usec, or more.

Search for cpu C-states , and powertop program.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Why ping latency is smaller with shorter send interval?
  2020-10-02  9:26 ` Eric Dumazet
@ 2020-10-02  9:56   ` Willy Tarreau
  2020-10-02 19:46   ` Vinicius Costa Gomes
  1 sibling, 0 replies; 5+ messages in thread
From: Willy Tarreau @ 2020-10-02  9:56 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: ???, linux-kernel, netdev

On Fri, Oct 02, 2020 at 11:26:00AM +0200, Eric Dumazet wrote:
> 2) Idle cpus can be put in a power conserving state.
>   It takes time to exit from these states, as you noticed.
>   These delays can typically be around 50 usec, or more.

This is often the case in my experience. I'm even used to starting a
busy loop in SCHED_IDLE prio on certain machines or in certain VMs
just to keep them busy, and to see the ping latency cut in half.

Willy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Why ping latency is smaller with shorter send interval?
  2020-10-02  9:26 ` Eric Dumazet
  2020-10-02  9:56   ` Willy Tarreau
@ 2020-10-02 19:46   ` Vinicius Costa Gomes
  1 sibling, 0 replies; 5+ messages in thread
From: Vinicius Costa Gomes @ 2020-10-02 19:46 UTC (permalink / raw)
  To: Eric Dumazet, 叶小龙, linux-kernel, netdev

Hi,

Eric Dumazet <eric.dumazet@gmail.com> writes:

>
> Many factors in play here.
>
> 1) if you keep cpus busy enough, they tend to keep in their caches
> the data needed to serve your requests. In your case, time taken to
> process an ICMP packet can be very different depending on how hot
> cpu caches are.
>
> 2) Idle cpus can be put in a power conserving state.
>   It takes time to exit from these states, as you noticed.
>   These delays can typically be around 50 usec, or more.

Still on the power management theme, in my experience, in addition to
the CPU power states, the PCIe and NIC power management settings also
effect latency on the order of 10-100s usecs when the system is allowed
to go idle, some things that have helped:

 - setting CONFIG_PCIEASPM to performance;
 - disabling EEE (energy efficient ethernet) in your NIC;

>
> Search for cpu C-states , and powertop program.
>


Cheers,
-- 
Vinicius

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Why ping latency is smaller with shorter send interval?
       [not found] <tencent_2AB240953B1EC86706967C25A6279EB60509@qq.com>
@ 2020-10-02 22:24 ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2020-10-02 22:24 UTC (permalink / raw)
  To: muryo; +Cc: netdev, linux-kernel, kuznet, kuba


Can you please not send the same posting to the mailing list
three times, from three different email addresses?

Once is enough, thank you.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-10-02 22:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02  8:51 Why ping latency is smaller with shorter send interval? 叶小龙
2020-10-02  9:26 ` Eric Dumazet
2020-10-02  9:56   ` Willy Tarreau
2020-10-02 19:46   ` Vinicius Costa Gomes
     [not found] <tencent_2AB240953B1EC86706967C25A6279EB60509@qq.com>
2020-10-02 22:24 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).