copy_stream从远程URL下载文件

发布于 2025-02-13 19:20:12 字数 338 浏览 0 评论 0原文

我们想将文件从远程URL下载到内存中,然后将其上传到某些公共云中。我打算在Ruby中使用copy_stream lib。但是,我不确定是否可以通过此实现这一目标,因为我还需要保持内存和CPU统计信息,以免妨碍性能。

任何建议或示例如何通过Ruby中的copy_stream lib实现这一目标,或者我们有其他lib来实现这一目标。

https://ruby-doc.org/core-core-2.5.5/io。 html

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.

https://ruby-doc.org/core-2.5.5/IO.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事↓在人 2025-02-20 19:20:12

您可以将SRC/DST设置为简单的IO抽象,以响应读/写:

src = IO.popen(["ssh", srchost, "cat /path/to/source_file | gzip"], "r")
dst = IO.popen(["ssh", dsthost, "gunzip > /path/to/dest_file"], "w")

IO.copy_stream(src, dst)

src.close
dst.close

You can setup src/dst to be simple IO abstractions that respond to read/write:

src = IO.popen(["ssh", srchost, "cat /path/to/source_file | gzip"], "r")
dst = IO.popen(["ssh", dsthost, "gunzip > /path/to/dest_file"], "w")

IO.copy_stream(src, dst)

src.close
dst.close
一枫情书 2025-02-20 19:20:12
  • 将SRC设置为可下载文件。
  • 通过写入权限,将DST设置为云资源。
  • 确保两者符合sendfile()

SendFile是基于内核的复制流过程。在RAM的使用和性能方面,没有什么更快的。您的申请将不参与转移。

对于sendfile(),输出套接字必须具有零副本的支持,并且输入文件必须具有mmap()支持。通常,这意味着您已经将文件下载到本地文件,在复制期间不会更改下载的文件,并且输出可以打开套接字。

  • Set up src to be the downloadable file.
  • Set up dst to be the cloud resource, with write permission.
  • Make sure the two are compliant with 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 have mmap() 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文