python-2.7 - 如何使用 azure cosmos db 最大化数据库上传速率

标签 python-2.7 azure azure-cosmosdb pymongo-3.x azure-cosmosdb-mongoapi

这是我的问题。我正在尝试将一个大型 csv 文件上传到 cosmos db (~14gb),但我发现很难最大化我所支付的吞吐量。在 Azure 门户指标概述 UI 上,它显示当我支付 16600 RU/s 时,我正在使用 73 RU/s。现在,我正在使用 pymongo 的批量写入功能上传到数据库,但我发现任何大于 5 的bulk_write 长度都会抛出硬 Request rates is big. 异常。我这样做错了吗?在这种情况下,有没有更高效的方式来上传数据呢?互联网带宽可能不是问题,因为我正在从 azure vm 上传到 cosmos db。

我现在如何在 python 中上传的结构:

for row in csv.reader:
    row[id_index_1] = convert_id_to_useful_id(row[id_index_1])

    find_criteria = {
        # find query
    }

    upsert_dict = {
        # row data
    }
    operations.append(pymongo.UpdateOne(find_criteria, upsert_dict, upsert=True))

    if len(operations) > 5:

        results = collection.bulk_write(operations)

        operations = []

如有任何建议,我们将不胜感激。

最佳答案

亚伦.是的,正如您在评论中所说,Azure Cosmos DB MongoDB API 支持迁移工具。您可以在 official doc 中找到打击声明。 .

The Data Migration tool does not currently support Azure Cosmos DB MongoDB API either as a source or as a target. If you want to migrate the data in or out of MongoDB API collections in Azure Cosmos DB, refer to Azure Cosmos DB: How to migrate data for the MongoDB API for instructions. You can still use the Data Migration tool to export data from MongoDB to Azure Cosmos DB SQL API collections for use with the SQL API.

我只是为您提供了一个可以使用的解决方法 Azure Data Factory 。请引用这个doc使 cosmos db 作为接收器。并引用此 doc将Azure Blob存储中的csv文件作为源。在管道中,您可以配置批量大小。

enter image description here

当然,您可以通过编程来完成此操作。您没有错过任何内容,错误请求率较大仅意味着您超出了预配置的 RU 配额。您可以提高 RU 设置的值。请引用这个doc .

如有任何疑问,请随时告诉我。

关于python-2.7 - 如何使用 azure cosmos db 最大化数据库上传速率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52016070/

相关文章:

python - 直接从终端运行已安装的 python 模块

python - fmin_cg : Desired error not necessarily achieved due to precision loss

azure - 使用脚本重新创建 cosmos DB

python - CosmosDB 和 Python3 : how to query?

python - Windows 上这 4 种不同类型的 Python shebangs 有什么区别?

python - 导入模块时到底会发生什么?

Azure Web作业在两个时区运行两次

azure - HDInsight 查询控制台作业历史记录

azure - 无法找到编辑 Microsoft Azure Web Bot 样式的方法

Azure - 使用 Terraform 恢复 CosmosDB 帐户