SFTP protocol is very susceptible no network latency due to its design. An SFTP file transfer consists of series of requests/responses, where the client requests the server to read or write short blocks of data, usually less than 64 KB each (the size can be customized using UploadBufferSize
and DownloadBufferSize
properties in FileServer.Settings
).
This means that for transferring a large file, the SFTP client has to issue thousands of read or write requests. The only reason why performance of SFTP does not suffer badly on high-latency connections due to high RTT is the fact that most SFTP clients use pipelining - they send many requests in advance, without waiting for response to each of them. The queue length varies fro client to client (some clients are known to queue more than 100 requests in advance).
Additionally, SFTP runs over SSH, which supports multiple channels withing the same SSH session (which runs over a single TCP connection), where each channel has its own independent send/receive buffers and its own flow control. This applies even if only a single channel is used, as with most SFTP connections. It also implies that simply tweaking TCP send/receive buffer sizes might not sufficient in order to achieve higher throughput.
Rebex File Server library provides some settings to address this. It can't force SFTP clients to use a queue length of particular size, but using larger buffers might mitigate some of the effects of increased RTT. Try increasing TCP buffer sizes for SSH session TCP sockets to see whether it makes any noticeable difference:
fileServer.Settings.ReceiveBufferSize = 64 * 1024 * 1024;
fileServer.Settings.SendBufferSize = 64 * 1024 * 1024;
There is also an experimental feature that makes it possible to increase the buffer size of SFTP protocol’s SSH channel. For example, to increases it to 4 MB, call this:
CryptoHelper.SetOption(fileServer.Settings, "SftpChannelBufferSize", 4 * 1024 * 1024);
(Where "fileServer" is an instance of Rebex.Net.Servers.FileServer and "CryptoHelper" is a static Rebex helper class from Rebex.Common assembly’s Rebex.Security.Cryptography namespace.)