Skip Menu |

This queue is for tickets about the Nagios-Object CPAN distribution.

Report information
The Basics
Id: 63803
Status: resolved
Priority: 0/
Queue: Nagios-Object

People
Owner: duncan_j_ferguson [...] yahoo.co.uk
Requestors: PIRZYK [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.21.12
Fixed in: (no value)



Subject: find_object() sufferes performance issues.
running parse.pl on our nagios configuration takes quite a while. We have around 650 hosts and over 700 service checks. Attached is the performance numbers from parse.pl before and after the patch was applied. I also included the perl -d:Profile parse.pl output to show where the optimizations helped out.
Subject: prof.out.parse.pl.new
Download prof.out.parse.pl.new
application/octet-stream 10.6k

Message body not shown because it is not plain text.

Subject: results.txt
# Active Host / Service Checks: 647 / 7283 parse.pl -b -n p2-nms1.cfg # Normal Nagios::Object performance: Benchmark: 51 wallclock secs (50.86 usr + 0.04 sys = 50.90 CPU) # With the find_object optimizations. Benchmark: 3 wallclock secs ( 2.95 usr + 0.05 sys = 3.00 CPU)
Subject: perl-Nagios-Object-0.21.12-find_object-performance.patch
--- ./lib/Nagios/Object/Config.pm.orig 2010-06-29 07:51:40.000000000 -0400 +++ ./lib/Nagios/Object/Config.pm 2010-11-30 10:42:27.000000000 -0500 @@ -71,9 +71,10 @@ config_files => [] }; - # initialize lists e.g. host_list, command_list, etc. + # initialize lists and indexes e.g. host_list, command_index, etc. foreach my $class ( keys %nagios_setup ) { $self->{ lc($class) . '_list' } = []; + $self->{ lc($class) . '_index' } = {}; } # parse arguments passed in @@ -295,6 +295,11 @@ = [ 'STRING', 0 ]; $current->{$key} = $val; } + + # Add to the find_object search hash. + if ( $key eq 'name' || $key eq $nagios_setup{ $current->setup_key }->{'name'}[0] ) { + push( @{ $self->{ lc($current->setup_key) . '_index' }->{$val} }, $current ); + } } else { croak @@ -335,15 +335,17 @@ if ( $type && $type =~ /^Nagios::/ ) { + my @objl = $self->find_objects($name, $type); + return $objl[0] if ( scalar @objl ); - $searchlist = $self->all_objects_for_type($type); } elsif ( !$type ) { $searchlist = $self->all_objects; - } - foreach my $obj (@$searchlist) { + foreach my $obj (@$searchlist) { - #printf STDERR "obj name '%s', name searched '%s'\n", $obj->name, $name; - if ( $obj->name && $obj->name eq $name ) { - return $obj; + #printf STDERR "obj name '%s', name searched '%s'\n", $obj->name, $name; + my $n = $obj->name; + if ( $n && $n eq $name ) { + return $obj; + } } } } @@ -342,6 +345,27 @@ } } +=item find_objects() + +Search through the list of objects' names and return all the matches. +The second argument is required. + + my @object_list = $parser->find_objects( "load", "Nagios::Service" ); + +=cut + +sub find_objects { + my ( $self, $name, $type ) = @_; + + if ( $type && $type =~ /^Nagios::(.*)/ ) { + my $index_type = lc($1) . '_index'; + if ( exists $self->{$index_type} && exists $self->{$index_type}->{$name} ) { + return @{$self->{$index_type}->{$name}}; + } + } + return (); +} + =item find_objects_by_regex() Search through the list of objects' names and return a list of matches. --- ./lib/Nagios/Object.pm.orig 2010-12-02 11:52:32.000000000 -0500 +++ ./lib/Nagios/Object.pm 2010-12-02 11:54:16.000000000 -0500 @@ -174,7 +174,7 @@ alias => [ 'STRING', 280 ], contact_groups => [ ['Nagios::ContactGroup'], 40 ], members => [ ['Nagios::Host'], 280 ], - name => [ 'hostgroup', 280 ], + name => [ 'hostgroup_name', 280 ], comment => [ 'comment', 280 ], file => [ 'filename', 280 ] },
Subject: prof.out.parse.pl.orig
Download prof.out.parse.pl.orig
application/octet-stream 10.7k

Message body not shown because it is not plain text.

Is there a specific order to apply the patches in for all the tickets you have raised? The attached patch wont apply cleanly and I'd prefer to keep my life simple by following the right order :) Duncs
CC: PIRZYK [...] cpan.org
Subject: Re: [rt.cpan.org #63803] find_object() sufferes performance issues.
Date: Tue, 21 Dec 2010 10:59:19 -0500
To: bug-Nagios-Object [...] rt.cpan.org
From: Jim Pirzyk <jim [...] pirzyk.org>
In order I submitted the tickets. If you need a different patch to change the order, I can do that. - JimP On Dec 21, 2010, at 10:55 AM, Duncan Ferguson via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=63803 > > > Is there a specific order to apply the patches in for all the tickets > you have raised? The attached patch wont apply cleanly and I'd prefer > to keep my life simple by following the right order :) > > Duncs
--- @(#) $Id: dot.signature,v 1.15 2007/12/27 15:06:13 pirzyk Exp $ __o jim@pirzyk.org ------------------------------------------- _'\<,_ (*)/ (*) I'd rather be out biking.
Download PGP.sig
application/pgp-signature 479b

Message body not shown because it is not plain text.

Fixed in git.