copy_stream从远程URL下载文件
我们想将文件从远程URL下载到内存中,然后将其上传到某些公共云中。我打算在Ruby中使用copy_stream lib。但是,我不确定是否可以通过此实现这一目标,因为我还需要保持内存和CPU统计信息,以免妨碍性能。
任何建议或示例如何通过Ruby中的copy_stream lib实现这一目标,或者我们有其他lib来实现这一目标。
We wanted to download files from remote-url into memory and then upload it to some public cloud. I am planning to use copy_stream lib in ruby. However I am not sure if it can be achieved by this, because I need to also maintain the memory and CPU stats in such a way that it will not hamper the performance.
Any suggestion or example how to achieve this via copy_stream lib in ruby or do we have any other lib to achieve this considering the performance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将SRC/DST设置为简单的IO抽象,以响应读/写:
You can setup src/dst to be simple IO abstractions that respond to read/write:
sendfile()
。SendFile是基于内核的复制流过程。在RAM的使用和性能方面,没有什么更快的。您的申请将不参与转移。
对于
sendfile()
,输出套接字必须具有零副本的支持,并且输入文件必须具有mmap()
支持。通常,这意味着您已经将文件下载到本地文件,在复制期间不会更改下载的文件,并且输出可以打开套接字。sendfile()
.Sendfile is a kernel based copy stream procedure. In terms of ram use and performance, there is nothing faster. You application will not be involved with the transfer.
For
sendfile()
, the output socket must have zero-copy support and the input file must havemmap()
support. In general, this means you have already downloaded the file to a local file, you do not change the downloaded file during the copy, and you have an open socket to the output.