ChunkedBackupDriver: Freeing memory on restore

When restoring many backups, the backup service uses a lot of memory and
when we do many concurrent restores the backup service ends up getting
killed becase the system runs out of memory.

This patch reduces the ref count to the data as soon as possible to let
Python garbage collect it instead of hogging it for the whole chunk
restore.

Related-Bug: #1865011
Change-Id: I942d9d8b3976232ae1cf82b698fb27285fbef13a
(cherry picked from commit 69462315bc)
(cherry picked from commit 94db15dd3b)
(cherry picked from commit f4aa81424f)
This commit is contained in:
Gorka Eguileor 2020-02-27 14:04:13 +01:00 committed by David Hill
parent bcea359d54
commit 20b6b7477d
1 changed files with 3 additions and 0 deletions

View File

@ -711,9 +711,12 @@ class ChunkedBackupDriver(driver.BackupDriver):
LOG.debug('decompressing data using %s algorithm',
compression_algorithm)
decompressed = decompressor.decompress(body)
body = None # Allow Python to free it
volume_file.write(decompressed)
decompressed = None # Allow Python to free it
else:
volume_file.write(body)
body = None # Allow Python to free it
# force flush every write to avoid long blocking write on close
volume_file.flush()