Skip to content

Share an elastic SFTP connection pool; faster, chunked initial sync - #21

Merged
SteveIves merged 2 commits into
masterfrom
connection-pool
Nov 20, 2026
Merged

SteveIves merged 2 commits into
masterfrom
connection-pool

Conversation

@SteveIves

Copy link
Copy Markdown
Collaborator

Why

Each search pattern had its own permanent SFTP connection (about 20 idle connections per user), plus about 20 more during the initial sync. Many developers share one server, so this was a lot of connections. The initial sync was also unbalanced: work was split per (directory, pattern), so one directory with thousands of files was a single worker's job while the rest sat idle.

What changed

  • One sync engine (RemoteSync) now handles all patterns, replacing one per pattern.
  • Real-time uploads go through a small elastic pool (SftpConnectionPool): connections open only when work needs them, up to MaxConnections (default 6), and idle ones close after 60s. One is kept warm and kept alive. Changes are queued and coalesced per file, the same file is never uploaded on two connections at once, and directory create/delete/rename wait for earlier uploads.
  • Initial sync scans each directory once, splits large directories into chunks of 50 files and uploads the largest first, spread over InitialSyncWorkers (default 20) connections. A retry resumes at the file that failed. Stopping the sync now stops the workers.
  • Delete before replace no longer does a separate Exists check: it tries DeleteFile and ignores only "file not found", with an Exists fallback for servers that report that differently. Any other delete failure still stops that upload, so a replaced file cannot keep stale bytes at its end.
  • Messages and progress: the per-worker and per-directory/pattern messages are gone. The log shows X of Y files uploaded (Z%) every 5 seconds, the status bar shows the same, and a final line gives the elapsed time.
  • New JSON-only settings InitialSyncWorkers and MaxConnections. The console SFTPSync app uses the new engine too.

Behaviour changes

  • If the upload of a renamed file fails after all retries, the old remote file is no longer deleted (previously it was deleted anyway).
  • A file that disappears before it can be uploaded is skipped quietly instead of retried five times.

Testing

Run against a slow, shared VMS server with about 15,500 files in 59 directories, 20 initial sync connections:

Run Time
Empty remote 241.8 s
Files already present (before removing Exists) 300.7 s
Files already present (after removing Exists) 233.8 s

Throughput is flat to the end, so there is no tail from large directories. The server is the limiting factor. The solution builds with no errors or warnings. There are no automated tests in the repo; the real-time paths (branch switch, delete, rename) were not exercised in these runs.

Not included: the new settings are not in docs/sftpsyncui.html, and there is no skip-unchanged-files optimisation.

🤖 Generated with Claude Code

SteveIves and others added 2 commits November 20, 2026 12:13
…erns.

Real-time uploads now go through one pool (default max 6, idle connections closed after 60s, one kept warm) instead of one permanent connection per pattern. Changes are queued and coalesced per file.

The initial sync scans each directory once, splits large directories into chunks and uploads the largest first, so the work is spread evenly over the connections whatever the mix of extensions. It reports files done out of total every 5 seconds and in the status bar.

New settings InitialSyncWorkers (default 20) and MaxConnections (default 6).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Try the delete and ignore only 'file not found' (falling back to an existence check if the server reports a missing file as another failure), saving a round trip per existing file. Any other delete failure still stops the upload, so a replaced file can never keep stale bytes at its end.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@SteveIves
SteveIves merged commit fc0460e into master Nov 20, 2026
1 check passed
@SteveIves
SteveIves deleted the connection-pool branch November 20, 2026 20:46
@SteveIves SteveIves mentioned this pull request Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant