I need to ping 723 hosts with a single packet every minute with a 3 second time out.
Using the example in NET::Ping:
use Net::Ping;
$p = Net::Ping->new();
print "$host is alive.\n" if $p->ping($host);
$p->close();
$p = Net::Ping->new("icmp");
$p->bind($my_addr); # Specify source interface of pings
foreach $host (@host_array)
{
print "$host is ";
print "NOT " unless $p->ping($host, 2);
print "reachable.\n";
sleep(1);
}
$p->close();
I can iterate through the list serially in a little over 100 seconds, what I would like to do is thread or fork this in order to speed things up. I've found a reference to a threaded "version" of the ping at:
http://www.perlmonks.org/index.pl?node_id=231514
when I altered that method to use NET::PING, the script really didn't speed up all that much. I tried altering where I created my ping object - inside the thread, outside the thread.. Print the ping as it goes, capture to an array and join back up at the end... Nothing really seems to help.
What I'm looking for is a way to heavily parallelize (sp?) my $p->ping() call in order to be able to get through the list quicker. The box it'll be running on can take it and so can the network. Any help would be greatly appreciated.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.