Skip to content

Optimize SFTP download performance with persistent streaming#33

Draft
VulcanoSoftware wants to merge 2 commits into
mainfrom
fix/sftp-download-speed-1456466687842950070
Draft

Optimize SFTP download performance with persistent streaming#33
VulcanoSoftware wants to merge 2 commits into
mainfrom
fix/sftp-download-speed-1456466687842950070

Conversation

@VulcanoSoftware

Copy link
Copy Markdown
Owner

Optimized SFTP download speeds by implementing a persistent streaming mechanism in DCFSSFTPBufferedFile. Previously, every SFTP read request (often 32KB) would open a new download stream from the backend. This was particularly slow with encryption enabled, as each plaintext read required re-downloading and re-decrypting at least one 64KB ciphertext chunk. The new implementation keeps the stream open and reuses it for sequential reads, significantly reducing CDN overhead and CPU usage. It also includes attribute caching for fstat and proper resource management via aclose().


PR created automatically by Jules for task 1456466687842950070 started by @VulcanoSoftware

Modified `DCFSSFTPBufferedFile` to maintain an active download stream across multiple `read` calls. This eliminates the massive overhead of re-initializing the stream and re-downloading/decrypting the same ciphertext chunks for sequential small reads, which was previously limiting download speeds to ~30 KBps.

Changes:
- Added `_read_stream`, `_read_iter`, and `_read_pos` to track streaming state.
- Implemented offset-based seek detection to reuse the stream or re-initialize if needed.
- Added `_read_lock` for task-safety during concurrent reads.
- Cached file attributes in `fstat` to reduce redundant metadata lookups.
- Ensured proper cleanup of the download stream in `close()` and during seeks.

Co-authored-by: VulcanoSoftware <113239901+VulcanoSoftware@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Mypy complained about `anext` receiving an `Optional[AsyncIterator]`. Added a cast to satisfy the type checker, as the logic ensures the iterator is not None at that point.

Co-authored-by: VulcanoSoftware <113239901+VulcanoSoftware@users.noreply.github.com>
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