从S3使用Ruby SDK进行并行下载

huangapple go评论64阅读模式
英文:

Parallel downloads from S3 with Ruby SDK

问题

我在S3上有一些非常大的文件。我想使用Ruby SDK下载它们。

是否有一种并行下载它们的方式?

我可以使用'parallel' gem,但想知道是否有另一种方式,例如SDK中内置的本地功能。

顺序下载需要很长时间。

提前感谢。

英文:

I have some very large files on s3. I want to download them using the ruby sdk.

Is there a way of downloading them in parallel?

I could use the ’parallel’ gem but wondering if there was another way eg native functionality built into the sdk

Sequential downloads takes a long time.

Thanks in advance

答案1

得分: 1

你可以使用 Threads,它们是 Ruby 核心的一部分,像这样使用:

downloads = []

downloads << Thread.new { # 下载文件 1 }
downloads << Thread.new { # 下载文件 2 }
#...
downloads << Thread.new { # 下载文件 n }

# 确保所有线程完成工作后再继续
downloads.each(&:join)
英文:

You could use Threads which are part of the Ruby core like this:

downloads = []

downloads &lt;&lt; Thread.new { # download file 1 }
downloads &lt;&lt; Thread.new { # download file 2 }
#...
downloads &lt;&lt; Thread.new { # download file n }

# Ensure that all threads finished their work before moving on
downloads.each(&amp;:join)

huangapple
  • 本文由 发表于 2023年6月29日 01:04:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575323.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定