从命令行scp实用程序所能实现的情况来看,在图书馆中,SCP上传速度似乎受到了极大的限制。我知道这是Ruby(1.9.2-p0),但是Net::SCP比Linux实用程序慢大约8倍(使用大文件可见...详见下文)。我很想知道(我快速查看了代码),这是Ruby中套接字的表现方式,还是可能更好地复用Net::SCP套接字?
我注意到无论我尝试了哪种上传方式(串行上传、通道异步操作、使用多个scp对象实例),我都无法在SCP上传中获得超过9兆字节/秒的传输速度。现在...让我解释一下我的调查细节:
1)尝试不同的加密算法
我使用了不同类型的加密,但速度没有显着变化。例如:我可以使用命令行scp(加密算法=arcfour128)提交我的1GB测试文件,并在我的内部千兆连接上获得73.3兆字节/秒的传输速率。使用Net::SCP.upload库,我从未在我的内部千兆连接上获得超过约9兆字节/秒的速度。
2)尝试不同的主机/操作系统
我发现Linux->Linux上传速度最快。SUA的ssh服务器(Windows)只能为我提供最多13.5兆字节/秒的上传速度(使用arcfour算法w/scp命令行),而Linux->Linux(使用arcfour,w/scp命令行)则是惊人的73.3兆字节/秒。我应该提到,这些Windows和Linux机器是完全相同的型号、硬件等。
3)尝试不同的SCP上传方法
->使用2个同步上传调用,一个在另一个完成后进行。->使用2个异步上传调用,一个在另一个启动后进行。->使用2个Net::SCP对象,并将文件提交给非阻塞/异步版本的上传(因此它们在并行运行)。这些不同的方法都没有任何显着的性能增益,这有点令人沮丧。
以下是测试结果(文本已优化可读性,但与提供的代码输出类似):
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
如果你有一个大文件(我使用了一个大约1GB的文件),你可以使用这些rspec测试(在scp_spec.rb中),或者改变它们为你熟悉的任何测试工具,以查看这种性能下降。如果你不知道如何改进库中的性能,除了通过子shell调用scp实用程序之外,你还有什么其他想法来提高SCP传输的额外并行速度?Rspec测试请参见:https://gist.github.com/703966。