-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SCP data transfer speed comparison with OpenSSH #688
Comments
I also have this problem |
I have tried transferring a 5.4GB file via SFTP from server A to server B, via the OpenSSH SFTP client in a shell script, a small Java application using the JSCH library, and this SSHJ library and the results are the following, in all cases with compression on:
Why is it so slow? Any way to improve performance for large files? |
Are you not using buffered streams maybe? A performance test is only as good as its implementation |
Otherwise you would need to use a profiler to find the hotspot for this |
Here is my sshj-relevant lines implementation, no BufferedStreams:
|
And without compression? |
@hierynomus what buffered stream do you mean? If you check my code example above you will see that I'm using the methods from the sshj library. Am I doing something wrong? @fire2 I have a similar code for testing sftp. I don't use compression because it makes the speed even slower. I suggest you disable compression and then you should see some improvement but still not as fast as the OpenSSH implementation. |
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 |
I just tried and it took 7 minutes 22 second. Even though I can't understand why without compression it is faster than with compression (opposite to OpenSSH client), it is still way too slow. |
I can have a look, I think the compression speed itself is suboptimal, thus a limiting factor. |
@hierynomus how to use the buffered stream? The upload method from the sshj lib requires FileSystemFile as a parameter. I think something needs to be changed internally in the library. @fire2 If I try to use compression I see a decrease in speed in both implementations - sshj and OpenSSH. |
For me the OpenSSH implementation takes 3m 04s without compression (-C flag), and 1m 38s with compression. It is always quite faster. It's using the zlib compression. |
@fire2 That means that most probably your bandwidth is the limiting factor in your test, not the CPU speed. |
Hmm, I don't understand. Why is the library then using less bandwidth? I am running all tests on the same machine. |
Regardless of the compression, I think some kind of improvement has to be done inside the sshj library. As @hierynomus mentioned, the use of buffered streams might be the answer here but if that's true then it probably needs to be implemented in the library. |
In my case the native SCP/rsync is 6.5ms/file and SFTP over SSHJ 8.4ms/file after the mentioned buffered input stream optimization (without optimization it was 18.7 ms/file). Also compression made it worse. I agree that it would be worthy to implement buffered streams directly to the lib. |
@yantom how did you implement the buffered input stream? Can you paste here a code snippet for uploading the file? |
File file = Paths.get("sample.pdf").toFile();
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file))) {
transfer.upload(new InputStreamSource(bis, file.getName()), "/samplelocation/sample.pdf");
} uses this class: private static class InputStreamSource extends InMemorySourceFile {
private String name;
private InputStream inputStream;
public InputStreamSource(InputStream is, String name) {
this.inputStream = is;
this.name = name;
}
public String getName() {
return name;
}
public long getLength() {
return -1;
}
public InputStream getInputStream() throws IOException {
return inputStream;
}
} |
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. |
@simhro just a random guess: does it help if you upload a file via |
参考大佬的评论 这样实现可以几乎跑满我服务器的带宽,适当调节缓冲区大小和请求数
|
使用ReadAheadRemoteFileInputStream提升空间很大 BufferedInputStream也是 ,sshClient.useCompression();对部分文件有提升 |
I 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:
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?
The text was updated successfully, but these errors were encountered: