fix(server): compress database backups on 75% of the cores, up to 32 (#32823)

(cherry picked from commit 02c0d4d392217b02b670afb0b4ce9941330120ec)
This commit is contained in:
Zack Pollard
2026-10-31 07:22:45 +03:00
committed by Codex
parent e708a80474
commit 92cf23b642
2 changed files with 12 additions and 4 deletions
@@ -241,11 +241,19 @@ describe(DatabaseBackupService.name, () => {
expect(mocks.process.spawnDuplexStream).toHaveBeenLastCalledWith('gzip', ['--rsyncable']);
});
it('should compress with pigz on every available core when it is installed', async () => {
it.each([
{ cores: 1, processes: '1' },
{ cores: 8, processes: '6' },
{ cores: 72, processes: '32' },
])('should compress with pigz on $processes of $cores cores when it is installed', async ({ cores, processes }) => {
mocks.process.isCommandAvailable.mockResolvedValue(true);
mocks.process.availableParallelism.mockReturnValue(8);
mocks.process.availableParallelism.mockReturnValue(cores);
await sut.handleBackupDatabase();
expect(mocks.process.spawnDuplexStream).toHaveBeenLastCalledWith('pigz', ['--rsyncable', '--processes', '8']);
expect(mocks.process.spawnDuplexStream).toHaveBeenLastCalledWith('pigz', [
'--rsyncable',
'--processes',
processes,
]);
});
it('should fail if pg_dump fails', async () => {
@@ -271,7 +271,7 @@ export class DatabaseBackupService {
private async getCompressionCommand() {
if (await this.processRepository.isCommandAvailable('pigz')) {
const processes = this.processRepository.availableParallelism();
const processes = Math.min(Math.max(Math.floor(this.processRepository.availableParallelism() * 0.75), 1), 32);
return { command: 'pigz', args: ['--rsyncable', '--processes', processes.toString()] };
}