Skip to content

Commit 1bdb92f

Browse files
author
Pedro Fonseca
committed
Improve SFTP performance on medium-high latency connections
- Increases maxPendingReads from 10 to 100 - Increases socket send/receive buffer to 10 SSH packets (320K)
1 parent f072c5f commit 1bdb92f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Renci.SshNet/Connection/ConnectorBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected Socket SocketConnect(string host, int port, TimeSpan timeout)
4242
{
4343
SocketAbstraction.Connect(socket, ep, timeout);
4444

45-
const int socketBufferSize = 2 * Session.MaximumSshPacketSize;
45+
const int socketBufferSize = 10 * Session.MaximumSshPacketSize;
4646
socket.SendBufferSize = socketBufferSize;
4747
socket.ReceiveBufferSize = socketBufferSize;
4848
return socket;

src/Renci.SshNet/ServiceFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ from s in serverAlgorithms
112112

113113
public ISftpFileReader CreateSftpFileReader(string fileName, ISftpSession sftpSession, uint bufferSize)
114114
{
115-
const int defaultMaxPendingReads = 3;
115+
const int defaultMaxPendingReads = 10;
116116

117117
// Issue #292: Avoid overlapping SSH_FXP_OPEN and SSH_FXP_LSTAT requests for the same file as this
118118
// causes a performance degradation on Sun SSH
@@ -132,7 +132,7 @@ public ISftpFileReader CreateSftpFileReader(string fileName, ISftpSession sftpSe
132132
{
133133
var fileAttributes = sftpSession.EndLStat(statAsyncResult);
134134
fileSize = fileAttributes.Size;
135-
maxPendingReads = Math.Min(10, (int) Math.Ceiling((double) fileAttributes.Size / chunkSize) + 1);
135+
maxPendingReads = Math.Min(100, (int) Math.Ceiling((double)(fileSize - (long)offset) / chunkSize) + 1);
136136
}
137137
catch (SshException ex)
138138
{

0 commit comments

Comments
 (0)