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

If you want this to run even faster, consider using NET::Ping with the 'syn' protocol. This allows you to overlap the pings to multiple hosts by not waiting for each to respond before starting the next.

See fping for an example of this.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re^2: I think I just found a good reason to use backticks in a void context.

Replies are listed 'Best First'.
Re^3: I think I just found a good reason to use backticks in a void context.
by OfficeLinebacker (Chaplain) on Jan 14, 2007 at 10:05 UTC
    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.
      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 absolutely agree. You've got to need the performance gain to make the extra complexity worth the effort.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.