Skip to content

Commit

Permalink
Merge pull request #4782 from MichaelEischer/fix-sftp-performance
Browse files Browse the repository at this point in the history
Fix sftp upload performance
  • Loading branch information
MichaelEischer committed May 12, 2024
2 parents e4f9bce + a1d682c commit b5fdb1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/issue-4209
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Fix slow sftp upload performance

Since restic 0.12.1, the upload speed of the sftp backend to a remote server
has regressed significantly. This has been fixed.

https://github.com/restic/restic/issues/4209
https://github.com/restic/restic/pull/4782
9 changes: 7 additions & 2 deletions internal/backend/sftp/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ func startClient(cfg Config) (*SFTP, error) {
}()

// open the SFTP session
client, err := sftp.NewClientPipe(rd, wr)
client, err := sftp.NewClientPipe(rd, wr,
// write multiple packets (32kb) in parallel per file
// not strictly necessary as we use ReadFromWithConcurrency
sftp.UseConcurrentWrites(true),
// increase send buffer per file to 4MB
sftp.MaxConcurrentRequestsPerFile(128))
if err != nil {
return nil, errors.Errorf("unable to start the sftp session, error: %v", err)
}
Expand Down Expand Up @@ -359,7 +364,7 @@ func (r *SFTP) Save(_ context.Context, h backend.Handle, rd backend.RewindReader
}()

// save data, make sure to use the optimized sftp upload method
wbytes, err := f.ReadFrom(rd)
wbytes, err := f.ReadFromWithConcurrency(rd, 0)
if err != nil {
_ = f.Close()
err = r.checkNoSpace(dirname, rd.Length(), err)
Expand Down

0 comments on commit b5fdb1d

Please sign in to comment.