Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SFTPStorage #1194

Merged
merged 4 commits into from Nov 9, 2022
Merged

Conversation

vainu-arto
Copy link
Contributor

  • Move seekability test to a separate helper function
  • Stop calling content.open() from SFTPStorage._save
  • Require at least version 1.10.0 of paramiko
  • Use SFTPClient.putfo() in SFTPStorage._save()

This produces a fairly major difference in performance, the original version needs over 10x the time it takes for the modified version to transfer a 380M test file. Transferring said file with the current version also requires about 2 gigabytes of memory, which drops to 50 megabytes after the change.

Having a third copy of this code would feel silly.
The open method isn't available in all file-like objects one might want to
save using the storage framework, so instead of relying on it calling
seek(0) for us do it ourselves (conditionally).
This version introduced the SFTPClient.putfo() method. It was released in
early 2013, so this shouldn't be a great hardship.
Instead of using SFTPClient.open() to get a file-like object, reading the
entire content into memory and then calling .write() on that.

The measured performance difference is stunning, and the uploaded file data
no longer needs to fit into memory.
@jschneier jschneier merged commit 04676b5 into jschneier:master Nov 9, 2022
@jschneier
Copy link
Owner

Looks great, thanks.

@vainu-arto vainu-arto deleted the improve-sftpstorage branch November 10, 2022 05:34
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.

None yet

2 participants