in reply to Re: Alarm Implemented in Win32?
in thread Alarm Implemented in Win32?

Elwarren, I implemeneted your code and then I looked at it and realized that I could get
the same functionality at half the speed.

UPDATE: errr...I should say at twice the speed...oops, typing faster than my brain
I thought you might be interested.
Here is the code:
#!/usr/bin/perl @pinglist=('10.17.1.60', '10.17.1.61', '10.17.1.62', '10.17.1.63'); use Net::Ping; my $p = Net::Ping->new(icmp, 5); foreach $h (@pinglist) { if ($p->ping($h, 5)) { print "[p (ok) $h]"; } else { print "[p <NO +> $h]"; } print "\n"; } $p->close;
And the benchmarking results:
H:\>benchingping.pl Benchmark: timing 5000 iterations of inline, modular... inline: 63 wallclock secs (22.26 usr + 8.72 sys = 30.98 CPU) @ 16 +1.37/s (n= 5000) modular: 104 wallclock secs (38.02 usr + 23.94 sys = 61.95 CPU) @ 8 +0.71/s (n= 5000)
Cool, huh? Thanks again!

Replies are listed 'Best First'.
RE: RE: Re: Alarm Implemented in Win32?
by elwarren (Priest) on May 19, 2000 at 23:29 UTC

    That's good to know. I never really went back to optimize the code, I was happy enough that I could run it on my NT machine at work. We had a server that kept crashing at different times, usually when nobody was looking :-) I threw this together to ping it every 5 minutes and it sort grew into a tool that did a few different checks. I put all the code into functions that handle creating the objects, connecting, checking the results, cleaning up and then returning a pass or fail. Each connection type has it's own special quirks hidden behind the function, so I can just as easily drop in a test_ping($hostname) as I could test_http($hostname)

    For a script that sits idle and wakes up every 5 minutes it's an acceptable slowdown ;-)

    Oh, and it ended up being a bad ups on the server...