Skip to content

Commit 72b88b7

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 508fc87 commit 72b88b7

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
@@ -49,7 +49,7 @@ protected Socket SocketConnect(string host, int port, TimeSpan timeout)
4949
{
5050
SocketAbstraction.Connect(socket, ep, timeout);
5151

52-
const int socketBufferSize = 2 * Session.MaximumSshPacketSize;
52+
const int socketBufferSize = 10 * Session.MaximumSshPacketSize;
5353
socket.SendBufferSize = socketBufferSize;
5454
socket.ReceiveBufferSize = socketBufferSize;
5555
return socket;

src/Renci.SshNet/ServiceFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public INetConfSession CreateNetConfSession(ISession session, int operationTimeo
143143
/// </returns>
144144
public ISftpFileReader CreateSftpFileReader(string fileName, ISftpSession sftpSession, uint bufferSize)
145145
{
146-
const int defaultMaxPendingReads = 3;
146+
const int defaultMaxPendingReads = 10;
147147

148148
// Issue #292: Avoid overlapping SSH_FXP_OPEN and SSH_FXP_LSTAT requests for the same file as this
149149
// causes a performance degradation on Sun SSH
@@ -163,7 +163,7 @@ public ISftpFileReader CreateSftpFileReader(string fileName, ISftpSession sftpSe
163163
{
164164
var fileAttributes = sftpSession.EndLStat(statAsyncResult);
165165
fileSize = fileAttributes.Size;
166-
maxPendingReads = Math.Min(10, (int) Math.Ceiling((double) fileAttributes.Size / chunkSize) + 1);
166+
maxPendingReads = Math.Min(100, (int) Math.Ceiling((double)(fileSize - (long)offset) / chunkSize) + 1);
167167
}
168168
catch (SshException ex)
169169
{

0 commit comments

Comments
 (0)