Performance issues with Ruby and Net::SCP transfers (sockets)

SCP upload speeds seem to be limited greatly in the library from what the command line scp utility is capable of. I understand this is Ruby (1.9.2-p0), but Net::SCP is approximately 8x slower than the Linux utility (seen using large files... see below). I'm curious to know (I took a quick look at the code) if this is how sockets are in Ruby, or if it's possible to multiplex the Net::SCP sockets better?

I noticed that no matter what style of upload I tried (serial upload, channels operating asynchronously, using multiple instances of the scp object) I never could get over 9 megabytes / second transfer speed on an SCP upload. Now... let me explain the details of my investigation:

1) Tried Different Encryption Algorithms

I used different types of encryption without much significant speed change Example: I could submit my 1GB test file using command line scp (encryption algorithm = arcfour128) and get a transfer rate of 73.3 megabytes/s on my internal gigabit connection. I never got more than about 9 megabytes/s on my internal gigabit connection using the Net::SCP.upload lib.

2) Tried Different Hosts/OSes

I found that Linux -> Linux uploads were the fastest. SUA's ssh server (Windows) could only provide me with a maximum of 13.5megabytes/s upload speeds (Linux -> Windows, using arcfour algorithm w/ scp command line), whereas Linux -> Linux (using arcfour, w/ scp command line) was a blazing 73.3megabytes/s. I should mention that these Windows and Linux machines are the exact same model, hardware, etc.

3) Tried Different SCP upload methods

-> used 2 synchronous upload! calls, one after the other was finished. -> used 2 asynchronous upload calls, one after the other had started -> used 2 Net::SCP objects and submitted the file to the non-blocking/asynchronous version of upload (so they were running in parallel) None of these different methods give any significant performance gain, which is sort of frustrating.

Here are the results of the test (text enhanced for readability, but similar to the output of the code provided):


Net::SCP
Done creating channels
Starting transfer of /home/seth/afpcases/systeme.afp # two upload! calls, one after another
Finished transfer of /home/seth/afpcases/systeme.afp
--> Duration: 126.07707 seconds (8.7168903909331 megabytes/s) should show transfer speed of serial uploads

Starting transfer of /home/seth/afpcases/systeme.afp # two upload calls, one after another, with a wait on both channels after both have started
Finished transfer of /home/seth/afpcases/systeme.afp
--> Duration: 122.588784 seconds (8.964931082112699 megabytes/s) should show transfer speed of simultaneous async channels.

Starting transfer of /home/seth/afpcases/systeme.afp # two upload calls on two separate Net::SCP objects, one after another, with a wait on both channels after both have started
Finished transfer of /home/seth/afpcases/systeme.afp
--> Duration: 122.822663 seconds (8.947860054133495 megabytes/s) should show transfer speed of simultaneous SCP instances

Finished in 371.761262 seconds

If you have a large file (I used a ~1GB file), you can use these rspec tests (in scp_spec.rb) or change them to whatever test harnesses you are familiar with to see this performance degradation.

If you don't know how this performance could be improved in the library, do you have any more ideas on how open up some extra parallel speed of SCP transfers besides just calling the scp utility via a subshell?

Rspec test here: https://gist.github.com/703966


You might try Net-sftp instead. Sftp is a newer protocol and the linux scp utility actually uses sftp protocol if it's available. I do not know if net-scp actually uses the sftp protocol, but I would not be surprised if it doesn't.

You might also try rsync, but that would require installing rsync on the remote host as well. Rsync is by far the king of speed with remote file transfers, although I can not vouche for the six-rsync gem.

链接地址: http://www.djcxy.com/p/92200.html

上一篇: scp命令将文件从远程复制到本地主机返回错误

下一篇: Ruby和Net :: SCP传输(套接字)的性能问题