SCP data transfer speed comparison with OpenSSH
See original GitHub issueI was testing the performance of the SCP method from the sshj library for uploading a file from my machine to a remote one and I find it significantly slower compared to the OpenSSH’s scp command which I executed from my centos machine.
The tests which I performed were all done in the same environment (local network with 2 centos machines) and I was transferring 1 GB file to a remote machine.
-
The scp command gives me about 180 MB/s upload speed:
scp testfile-1gb username@1.2.3.4:/tmp
-
When I tried to use the sshj’s scp to upload the same file it only gives me about 40 MB/s. Here is a simple java code I’m using:
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
import java.io.IOException;
public class TestSshj {
public static void main(String[] args) throws IOException {
SSHClient ssh = new SSHClient();
try {
ssh.addHostKeyVerifier(new PromiscuousVerifier());
ssh.connect("1.2.3.4");
ssh.authPassword("username", "password");
ssh.newSCPFileTransfer().upload("test-1gb", "/tmp");
}
finally {
ssh.close();
}
}
}
I also tried using SFTP method for uploading the data to see if there is any difference but it gives pretty much the same slow-ish speed. Another thing I tried changing was the encryption algorithms (I tried using the same as OpenSSH was using) but that didn’t help either.
Is this kind of performance difference expected or can it be improved somehow?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:22 (7 by maintainers)
I’ve tried with the buffered stream as you’ve shown but I’m not getting any speed improvement. I was testing it by uploading a 5GB file.
If you use FileSystemFile, that uses direct FileInputStream and FileOutputStream. It might be worthwhile to wrap those in a Buffered(Input|Output)Stream before passing them