Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use timeout option when timeout config option is set #101

Merged
merged 6 commits into from
Sep 16, 2019
Merged

use timeout option when timeout config option is set #101

merged 6 commits into from
Sep 16, 2019

Conversation

sa-linetco
Copy link
Contributor

fixes #100

@mondwan
Copy link
Collaborator

mondwan commented Aug 22, 2019 via email

@sa-linetco
Copy link
Contributor Author

sa-linetco commented Aug 22, 2019

With the timeout option set, ping also immediately returns on the first successful ping.

time /bin/ping -n -w 5 -c 1 192.168.133.33
PING 192.168.133.33 (192.168.133.33) 56(84) bytes of data.
64 bytes from 192.168.133.33: icmp_seq=1 ttl=64 time=2.35 ms

--- 192.168.133.33 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 2.358/2.358/2.358/0.000 ms

real	0m0,007s
user	0m0,001s
sys	0m0,004s
time /bin/ping -n -W 5 -c 1 192.168.133.33
PING 192.168.133.33 (192.168.133.33) 56(84) bytes of data.
64 bytes from 192.168.133.33: icmp_seq=1 ttl=64 time=5.11 ms

--- 192.168.133.33 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 5.110/5.110/5.110/0.000 ms

real	0m0,010s
user	0m0,001s
sys	0m0,004s

As described in #100 -W also guarantees that the ping process exits after the given timeout.

The difference between timeout and deadline is that deadline will ignore the count parameter in case the ping requests are not being answered. But as ping is called with -n (or -c) in the module, I expect that only the given number of ping requests is sent (which is also what I'd expect after reading the documentation: * @property {number} min_reply - Exit after sending number of ECHO_REQUEST.

@sa-linetco
Copy link
Contributor Author

If you want to conserve the possibility to set the deadline option on the javascript side, I'd suggest adding a deadline config option to the ping module. Translating timeout to the deadline ping option seems counterintuitive to me (especially as there is a timeout option available).

@mondwan
Copy link
Collaborator

mondwan commented Aug 23, 2019

I have done some experiments regarding to the deadline, and timeout option.

In your scenario, one ping packet, both options guarantee the exit time of command ping. But, timeout cannot do so if number of ping packets are more than 1, and the host is not reachable.

  • The deadline one
time ping -n -w 10 -c 10 1.2.3.4
PING 1.2.3.4 (1.2.3.4) 56(84) bytes of data.

--- 1.2.3.4 ping statistics ---
10 packets transmitted, 0 received, 100% packet loss, time 9209ms


real	0m10.001s
user	0m0.002s
sys	0m0.000s

  • The timeout one
time ping -n -W 10 -c 10 1.2.3.4
PING 1.2.3.4 (1.2.3.4) 56(84) bytes of data.

--- 1.2.3.4 ping statistics ---
10 packets transmitted, 0 received, 100% packet loss, time 9218ms


real	0m19.222s
user	0m0.000s
sys	0m0.003s

For host is reachable case, the result sames as the unreachable case mentioned above.

To conclude, I agree with your changes on timeout option (-w to -W), but we do need a new deadline option, which is linux specific, and write it down in the README FAQ section for this subtle usage.

Would you mind to help me to implement them?

@sa-linetco
Copy link
Contributor Author

sa-linetco commented Aug 23, 2019

Would you mind to help me to implement them?

Sure thing! As I do not have a mac available, could you please make sure that the mac version also inherits the unix ping options of -w for deadline and -W for timeout?
On the windows parameter builder I'd suggest to log a warning if deadline option is used.

@mondwan
Copy link
Collaborator

mondwan commented Aug 23, 2019 via email

@sa-linetco
Copy link
Contributor Author

For now I implemented the same behaviour for mac as I did for windows. When the deadline option is set, an error is thrown.

@sa-linetco
Copy link
Contributor Author

Another fact I found out while working on this:
-w on windows and -W on linux do not show the same behaviour.
I think we should change the documentation regarding the configuration object accordingly.

Example (windows, unreachable ip):
> Measure-Command {start-process ping -argumentlist "-w 7000 -n 3 172.29.14.32" -wait}
TotalSeconds      : 23,5091395
Example (windows, reachable ip)
> Measure-Command {start-process ping -argumentlist "-w 7000 -n 3 192.168.133.33" -wait}
TotalSeconds      : 3,0480599
Example (linux, unreachable ip):
:~$ time ping -W 7 -c 3 172.29.14.32
PING 172.29.14.32 (172.29.14.32) 56(84) bytes of data.

--- 172.29.14.32 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2038ms

real	0m9,040s
user	0m0,001s
sys	0m0,000s
Example (linux, reachable ip)
time ping -W 7 -c 3 192.168.133.33
PING 192.168.133.33 (192.168.133.33) 56(84) bytes of data.
64 bytes from 192.168.133.33: icmp_seq=1 ttl=64 time=2.65 ms
64 bytes from 192.168.133.33: icmp_seq=2 ttl=64 time=3.65 ms
64 bytes from 192.168.133.33: icmp_seq=3 ttl=64 time=2.67 ms

--- 192.168.133.33 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 2.658/2.996/3.652/0.465 ms

real	0m2,012s
user	0m0,006s
sys	0m0,000s

@mondwan
Copy link
Collaborator

mondwan commented Aug 24, 2019

Thanks. These are great, and high quality patch.

  • Below are conclusion so far on this issue. Would you mind to implement the MAC OS side as described in below table?
  • For the window's ping behaviour, I cannot notices the differences you mentioned. Would you mind to elaborate the differences so that we can see how to update the document accordingly?

Conclusion

Type MAC OS Ping Linux Ping Window ping
deadline -t (unit sec) -w (unit sec) NA
timeout -W (unit msec) -W (unit sec) -w (unit msec)

Experiments from MAC OS

Below are experiments on MAC OS

Not reachable cases

deadline option

MacBook-Air-4:~$ time ping -t 10 -c 15 1.2.3.4
PING 1.2.3.4 (1.2.3.4): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5
Request timeout for icmp_seq 6
Request timeout for icmp_seq 7
Request timeout for icmp_seq 8

--- 1.2.3.4 ping statistics ---
10 packets transmitted, 0 packets received, 100.0% packet loss

real	0m10.008s
user	0m0.002s
sys	0m0.003s

timeout option

MacBook-Air-4:~$ time ping -W 1000 -c 15 1.2.3.4
PING 1.2.3.4 (1.2.3.4): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
Request timeout for icmp_seq 5
Request timeout for icmp_seq 6
Request timeout for icmp_seq 7
Request timeout for icmp_seq 8
Request timeout for icmp_seq 9
Request timeout for icmp_seq 10
Request timeout for icmp_seq 11
Request timeout for icmp_seq 12
Request timeout for icmp_seq 13

--- 1.2.3.4 ping statistics ---
15 packets transmitted, 0 packets received, 100.0% packet loss

real	0m16.040s
user	0m0.002s
sys	0m0.005s

Reachable case

deadline

MacBook-Air-4:~$ time ping -t 1 -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=55 time=6.148 ms

--- 8.8.8.8 ping statistics ---
2 packets transmitted, 1 packets received, 50.0% packet loss
round-trip min/avg/max/stddev = 6.148/6.148/6.148/0.000 ms

real	0m1.007s
user	0m0.002s
sys	0m0.003s

Timeout

MacBook-Air-4:~$ time ping -W 1000 -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=55 time=5.667 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=6.099 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=5.860 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=55 time=14.086 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=55 time=6.324 ms

--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 5.667/7.607/14.086/3.247 ms

real	0m4.022s
user	0m0.002s
sys	0m0.003s

@sa-linetco
Copy link
Contributor Author

* Below are conclusion so far on this issue. Would you mind to implement the MAC OS side as described in below table?

Sure thing, I'll get on it later today.

@sa-linetco
Copy link
Contributor Author

sa-linetco commented Aug 26, 2019

* For the window's ping behaviour, I cannot notices the differences you mentioned. Would you mind to elaborate the differences so that we can see how to update the document accordingly?

Timeout: 7
Count: 3
Time for the ping process to exit:

unreachable IP reachable IP
linux 9 2
windows 23 3

The documentation for the configuration objects states that timeout determines the time for the ping process to exit, which is not what timeout stands for.
See:

  • @Property {number} timeout - Time duration, in seconds, for ping command to exit

My suggestion for the timeout option:

 * @property {number} timeout - Timeout in seconds for each ping request. Behaviour varies between platforms. Check platform ping documentation for more information.

@mondwan
Copy link
Collaborator

mondwan commented Aug 27, 2019

Great. Thanks for your patch. I have link up the discussions here in the README.

If there are no problems at all, I will merge this MR in a day or 2

@sa-linetco
Copy link
Contributor Author

Hi @mondwan , are there any problems that arose with this version which need addressing?

@mondwan mondwan merged commit 1592b68 into danielzzz:master Sep 16, 2019
@mondwan
Copy link
Collaborator

mondwan commented Sep 16, 2019

Ah, I forgot to press the button. Thanks for the remind.

@sa-linetco
Copy link
Contributor Author

Thanks for the merge! Do you have any info on when to expect a release on npm?

@mondwan
Copy link
Collaborator

mondwan commented Sep 17, 2019 via email

@mondwan mondwan mentioned this pull request Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

linux ping is using deadline instead of timeout for probes
2 participants