英文:
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 << Thread.new { # download file 1 }
downloads << Thread.new { # download file 2 }
#...
downloads << Thread.new { # download file n }
# Ensure that all threads finished their work before moving on
downloads.each(&:join)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论