Hi, Browser, I saw that; but I saw this in the doc: "NOTE: Unlike the other protocols, the return value does NOT determine if the remote host is alive or not since the full TCP three-way handshake may not have completed yet."

So I guess the thing to do would be to ping the hosts outside the loop and then only loop through the hosts that respond? I guess you lose a little bit of timeliness (the whole script takes about 20 seconds to run). So it's possible that when I get to the last machine in my list, I'm working on a ping success value from ~19 seconds ago. Also, a quick benchmark of the syn vs udp protocols (similar to the one where I bm'd backticks vs Net::Ping) actually showed no advantage (some were faster, some were slower) (and that's just the outward leg!):

Ping with Net::Ping (syn) took 0.002087 seconds
Ping with Net::Ping (udp) took 0.000932 seconds
..
Ping with Net::Ping (syn) took 0.000977 seconds
Ping with Net::Ping (udp) took 0.001136 seconds
..
Ping with Net::Ping (syn) took 0.001145 seconds
Ping with Net::Ping (udp) took 0.001183 seconds
..
Ping with Net::Ping (syn) took 0.001282 seconds
Ping with Net::Ping (udp) took 0.001024 seconds
..
Ping with Net::Ping (syn) took 0.001163 seconds
Ping with Net::Ping (udp) took 0.001019 seconds
..
Ping with Net::Ping (syn) took 0.001049 seconds
Ping with Net::Ping (udp) took 0.000696 seconds
..
Ping with Net::Ping (syn) took 0.00084 seconds
Ping with Net::Ping (udp) took 0.000815 seconds
..
Ping with Net::Ping (syn) took 0.000822 seconds
Ping with Net::Ping (udp) took 0.000707 seconds
..
Ping with Net::Ping (syn) took 0.000956 seconds
Ping with Net::Ping (udp) took 0.000822 seconds
..
Ping with Net::Ping (syn) took 0.000828 seconds
Ping with Net::Ping (udp) took 0.000734 seconds
..
Ping with Net::Ping (syn) took 0.000802 seconds
Ping with Net::Ping (udp) took 0.000704 seconds
..
Ping with Net::Ping (syn) took 0.000835 seconds
Ping with Net::Ping (udp) took 0.000821 seconds
..
Ping with Net::Ping (syn) took 0.000822 seconds
Ping with Net::Ping (udp) took 0.000712 seconds
..
Ping with Net::Ping (syn) took 0.000702 seconds
Ping with Net::Ping (udp) took 0.000824 seconds
..
Ping with Net::Ping (syn) took 0.000823 seconds
Ping with Net::Ping (udp) took 0.000719 seconds
..
Ping with Net::Ping (syn) took 0.00104 seconds
Ping with Net::Ping (udp) took 0.000782 seconds
..
Ping with Net::Ping (syn) took 0.000563 seconds
Ping with Net::Ping (udp) took 0.000474 seconds

It seems to me a better way to test the performance is something like this:(it's late so forgive me if my logic is off)

Readonly my $udp_pinger => Net::Ping->new( 'udp', 1 ); Readonly my $syn_pinger => Net::Ping->new( 'syn', 1 ); foreach my $x ( 0 .. 5 ) { #test the syn prot with two loops my $t0 = [ gettimeofday() ]; foreach my $host (@host_list) { $syn_pinger->ping($host) || die "syn ping failed for $host"; } foreach my $host (@host_list) { $syn_pinger->ack($host) || die "syn ack failed for $host"; } my $e0 = tv_interval($t0); print "$e0 seconds to ping $NUM_HOSTS hosts with syn"; #test the udp prot with one loop $t0 = [ gettimeofday() ]; foreach my $host (@host_list) { $udp_pinger->ping($host) || die "udp ping failed for $host"; } $e0 = tv_interval($t0); print "$e0 seconds to ping $NUM_HOSTS hosts with udp"; print "---------------------------"; } ## end foreach my $x ( 0 .. 5 )
(I didn't want to go too crazy with number of iterations, but here's a pretty representative result:
0.015293 seconds to ping 17 hosts with syn
0.013442 seconds to ping 17 hosts with udp
---------------------------
0.013814 seconds to ping 17 hosts with syn
0.013393 seconds to ping 17 hosts with udp
---------------------------
0.01381 seconds to ping 17 hosts with syn
0.01327 seconds to ping 17 hosts with udp
---------------------------
0.014273 seconds to ping 17 hosts with syn
0.013056 seconds to ping 17 hosts with udp
---------------------------
0.014191 seconds to ping 17 hosts with syn
0.013396 seconds to ping 17 hosts with udp
---------------------------
0.016453 seconds to ping 17 hosts with syn
0.013 seconds to ping 17 hosts with udp

I suppose a better test would be just just call ack non-specifically the right number of times, and keep track of who's responded. But that seems like a lot of work to save a few milliseconds (yeah, I know--kinda late to be saying that). I'm happy going from 1.008->.008->.005->.0015 seconds per host. I think I've reached the point of diminishing returns. However, if you were checking hundreds or more hosts, I could see where that could be worth it.


I like computer programming because it's like Legos for the mind.

In reply to Re^3: I think I just found a good reason to use backticks in a void context. by OfficeLinebacker
in thread I thought I found a good reason to use backticks in a void context, but I was wrong. by OfficeLinebacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.