Read ahead over SFTP: one connection with 32 requests in flight by default, more with restore_sftp_connections; a Storage Box gets slower with parallel readers
This commit is contained in:
@@ -79,9 +79,9 @@ class SftpRangeFetcherTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testKeepsSeveralRequestsInFlightOnEachConnection(): void {
|
||||
$this->files['/home/repo/packs/big'] = random_bytes(6 * 1048576);
|
||||
$this->files['/home/repo/packs/big'] = random_bytes(10 * 1048576);
|
||||
$connections = $this->connections(2);
|
||||
self::collect(SftpRangeFetcher::fetch(self::opened($connections), '/home/', [['repo/packs/big', 0, 6 * 1048576], ['repo/packs/big', 5, 6 * 1048576 - 5]], $this->tempDir()));
|
||||
self::collect(SftpRangeFetcher::fetch(self::opened($connections), '/home/', [['repo/packs/big', 0, 10 * 1048576], ['repo/packs/big', 5, 10 * 1048576 - 5]], $this->tempDir()));
|
||||
|
||||
$this->assertSame(SftpRangeFetcher::DEPTH, $connections[0]->maxInFlight);
|
||||
$this->assertSame(SftpRangeFetcher::DEPTH, $connections[1]->maxInFlight);
|
||||
|
||||
@@ -53,6 +53,7 @@ class StorageBackendReadAheadTest extends TestCase {
|
||||
|
||||
public function testReadsAheadOnNewConnectionsOnly(): void {
|
||||
$backend = new StorageBackend($this->storage(), 'base/repo', false, fn (): IStorage => $this->storage());
|
||||
$backend->readAheadConnections = 4;
|
||||
$this->assertTrue($backend->canReadAhead());
|
||||
|
||||
$result = [];
|
||||
@@ -62,7 +63,7 @@ class StorageBackendReadAheadTest extends TestCase {
|
||||
|
||||
$expected = array_map(fn (int $i): string => sha1(substr($this->files["/home/base/repo/packs/p$i"], 7, 1048576 - 7)), range(0, 5));
|
||||
$this->assertSame($expected, $result);
|
||||
$this->assertCount(1 + SftpRangeFetcher::CONNECTIONS, $this->connections);
|
||||
$this->assertCount(1 + 4, $this->connections);
|
||||
$this->assertSame(0, $this->connections[0]->sent, 'the storage\'s own connection stays free');
|
||||
foreach (array_slice($this->connections, 1) as $c) {
|
||||
$this->assertTrue($c->disconnected);
|
||||
@@ -72,6 +73,7 @@ class StorageBackendReadAheadTest extends TestCase {
|
||||
public function testGoesOnWithTheConnectionsTheServerAllows(): void {
|
||||
$this->connectLimit = 3;
|
||||
$backend = new StorageBackend($this->storage(), 'base/repo', false, fn (): IStorage => $this->storage());
|
||||
$backend->readAheadConnections = 4;
|
||||
|
||||
$count = 0;
|
||||
foreach ($backend->readAhead(self::ranges(), $this->tempDir()) as $fh) {
|
||||
@@ -83,6 +85,16 @@ class StorageBackendReadAheadTest extends TestCase {
|
||||
$this->assertCount(3, $this->connections);
|
||||
}
|
||||
|
||||
public function testByDefaultOneConnectionNextToTheStoragesOwn(): void {
|
||||
$backend = new StorageBackend($this->storage(), 'base/repo', false, fn (): IStorage => $this->storage());
|
||||
foreach ($backend->readAhead(self::ranges(), $this->tempDir()) as $fh) {
|
||||
$this->assertIsResource($fh);
|
||||
}
|
||||
|
||||
$this->assertSame(1, SftpRangeFetcher::DEFAULT_CONNECTIONS);
|
||||
$this->assertCount(2, $this->connections);
|
||||
}
|
||||
|
||||
public function testNoNewConnectionMeansNoReadingAhead(): void {
|
||||
$this->connectLimit = 1;
|
||||
$backend = new StorageBackend($this->storage(), 'base/repo', false, fn (): IStorage => $this->storage());
|
||||
|
||||
@@ -191,7 +191,7 @@ if [ "$MODE" = sftp ]; then
|
||||
LOGINS=$(( $(sftp_logins) - LOGINS_BEFORE ))
|
||||
[ "$LOGINS" -gt 1 ] || fail "the restore did not read ahead on connections of its own ($LOGINS SFTP logins)"
|
||||
docker exec ngb-frt-restore sh -c 'ls -a /var/www/html/data' | grep -q ngb-restore-spool && fail "the spool folder was left behind"
|
||||
ok "over SFTP: read ahead on $LOGINS connections, large file identical, no spool left"
|
||||
ok "over SFTP: read ahead on connections of its own ($LOGINS SFTP logins during the restore), large file identical, no spool left"
|
||||
fi
|
||||
|
||||
run_on ngb-frt-restore backup:run offsite -l post-restore-check >/dev/null || fail "a new backup after the restore fails"
|
||||
|
||||
Reference in New Issue
Block a user