python - 使用 boto3 在 S3 存储桶中移动对象的最快方法
问题描述
我需要将所有文件从 S3 中的一个前缀复制到同一存储桶中的另一个前缀。我的解决方案是这样的:
file_list = [List of files in first prefix]
for file in file_list:
copy_source = {'Bucket': my_bucket, 'Key': file}
s3_client.copy(copy_source, my_bucket, new_prefix)
但是我只移动了 200 个小文件(每个 1 kb),这个过程最多需要 30 秒。一定有可能做得更快吗?
解决方案
我会并行进行。例如:
from multiprocessing import Pool
file_list = [List of files in first prefix]
print(objects_to_download)
def s3_coppier(s3_file):
copy_source = {'Bucket': my_bucket, 'Key': s3_file}
s3_client.copy(copy_source, my_bucket, new_prefix)
# copy 5 objects at the same time
with Pool(5) as p:
p.map(s3_coppier, file_list)
推荐阅读
- c++ - C ++中的双重调度不起作用
- sql-server - 从函数返回 Nvarchar 当返回值为 0 时,则为其他数值
- javascript - HTML5 音频在结束前停止
- r - 如何在 R 中自动导入数据、添加时间戳和标准化数据文件中的行数
- python - Python - 导入自己的模块的正确方法
- c# - 数据驱动测试 - 带有 Nunit 的示例表
- sql - ERROR: column "summed_hits" does not exist When using AS in select
- selenium-chromedriver - Robot Framework: Iast argument shows invalid syntax in test step
- html - zoho 邮件提供商的 emailto 正文内容换行符
- c# - WIA 的 DeviceManager 有 0 个 DriveInfos