Skip to content

Download Speed Slow #145

Description

@Dailison

With WinScp plugin i have 1,6MB/s download speed, with SSH.NET my download is 70 KBPs or lesss, how i can fix this?

I'm using the last versions of Both and VS2015 Nugget Plugins

Code SSH.nET:
using (var client = new SftpClient("XXXXX", "XXXX", "XXXX"))
{
client.Connect();
if (client.IsConnected)
{
Program.setLog("Demorou " + TimeSpan.FromSeconds((DateTime.Now - startTime).TotalSeconds) + " ms para conectar!");
Program.setLog("Baixando: " + client.WorkingDirectory + strRmPath);
using (Stream stream = File.OpenWrite(strLcGz))
{
client.DownloadFile(strRmPath, stream);
}
var timespan = TimeSpan.FromSeconds((DateTime.Now - startTime).TotalSeconds);
var size = (new FileInfo(strLcGz).Length / 1024) / 1024;
var speed = size / timespan.TotalSeconds;
Program.setLog("Speed: " + speed + " MB/s");
Program.setLog("Demorou " + timespan + " ms para baixar!");
Program.setLog("Download concluido!");
client.Disconnect();
}
}
Code WinScp:

SessionOptions soptSettings = new SessionOptions();
soptSettings.Protocol = Protocol.Sftp;
soptSettings.HostName = "XXXX";
soptSettings.UserName = "XXXX";
soptSettings.Password = "XXXX";
//soptSettings.SshHostKeyFingerprint = "XXXXXXXX";
Program.setLog("Demorou " + TimeSpan.FromSeconds((DateTime.Now - startTime).TotalSeconds) + " ms para conectar!");
Program.setLog("Baixando: " + strRmPath);
using (WinSCP.Session sesConnection = new WinSCP.Session())
{
sesConnection.Open(soptSettings);
TransferOptions toptStreamSettings = new TransferOptions();
toptStreamSettings.TransferMode = TransferMode.Binary;
sesConnection.GetFiles(strRmPath, strLcGz, false, toptStreamSettings);
}
var timespan = TimeSpan.FromSeconds((DateTime.Now - startTime).TotalSeconds);
var size = (new FileInfo(strLcGz).Length / 1024) / 1024;
var speed = size / timespan.TotalSeconds;
Program.setLog("Speed: {0} MB/s" + speed);
Program.setLog("Demorou " + timespan + " ms para baixar!");
Program.setLog("Download concluido para pasta: " + strLcGz);

Activity

  1. changed the title [-]Download soo Slow[/-] [+]Download Speed Slow[/+] on Dec 30, 2016
  2. drieseng commented on Jan 4, 2017

    @drieseng
    Member

    What SSH server are you using ?
    Would it possible to set up a VM that hosts the SSH server, and share it with me if you can reproduce this issue with that VM?

  3. Dailison commented on Jan 4, 2017

    @Dailison
    Author

    I can create a sftp user into the machine and you can use, it's a OVH Host VPN.

    user: easykits
    pass: SENDED FOR YOU IN EMAIL gertdriesen@msn.com

    Upload a file and try'it....

    I stop to SFTP beacause that problem and start to use FTP.

    I try to use WinScp but is a bad idea install that program in my users...

    I'm here for help you resolve that problem....

  4. drieseng commented on Jan 12, 2017

    @drieseng
    Member

    I'm making good progress on this as part of issue #100.
    I'll update this issue once I have new performance numbers for downloading from the OVH host.

  5. imapangolin commented on Jan 19, 2017

    @imapangolin

    I'm experiencing the same slow down. I don't know the SFTP host software but with FileZilla my 28 meg download takes 8 seconds. Over a minute with SSH.NET. Here's my code. I've dinked around with buffer sizes but that appears to be the only thing I can set that will impact it. 4K buffer gives me a 2 minute+ transfer. This 63K buffer gives me the minute. I'm using the beta1 pre-release package.

        public string GetFileSFTP(string ClientFileName, string ServerFileName, string ServerName, string Port, string UserID, string Password)
        {
        System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        string Result = "Success";
        try
        {
            using (var client = new SftpClient(ServerName, Convert.ToInt32(Port), UserID, Password))
            {
                client.Connect();
    
                client.BufferSize = 63 * 1024;
                using (Stream file1 = File.OpenWrite(ClientFileName))
                {
                    client.DownloadFile(ServerFileName, file1);
                }
            }
        }
        catch (Exception e)
        {
            Result = "Fail: " + e.ToString();
        }
        return (Result);
    
        }
    
  6. imapangolin commented on Jan 19, 2017

    @imapangolin

    Could this simply be that the download is single threaded?

  7. drieseng commented on Jan 19, 2017

    @drieseng
    Member

    I modified DownloadFile to read-ahead 10 chunks asynchronously.
    This greatly improves performance, even up to a point where we're fasten than WS_FTP.
    I went from around 30 MB to 56 MB/s with my local SSH server.
    Do note that these changes are not yet available (not in beta1, and not even in the develop branch).

    In case of the original issue reported by @Dailison, I got around 250 KB/s against the server he used before my changes (while he claimed 70 KB/s).
    After my changes - and based on preliminary tests - I got around 850 KB/s.
    The "read-ahead" has more effect on slower servers and/or connections.

    But even with these changes, I doubt throughput will increase in such a way that downloading a 28 MB file will go from 2+ minutes to 8 seconds.
    I think there may be another issue here.
    If you can debug or instrument the code, it would be great to learn if much time is spent in KeyExchangeDiffieHellman.PopulateClientExchangeValue().

  8. imapangolin commented on Jan 19, 2017

    @imapangolin
  9. Dailison commented on Jan 19, 2017

    @Dailison
    Author

    I'm looking forward to a new version with this bug fixed.
    And again @drieseng , tank's for support us.

  10. drieseng commented on Jan 22, 2017

    @drieseng
    Member

    I committed a preliminary version of these changes in the develop branch.
    Please hammer away at them, and let me know if it reduces download speed for you.

  11. imapangolin commented on Jan 23, 2017

    @imapangolin

    I tried the newly committed code. I wish I had good news - but for me with the following code to call it, it never return from the download. I am calling it from a .net com server so I have to create a console application to debug further but as it stands right now it just doesn't work at all!

    It there something I need to do to activate it - tried various buffer sizes as well.

        string Result = "Success";
        try
        {         
            using (var client = new SftpClient(ServerName, Convert.ToInt32(Port), UserID, Password))
            {
                client.Connect();
    
                client.BufferSize = 4 * 1024;
                using (Stream file1 = File.OpenWrite(ClientFileName))
                {
                    client.DownloadFile(ServerFileName, file1);
                }
            }
        }
        catch (Exception e)
        {
            Result = "Fail: " + e.ToString();
        }
        return (Result);
    
  12. imapangolin commented on Jan 25, 2017

    @imapangolin

    The committed developer build now functions! I will give you some performance comparisons tomorrow.
    I really really appreciate what you are doing here. Thank you.

  13. imapangolin commented on Jan 25, 2017

    @imapangolin

    I know you say it's a WIP but I'd call it a rousing success. WinSCP which was the fastest transfer I could find has been doing 29-31 seconds on my sample file. Consistently getting 15-16 using the changes you put into SSH.NET. I say go for it and put it in the next beta! THANK YOU!

  14. drieseng commented on Jan 25, 2017

    @drieseng
    Member

    @Dailison Can you also build SSH.NET from the develop branch, and validate my changes?

  15. Dailison commented on Feb 16, 2017

    @Dailison
    Author

    I have changed the password authentication method for private key.

    Gert i have tested the developer branch and the download speed was increased to 600 ~~ 700 kbps ....

    But it's not my max download speed, currently is 1500 kbps

  16. drieseng commented on Feb 17, 2017

    @drieseng
    Member

    For now, I don't see much room for improvement.
    It would be great if someone would scan the code for any possible performance improvements.
    Since you've reported a throughput increase of about 1000%, I think we can safely consider this specific issue closed.
    Agree?

  17. imapangolin commented on Feb 17, 2017

    @imapangolin
  18. added this to the milestone on Jul 21, 2017
  19. self-assigned this
    on Jul 21, 2017
  20. drieseng commented on Jul 21, 2017

    @drieseng
    Member

    We cannot sacrifice stability for speed.
    Since you confirmed that - with these changes - throughput went from roughly 70 KB/s to 700 KB/s, we can surely consider this issue fixed.

  21. drieseng commented on Jul 21, 2017

    @drieseng
    Member

    Here's some more info on the read-ahead implementation

    Maximum shunk size

    The maximum size of a chunk that we read ahead is the configured buffer size (default is 32 KB) limited to the maximum packet size (which currently is 64 KB) minus 13 bytes (which is the protocol overhead of a SSH_FXP_DATA message):

    maximum chunk size = MAX(buffer size, maximum packet size) - 13

    This a technique we generally apply because most SSH servers limit the size of the payload of a SSH_MSG_CHANNEL_DATA message to 16 KB.

    If we requested 16 KB of data, then the SSH_FXP_DATA payload of the SSH_MSG_CHANNEL_DATA message would be too big (16 KB + 13 bytes) to fit a single SSH_MSG_CHANNEL_DATA response.

    As a result, the SSH server would split the SSH_FXP_DATA over two SSH_MSG_CHANNEL_DATA responses: one containing 16384 bytes (13 bytes header, and 16371 bytes file data), and one with the remaining 13 bytes of file data.

    Maximum pending reads

    The definition for a pending read is a read-ahead that either the server has not yet responsed to, or for which the response has not been consumed.

    The maximum number of pending reads is the total size of the file to download divided by the maximum chunk size, plus 1 limited to 10:

    maximum pending reads = MIN(10, ROUNDUP(file size / maximum chunk size) + 1)

    If the file size cannot be determined, the maximum pending reads is set to 3.

    Once this limit is reached, no further chunks a read-ahead until a pending read is completed.

  22. laurentchougrani commented on Dec 12, 2020

    @laurentchougrani

    as of 2020 I can state that the Sftp process is very slow....
    if i use SSH directly from powershell for transfering, say a 700Mb file, it takes less than a minute, now using this transfer method it takes about 5 cigarettes and three coffees (which makes about 30min).... I do like [Coffee + cigarettes] but still... ^^

  23. jjxtra commented on Apr 8, 2021

    @jjxtra

    Upload speed is definitely broken. I can't get more than 500K / second out of it regardless of how many clients I create per file. Even one file has the same speed limit. Must be a global bottleneck or lock somewhere... Using mobaxterm I get 50mb / sec upload.

  24. zybexXL commented on Aug 30, 2021

    @zybexXL
    Contributor

    I've added two PRs today that improve SFTP performance (by a LOT, in my case), and simultaneously reduce CPU usage: #865 and #866. I'm not sure if the SCP file transfers also benefit, I didn't test/check that.

    According to my benchmarks, both FileUpload and FileDownload have massive speed gains and are now comparable to Filezilla.

    I'd be very interested to know if these changes also help you guys :)

  25. imapangolin commented on Aug 30, 2021

    @imapangolin
  26. zybexXL commented on Aug 30, 2021

    @zybexXL
    Contributor

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions