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

How to maximize DB upload rate with azure cosmos db

这是我的问题。我正在尝试将一个大的 csv 文件上传到 cosmos db (~14gb),但我发现很难最大化我所支付的吞吐量。在 Azure 门户指标概述 UI 上,它说我在支付 16600 RU/s 时使用 73 RU/s。现在,我正在使用 pymongo 的批量写入功能上传到数据库,但我发现任何 bulk_write 长度大于 5 都会抛出硬 Request rate is large. 异常。我做错了吗?这种场景下有没有更高效的上传数据的方式? Internet 带宽可能不是问题,因为我正在从 azure 虚拟机上传到 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 = []

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

我会看一下 Cosmos DB: Data Migration Tool。我没有将它与 MongoDB API 一起使用,但它是受支持的。我已经使用它成功地将大量文档从我的本地计算机移动到 Azure,并且它将利用可用的 RU/s。

如果您需要以编程方式执行此操作,我建议您查看数据库迁移工具的底层源代码。这是开源的。您可以找到代码 here

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

中找到 blow 语句

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. Please refer to this doc to make the cosmos db as sink.And refer to this doc 将 Azure Blob 存储中的 csv 文件作为 source.In 管道,您可以配置批处理大小。

当然,您可以通过编程方式执行此操作。您没有遗漏任何内容,错误 Request rate is large 仅表示您超出了预配的 RU 配额。您可以提高 RUs 设置的值。请参考这个doc.

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

我能够提高上传速度。我注意到每个物理分区都有一个吞吐量限制(出于某种原因,物理分区的数量乘以每个分区的吞吐量仍然不是集合的总吞吐量)所以我所做的是按每个分区拆分数据然后创建每个分区键的单独上传过程。这将我的上传速度提高了(# of physical partitions)倍。

我使用了 ComsodDB 迁移工具,无需进行太多配置即可将数据发送到 CosmosDB 非常棒。即使我们也可以按照我的假设发送 14Gb 的 CSV 文件。

下面是我们传输的数据

[已传输 10000 条记录 |吞吐量 4000 | 500 并行请求 | 25 秒]。 [已传输 10000 条记录 |吞吐量 4000 | 100 个并行请求 | 90 秒]。 [已传输 10000 条记录 |吞吐量 350 |并行请求 10 | 300 秒].