Skip to content

Commit

Permalink
[backend] Speedup jobhistory route by 4-6x
Browse files Browse the repository at this point in the history
This is a two part change. But put together to allow context to the next
change.

This patch allows fdb_getall_reverse to return undecoded line to filter.
This raw line can be filtered out earlier without the need of decoding
over the layout.

This is useful for large and long maintained projects. Projects
(Factory, Devel..)  have a long build history, decoding every
line in the jobhistory file only to be filtered out based on filter
conditions (package type, result code, buildtimes) is expensive. This
patch facilitates skipping those costs reach the result faster.

Tested on IBS/SUSE:FACTORY:HEAD/standard/i586/MozillaThunderbird
without patch:
100 results: 6 sec
1000 results: 53 sec

with patch:
100 results: 1 sec
1000 results: 13 sec
  • Loading branch information
Sumit Jamgade committed May 26, 2020
1 parent 09fb69e commit 90ba8fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
16 changes: 14 additions & 2 deletions src/backend/BSFileDB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ sub decode_line {
return $r;
}

sub encode_field {
my ($str) = @_;
$str =~ s/([\000-\037%|=\177-\237])/sprintf("%%%02X", ord($1))/ge;
return $str;
}

sub encode_line {
my ($r, $lay) = @_;
my @line;
Expand Down Expand Up @@ -229,9 +235,15 @@ sub fdb_getall_reverse {
@l = split("\n", $buf, -1);
}
for (reverse @l) {
my $r = decode_line($_, $lay);
my $r = $_;
$r = decode_line($_, $lay) if defined($lay);
if ($filter) {
my $f = $filter->($r);
my $f;
if (defined($lay)) {
$f = $filter->($r);
} else {
$f = $filter->(split('\|', $r));
}
next unless $f;
if ($f < 0) {
push @res, $r if $f == -1;
Expand Down
22 changes: 14 additions & 8 deletions src/backend/bs_repserver
Original file line number Diff line number Diff line change
Expand Up @@ -3154,24 +3154,30 @@ sub getjobhistory {
if ($cgi->{'code'} && @{$cgi->{'code'}} == 1 && $cgi->{'code'}->[0] eq 'lastfailures') {
return getlastfailures($cgi, $projid, $repoid, $arch);
}
my $idx = 0;
my %indices = map {$_ => $idx++} @$BSXML::jobhistlay;
my $packidx = $indices{'package'};
my $codeidx = $indices{'code'};
my $endtimeidx = $indices{'endtime'};
if ($cgi->{'package'} && $cgi->{'code'}) {
my %packid = map {$_ => 1} @{$cgi->{'package'}};
my %packid = map {BSFileDB::encode_field($_) => 1} @{$cgi->{'package'}};
my %code = map {$_ => 1} @{$cgi->{'code'}};
$filter = sub {$packid{$_[0]->{'package'}} && $code{$_[0]->{'code'}}};
$filter = sub {$packid{$_[$packidx]} && $code{$_[$codeidx]}};
} elsif ($cgi->{'package'}) {
my %packid = map {$_ => 1} @{$cgi->{'package'}};
$filter = sub {$packid{$_[0]->{'package'}}};
my %packid = map {BSFileDB::encode_field($_) => 1} @{$cgi->{'package'}};
$filter = sub {$packid{$_[$packidx]}};
} elsif ($cgi->{'code'}) {
my %code = map {$_ => 1} @{$cgi->{'code'}};
$filter = sub {$code{$_[0]->{'code'}}};
$filter = sub {$code{$_[$codeidx]}};
}
if ($cgi->{'endtime_start'} || $cgi->{'endtime_end'} || 1) {
if ($cgi->{'endtime_start'} || $cgi->{'endtime_end'}) {
my $filter2 = $filter;
my $endtime_start = $cgi->{'endtime_start'} || 0;
my $endtime_end = $cgi->{'endtime_end'};
$filter = sub {$_[0]->{'endtime'} < $endtime_start ? -2 : defined($endtime_end) && $_[0]->{'endtime'} > $endtime_end ? 0 : $filter2 ? $filter2->($_[0]) : 1};
$filter = sub { $_[$endtimeidx] < $endtime_start ? -2 : defined($endtime_end) && $_[$endtimeidx] > $endtime_end ? 0 : $filter2 ? $filter2->(@_) : 1 };
}
my @hist = BSFileDB::fdb_getall_reverse("$reporoot/$projid/$repoid/$arch/:jobhistory", $BSXML::jobhistlay, $cgi->{'limit'} || 100, $filter);
my @hist = BSFileDB::fdb_getall_reverse("$reporoot/$projid/$repoid/$arch/:jobhistory", undef, $cgi->{'limit'} || 100, $filter);
@hist = map {BSFileDB::decode_line($_, $BSXML::jobhistlay)} @hist;
@hist = reverse @hist;
my $ret = {jobhist => \@hist};
return ($ret, $BSXML::jobhistlist);
Expand Down

0 comments on commit 90ba8fa

Please sign in to comment.