Menu

#4 slow update, bad refreshperformance, nsc::statuslog::_v2_par

open
nobody
None
5
2014-08-21
2006-04-29
Anonymous
No

nsc v0.80-2

With a nagios installation of a thousand or two
services, the performance of _v2_parser degrades to
unuseable.

nsc::statuslog::_v2_parser

from : nsc/nsc_nagios.pm

Original.

sub _v2_parser {

my $this = shift;
my $lines = join('', @{ $this->{lines} }); #one
long string now

my @res = ();

while ($lines =~ /^(.*) \n([a-z]+) \s+ \{ (.*) \}
(.*)$/xs) {
my ($pre,$typ,$content,$post) = ($1,$2,$3,$4);
$lines = $pre . $post;
my $row = $this->_v2_parse_entry($typ, \$content);
if ($this->{filter_sub} && (!
$this->{filter_sub}->($row))) {
next;
}
push(@res, $row);
}

#debug check, should be empty..
if ($this->{debug}) {
$lines =~ s/\s+//g;
$this->d("remaining lines = '$lines'");
}

return \@res;

} #_v2_parser

The while loop is elegent but slow.

A partialy tested replacement is :

sub _v2_parser {

my $this = shift;
my $lines = join('', @{ $this->{lines} }); #one
long string now

my @res = ();

my @entries;
@entries = grep { /\S+/ } split /\n\s*\n/ms , $lines ;

map {
my $line = $_;
if ($line =~ /^(\s*)([a-z]+) \s+ \{ (.*) \}
(.*)$/xs ){
my ($pre,$typ,$content,$post) = ($1,$2,$3,$4);
my $row = $this->_v2_parse_entry($typ, \$content);
if ($this->{filter_sub} && (!
$this->{filter_sub}->($row))) {
next;
}
push(@res, $row);
}
} @entries;

#debug check, should be empty..
if ($this->{debug}) {
$lines =~ s/\s+//g;
$this->d("remaining lines = '$lines'");
}

return \@res;

} #_v2_parser

Ugly, but 50 X faster. A 9 second call took .18
seconds after the optimization.

Discussion


Log in to post a comment.