[Nagiosplug-devel] Re: Perl plugins that fail gracefully by reporting missing modules.

Stanley Hopcroft Stanley.Hopcroft at IPAustralia.Gov.AU
Sun Mar 7 19:44:01 CET 2004


Dear Gentlemen,

I am writing to thank you for your leters and say,

On Mon, Mar 08, 2004 at 01:51:02AM +0000, Awais Ahmad wrote:
> I thought they already failed gracefully :). I find the contents of @INC
> being printed to STDERR pretty useful, so I wouldn't use eval {} in the
> context being discussed myself.

Yep. I agree. However, if you subscribe to Nag users, many if not all, 
of the questions about Perl plugins express dismay on seeing @INC.

> 
> BTW what performance hit? eval {} does not cause repeated recompilations
> as eval STRING does. All eval {BLOCK} does is trap runtime exceptions.
> 

With regard to the performance impact,

tsitc> diff -c check_traceroute check_traceroute_sans_runtime_checks 
*** check_traceroute    Fri Feb  6 16:11:37 2004
--- check_traceroute_sans_runtime_checks        Mon Mar  8 11:04:45 2004
***************
*** 3,22 ****
  use strict;
  use Getopt::Long;
  
! eval { require utils_1_4_0alpha1 } ;
! if ($@) {
!       print "This plugin requires the 'utils.pm' module from the Nag 
plugin distro. Please install it in the Perl \@INC path or add a 'use 
lib q(path_to_utils.pm)'.\n" ;
!       exit 0 ;
! };
! 
  use vars qw(%ERRORS $TIMEOUT) ;
- import utils qw(%ERRORS  $TIMEOUT &print_revision &support &usage) ;
  
! eval { require Net::Traceroute } ;
! if ($@) {
!       print "This plugin requires the 'Net::Traceroute' module from a 
CPAN near you.\n" ;
!       exit $ERRORS{UNKNOWN} ;
! } ;
  
  sub print_help ();
  sub print_usage ();
--- 3,12 ----
  use strict;
  use Getopt::Long;
  
! use utils_1_4_0alpha1 qw(%ERRORS  $TIMEOUT &print_revision &support 
&usage) ;
  use vars qw(%ERRORS $TIMEOUT) ;
  
! use Net::Traceroute ;
  
  sub print_help ();
  sub print_usage ();
tsitc> 

100 timed runs on the check_traceroute (with run time module checks)
take 357 msec (.357 sec)/run; 100 runs of
check_traceroute_sansruntime_checks take 320 msec.

I agree that this not a helpful argument and that I should devise a 
portable benchmark for this to be convincing.

However, in this case, the run time checks adds about 10% to the 
run-time (possibly because the compile phase has to to be re-invoked by the
run time 'require'; case eval { require foo } _is_ compiled but then
traps any run time exception loading and compiling foo).


> Anyway since we usually don't need a plugin to execute hundreds of times
> a second or/and crank out hundreds of millions of web pages a day, I
> would consider the use of either forms of eval quite reasonable, at
> least in the plugin context.
> 

I agree.

> 
> 
> Awais Ahmad

Yours sincerely.

-- 
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------

'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'

from Meditation 17, J Donne.




More information about the Devel mailing list