python - 如何并行化 Databricks 文件复制/上传操作?
问题描述
我在 Microsoft Azure 上运行 Databricks。我正在使用名为 google-cloud-storage 和 google-cloud-core 的 python 库将所有文件从 Databricks dbfs 路径复制到 GCP/GCS 存储桶(Google Cloud Platform / Google Cloud Storage 存储桶)。我用 PyPl 安装了这些库,并使用了 google-cloud-storage python 库中的“upload_from_filename”命令。源目录包含数百个文件,文件总量超过 100 GB。文件复制/上传成功,但复制/上传操作是一个接一个,一次一个文件。
我的问题是:如何强制 Databricks “并行化”复制/上传操作(即在多个线程中异步执行复制操作)?
以下是我的代码(为清楚起见,修改了 gcp 存储桶名称和源文件路径)
from google.cloud import storage
from datetime import datetime
storage_client = storage.Client()
bucket = storage_client.bucket('the-gcp-bucket')
files = dbutils.fs.ls('dbfs:/sourcefilepath/')
filenumber = 0
for fi in files:
source_file_name = fi.path
source_file_name = source_file_name.replace("dbfs:", "/dbfs")
blob = bucket.blob('TargetSubFolder/' + fi.name)
blob.upload_from_filename(source_file_name)
filenumber = filenumber + 1
print("File num: {} {} uploaded to {}.".format(str(filenumber), source_file_name, destination_blob_name))
print("File Copy Complete")
解决方案
推荐阅读
- reactjs - React .- JSX 中的 reduce() 不渲染
- c# - 如何防止C#强制excel文件以只读方式打开?
- sql - 循环依赖 - 表插入错误
- grails - Grails GORM:在 beforeUpdate 上更新关联对象的属性未持久化
- java - Weblogic Server 启动期间 JVM 崩溃和巨大的错误日志
- angular - Angular 6 - @types/googlemaps/index.d.ts' 不是一个模块
- php - 如何从我的服务器 [PHP] 读取 .txt 文件?
- python - 从另一个python文件导入类错误
- wordpress - 制作联系表格 7 添加自定义必填复选框
- swift - Swift拆分视图控制器,首次加载时出现“重复”通知