1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-09-02 12:41:14 +03:00

Inflate performance improvement for gzip filter and full unit test coverage.

This commit is contained in:
David Steele
2017-11-14 15:12:31 -05:00
parent 04e55fe71b
commit b8746f368d
4 changed files with 26 additions and 17 deletions

View File

@@ -57,6 +57,10 @@
<release-item> <release-item>
<p>Simplify try..catch..finally names.</p> <p>Simplify try..catch..finally names.</p>
</release-item> </release-item>
<release-item>
<p>Inflate performance improvement for gzip filter.</p>
</release-item>
</release-refactor-list> </release-refactor-list>
</release-core-list> </release-core-list>
@@ -78,6 +82,10 @@
<release-item> <release-item>
<p>Update Debian/Ubuntu containers to download latest version of <file>pip</file>.</p> <p>Update Debian/Ubuntu containers to download latest version of <file>pip</file>.</p>
</release-item> </release-item>
<release-item>
<p>Full unit test coverage for gzip filter.</p>
</release-item>
</release-refactor-list> </release-refactor-list>
</release-test-list> </release-test-list>
</release> </release>

View File

@@ -156,29 +156,26 @@ sub read
else else
{ {
# If the local buffer size is not large enough to satisfy the request and there is still data to decompress # If the local buffer size is not large enough to satisfy the request and there is still data to decompress
if ($self->{lUncompressedBufferSize} < $iSize) while ($self->{lUncompressedBufferSize} < $iSize && !$self->parent()->eof())
{ {
while ($self->{lUncompressedBufferSize} < $iSize) if (!defined($self->{tCompressedBuffer}) || length($self->{tCompressedBuffer}) == 0)
{ {
if (!defined($self->{tCompressedBuffer}) || length($self->{tCompressedBuffer}) == 0) $self->parent()->read(\$self->{tCompressedBuffer}, $self->{lCompressBufferMax});
{
$self->parent()->read(\$self->{tCompressedBuffer}, $self->{lCompressBufferMax});
}
my $iZLibStatus = $self->{oZLib}->inflate($self->{tCompressedBuffer}, $self->{tUncompressedBuffer});
$self->{lUncompressedBufferSize} = length($self->{tUncompressedBuffer});
last if $iZLibStatus == Z_STREAM_END;
$self->errorCheck($iZLibStatus);
} }
my $iZLibStatus = $self->{oZLib}->inflate($self->{tCompressedBuffer}, $self->{tUncompressedBuffer});
$self->{lUncompressedBufferSize} = length($self->{tUncompressedBuffer});
last if $iZLibStatus == Z_STREAM_END;
$self->errorCheck($iZLibStatus);
} }
# Actual size is the lesser of the local buffer size or requested size - if the local buffer is smaller than the requested # Actual size is the lesser of the local buffer size or requested size - if the local buffer is smaller than the requested
# size it means that there was nothing more to be read # size it means that there was nothing more to be read
my $iActualSize = $self->{lUncompressedBufferSize} < $iSize ? $self->{lUncompressedBufferSize} : $iSize; my $iActualSize = $self->{lUncompressedBufferSize} < $iSize ? $self->{lUncompressedBufferSize} : $iSize;
# Append the to the request buffer # Append to the request buffer
$$rtBuffer .= substr($self->{tUncompressedBuffer}, 0, $iActualSize); $$rtBuffer .= substr($self->{tUncompressedBuffer}, 0, $iActualSize);
# Truncate local buffer # Truncate local buffer
@@ -206,7 +203,7 @@ sub write
$self->errorCheck($self->{oZLib}->deflate($$rtBuffer, $self->{tCompressedBuffer})); $self->errorCheck($self->{oZLib}->deflate($$rtBuffer, $self->{tCompressedBuffer}));
# Only write when buffer is full # Only write when buffer is full
if (defined($self->{tCompressedBuffer}) && length($self->{tCompressedBuffer}) > $self->{lCompressBufferMax}) if (length($self->{tCompressedBuffer}) > $self->{lCompressBufferMax})
{ {
$self->parent()->write(\$self->{tCompressedBuffer}); $self->parent()->write(\$self->{tCompressedBuffer});
$self->{tCompressedBuffer} = undef; $self->{tCompressedBuffer} = undef;
@@ -260,6 +257,8 @@ sub close
# Close io # Close io
return $self->parent()->close(); return $self->parent()->close();
} }
return false;
} }
1; 1;

View File

@@ -329,7 +329,7 @@ my $oTestDef =
&TESTDEF_COVERAGE => &TESTDEF_COVERAGE =>
{ {
'Storage/Filter/Gzip' => TESTDEF_COVERAGE_PARTIAL, 'Storage/Filter/Gzip' => TESTDEF_COVERAGE_FULL,
}, },
}, },
{ {

View File

@@ -63,7 +63,8 @@ sub run
{ {
#--------------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------------------------------
my $oGzipIo = $self->testResult( my $oGzipIo = $self->testResult(
sub {new pgBackRest::Storage::Filter::Gzip($oDriver->openWrite($strFileGz))}, '[object]', 'new write compress'); sub {new pgBackRest::Storage::Filter::Gzip($oDriver->openWrite($strFileGz), {lCompressBufferMax => 4})},
'[object]', 'new write compress');
my $tBuffer = substr($strFileContent, 0, 2); my $tBuffer = substr($strFileContent, 0, 2);
$self->testResult(sub {$oGzipIo->write(\$tBuffer)}, 2, ' write 2 bytes'); $self->testResult(sub {$oGzipIo->write(\$tBuffer)}, 2, ' write 2 bytes');
@@ -125,6 +126,7 @@ sub run
$self->testResult(sub {$oGzipIo->read(\$tBuffer, 2)}, 0, ' read 0 bytes'); $self->testResult(sub {$oGzipIo->read(\$tBuffer, 2)}, 0, ' read 0 bytes');
$self->testResult(sub {$oGzipIo->close()}, true, ' close'); $self->testResult(sub {$oGzipIo->close()}, true, ' close');
$self->testResult(sub {$oGzipIo->close()}, false, ' close again');
$self->testResult($tBuffer, $strFileContent, ' check content'); $self->testResult($tBuffer, $strFileContent, ' check content');
storageTest()->remove($strFileGz); storageTest()->remove($strFileGz);