Conversation
SFTPWriteStream sent a single SSH_FXP_WRITE packet and then blocked on its acknowledgement before sending the next one. That made every write a full round trip, and on low-latency links it additionally triggered a write-then-read (Nagle / delayed-ACK) stall, capping throughput at ~2 MB/s. Mirror phpseclib's SFTP::put() instead: send WRITE packets sized to the negotiated maximum without waiting for each acknowledgement, and drain the acknowledgements in batches (at NET_SFTP_UPLOAD_QUEUE_SIZE, and on flush / close). Throughput becomes bandwidth-bound instead of round-trip-bound. This also fixes a latent issue where the entire flush buffer was sent as a single SSH_FXP_WRITE that could exceed the negotiated maximum packet size. Write throughput, 8 KiB stream chunks, OpenSSH sftp-server (indicative, custom read stream and reads are unchanged as they were already pipelined): | delay | file size | before (sync) | after (pipelined) | phpseclib sftp:// | --------|-----------|---------------|-------------------|-------------------| | LAN | 1 MB | 1.8 MB/s | 307 MB/s | 28 MB/s | | LAN | 8 MB | 1.9 MB/s | 332 MB/s | 38 MB/s | | LAN | 32 MB | 1.9 MB/s | 337 MB/s | 37 MB/s | | ~20ms | 1 MB | 1.3 MB/s | 6.3 MB/s | 0.24 MB/s | | ~20ms | 8 MB | 1.7 MB/s | 20.8 MB/s | 0.24 MB/s | Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
susnux
marked this pull request as ready for review
July 22, 2026 09:29
susnux
requested review from
Altahrim,
come-nc,
leftybournes and
salmart-dev
and removed request for
a team
July 22, 2026 09:29
icewind1991
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Before
SFTPWriteStreamsent a single SSH_FXP_WRITE packet and then blocked on itsacknowledgement before sending the next one. That made every write a full round trip.
After
Mirror phpseclib's
SFTP::put()instead: sendWRITEpackets sized to thenegotiated maximum without waiting for each acknowledgement, and drain the
acknowledgements in batches.
Checklist
3. to review, feature component)stable32)AI (if applicable)
ℹ️ AI was used for creating unit tests and creating the benchmark setup.