0

我有一个名为 User.java 的对象,我想在 Azure CosmosDB 中一次推送 50 个对象。

以下是我的一项服务中的代码

List<User> lists = new ArrayList<>();
LongStream.range(1L, 50L).forEach(index -> {
     User user = new Gson().fromJson("<Long Json String>", User.class);
     user.setUserId(index);
     lists.add(user);
});
userDao.saveAll(lists);

userDao 具有以下功能

public void saveAlls(List<User> users) {
    BulkOperations bulkOps = mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED, User.class, "User");
    users.forEach(bulkOps::insert);
    BulkWriteResult result = bulkOps.execute();
    log.info("Inserted Records : {}", result.getInsertedCount());
}

尝试执行上述代码,但从 Azure Cosmos Side 收到错误

2022-02-22T08:19:42.271866499Z,SDK:Microsoft.Azure.Documents.Common/2.14.0'。完整的响应是 {"_t": "OKMongoResponse", "ok": 0, "code": 16500, "errmsg": "Message: {"Errors":["请求率很大。可能需要更多请求单元,因此未进行任何更改。请稍后重试此请求。了解详情:http://aka.ms/cosmosdb-error-429"]}\r,RequestStats:\r\nRequestStartTime:2022-02-22T08:19:42.1311079Z,RequestEndTime:2022-02-22T08:19: 42.1311079Z,尝试的区域数:1\r\n{"systemHistory":[{"dateUtc":"2022-02-22T08:18:48.9014579Z","cpu":1.915,"memory":410733700.000," threadInfo":{"isThreadStarving":"False","threadWaitIntervalInMs":0.0187,"availableThreads" 1311079Z; 响应时间:2022-02-22T08:19:42.1311079Z;LSN:77910,GlobalCommittedLsn:77910,PartitionKeyRangeId:,IsValid:True,StatusCode:429,SubStatusCode:3200,RequestCharge:0.38,ItemLSN:-1,SessionToken:,UsingLocalLSN:False,TransportException:null,BELatencyMs:,ActivityId:4c3926ed- 0000-0000-0000-000000000000,RetryAfterInMs:68,TransportRequestTimeline:{“requestTimeline”:[{“event”:“Created”,“startTimeUtc”:“2022-02-22T08:19:42.1311079Z”,“durationInMs”: 0.0359},{“事件”:“ChannelAcquisitionStarted”,“startTimeUtc”:“2022-02-22T08:19:42.1311438Z”,“durationInMs”:0.0031},{“事件”:“流水线”,“startTimeUtc”:“ 2022-02-22T08:19:42.1311469Z", "durationInMs": 0.3715},

注意:还尝试将 RU [请求单位] 从 400 增加到 4000 并将收集置于 AutoScale 模式,但我们仍然面临同样的错误。

4

0 回答 0