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:
2026-10-19 07:46:12 +02:00
parent 6121f684e9
commit c95f552cc6
8 changed files with 47 additions and 22 deletions
+5 -2
View File
@@ -29,6 +29,8 @@ final class StorageBackend implements IBackend, IReadsAhead {
/** Seconds without a request after which an SFTP connection is checked before it is used. */
public const IDLE_CHECK = 60;
private float $lastUsed;
/** Connections readAhead() opens (see SftpRangeFetcher::DEFAULT_CONNECTIONS). */
public int $readAheadConnections = SftpRangeFetcher::DEFAULT_CONNECTIONS;
/** Times the storage was built anew after its connection died (for tests and diagnostics). */
public int $reconnects = 0;
@@ -244,7 +246,7 @@ final class StorageBackend implements IBackend, IReadsAhead {
}
/**
* Over SFTP: SftpRangeFetcher, on CONNECTIONS new connections of its own (built with the
* Over SFTP: SftpRangeFetcher, on readAheadConnections new connections of its own (built with the
* reconnect function), so the storage's connection stays free for other requests. Elsewhere
* not (yet): null.
*/
@@ -262,7 +264,8 @@ final class StorageBackend implements IBackend, IReadsAhead {
$storages = [];
$connections = [];
$root = '';
for ($n = 0; $n < SftpRangeFetcher::CONNECTIONS; $n++) {
$wanted = max(1, min(SftpRangeFetcher::MAX_CONNECTIONS, $this->readAheadConnections));
for ($n = 0; $n < $wanted; $n++) {
try {
$storage = $reconnect();
$sftp = SftpReadStream::connection($storage);