OT: Conditional object construction in Perl plugins to reduce memory use of embedded Perl Nagios.

Stanley.Hopcroft at Dest.gov.au Stanley.Hopcroft at Dest.gov.au
Fri May 19 03:53:03 CEST 2006


Dear Folks,

I have hacked a home-brew Perl plugin (vi) to (mainly) construct
Perl objects only if there is _not_ one from the last run (of the plugin
under
embedded Perl) ie construct one object only and keep using it.

This plugin has been informally tested and continues to
validate that a DHCP server is healthy.

It has not been tested to

1 detect a failed DHCP server/b0rked network (same thing from the plugin
point of view)

2 ascertain whether less memory is used.

so while I cannot conclude that the plugin still functions as it did
before
the changes, or that the change was even worthwhile, it is encouraging
that
there are as yet no obvious reasons to dismiss this approach.

Yours sincerely.




[root at acisf011 plugins]# diff -c check_dhcp.pl check_dhcp.pl.ok | more
*** check_dhcp.pl       2006-05-19 11:42:19.000000000 +1000
--- check_dhcp.pl.ok    2006-05-19 11:32:09.000000000 +1000
***************
*** 100,123 ****
  
    $ENV{'PATH'} = '/sbin:/bin:/usr/local/bin' ;
  
!   unless ( $sock ) {
! 
!                                                       # Conditional
object construction
!                                                       # to try and
reduce memory use
!                                                       # in embedded
Perl applications.
! 
!     $sock = IO::Socket::INET->new(
                        LocalAddr       => inet_ntoa(INADDR_ANY),
                        LocalPort       => 68,
                        Proto           => 'udp',
                        Type            => SOCK_DGRAM,
                        Broadcast       => 1,
                ) or do {
!       print "Cannot create socket or bind to priviledged port: $!\n" ;
!       exit $ERRORS{UNKNOWN}
!     } 
! 
!   } 
  
    $hispaddr = sockaddr_in(67, inet_aton($subnet_bcast) ||
INADDR_BROADCAST) ;
  
--- 100,115 ----
  
    $ENV{'PATH'} = '/sbin:/bin:/usr/local/bin' ;
  
!   $sock = IO::Socket::INET->new(
                        LocalAddr       => inet_ntoa(INADDR_ANY),
                        LocalPort       => 68,
                        Proto           => 'udp',
                        Type            => SOCK_DGRAM,
                        Broadcast       => 1,
                ) or do {
!     print "Cannot create socket or bind to priviledged port: $!\n" ;
!     exit $ERRORS{UNKNOWN}
!   } ;
  
    $hispaddr = sockaddr_in(67, inet_aton($subnet_bcast) ||
INADDR_BROADCAST) ;
  
***************
*** 364,372 ****
  
    my ($p, $message_type, $ok) ;
  
!   $p = Dhcp->new($msg)
!      unless $p ;
! 
    ($message_type) = $p->dhcp_message_type ;
  
    $$msg_ref = $p ;
--- 356,362 ----
  
    my ($p, $message_type, $ok) ;
  
!   $p = Dhcp->new($msg) ;
    ($message_type) = $p->dhcp_message_type ;
  
    $$msg_ref = $p ;
[root at acisf011 plugins]# 


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list