Skip to content

perf: create upload parents only when the upload fails without them - #101

Merged
shcheklein merged 3 commits into
mainfrom
perf/upload-makedirs-on-demand
Nov 29, 2026
Merged

shcheklein merged 3 commits into
mainfrom
perf/upload-makedirs-on-demand

Conversation

@shcheklein

@shcheklein shcheklein commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

put_file and pipe_file call makedirs on the parent before every upload, and asyncssh's makedirs sends a MKDIR for each path component, plus a STAT when the directory exists. Uploads into an existing directory paid about two round trips per component.

Uploads now run first, and create the parent directories and retry only when they fail with SFTPNoSuchFile. The retry takes a new channel, so an upload never holds one channel while waiting for another. Top-level paths, whose parent is "", never retry, as before (#91).

SFTP requests counted against the test server by wrapping SFTPClientHandler._make_request, for a directory 20 levels deep:

main this PR
put_file into an existing directory 46 4
pipe_file into an existing directory 45 3
put_file into a new directory 47 49

One behavior change: a put_file whose local file is missing no longer creates the remote parent directories before failing.

The tests record asyncssh's SFTPClient.makedirs calls. Uploads into an existing directory make none, pipe_file into a new nested directory makes one, and a missing local file leaves no remote directory behind.

Fixes #89.

🤖 Generated with Claude Code

put_file and pipe_file called makedirs on the parent before every
upload, and asyncssh's makedirs sends a MKDIR, plus a STAT when the
directory exists, for each path component. Uploads now run first and
create the parents and retry only when they fail with SFTPNoSuchFile.
The retry takes a new channel, so an upload never holds one channel
while waiting for another.

A put_file whose local file is missing no longer creates the remote
parent directories before failing.

Fixes #89.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use asyncssh.SFTPNoSuchFile instead of editing the asyncssh.sftp import,
and define the makedirs_calls fixture next to the tests that use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Both upload methods fail to create missing parent directories when SFTP v4+ servers raise SFTPNoSuchPath, regressing automatic directory creation.

1 open issue
What changed in this PR

This PR reduces SFTP round trips for uploads into existing directories, addressing #89 while preserving the relative and top-level path handling from #91.

Changes:

  • Attempts uploads first, creating missing parents and retrying on a fresh channel after SFTPNoSuchFile.
  • Avoids creating remote directories when the local upload file is missing.
  • Adds tests for skipped directory creation, missing-parent recovery, and missing local files.
File Description
tests/​test_sshfs.py Records directory-creation calls and tests the updated upload behavior.
sshfs/​spec.py Shares upload-first retry logic between put_file and pipe_file.

Review effort: Balanced

Comment thread sshfs/spec.py Resolved
With SFTP v4 and later, a server can report a missing parent directory
as SFTPNoSuchPath, which isn't a subclass of SFTPNoSuchFile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the upload-first retry change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

shcheklein added a commit that referenced this pull request Nov 29, 2026
Avoids a conflict with #101, which changes the asyncssh.sftp import
next to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shcheklein added a commit that referenced this pull request Nov 29, 2026
* perf: run uname once per filesystem instead of on every checksum

checksum ran uname on the server before every md5sum or md5 command
to pick between them. The server's OS can't change while the
filesystem is connected, so _get_system now caches the result.

Fixes #90.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: run uname once when the first checksums are concurrent

Concurrent first calls each saw no cached result and ran their own
uname. A lock now makes them wait for one, and the test covers
concurrent first calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: patch the client's class instead of importing it

Avoids a conflict with #101, which changes the asyncssh.sftp import
next to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@shcheklein shcheklein self-assigned this Nov 29, 2026
@shcheklein
shcheklein merged commit 346fa68 into main Nov 29, 2026
11 checks passed
@shcheklein
shcheklein deleted the perf/upload-makedirs-on-demand branch November 29, 2026 17:39
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.

put_file and pipe_file send two SFTP requests per path component before every upload

2 participants