Hi Experts,
I am using bulkwriter to upsert batch documents into a collection with 2 unique sparse indexes.
During the testing, the CPU usage was almost 100% and there was timeout error when the bulkwrite size is 100 only.
However, I did the similar testing on a collection with single unique index. There is no such perfromance issue at all. THe CPU usage was only below 10%.
I am quite confused with the issue.
Appreciate any feedback.
More information are provided as below.
platform information:
MongoDB Atlas M20: 6.0.11
Node.js:
version 20
mongodb: 6.1.0
Indexes on the collections:
[
{
key: { myId1: 1 },
name: "myId1_1",
unique: true,
sparse: true
},
{
key: { myId2: 1 },
name: "myId1_2",
unique: true,
sparse: true
}
]
Here is the list for bulkwrite: The number of bulksize is 100, and there is same index id for a whole batch.
[{
"updateOne":{
"filter":{"myId1":"myId1_0"},
"update":{"$setOnInsert":{"myId1":"myId1_0"},"$set":{"att1": "100", "updated":1697585425844}},
"upsert":true},
"updateOne":{
"filter":{"myId1":"myId1_1"},
"update":{"$setOnInsert":{"myId1":"myId1_1"},"$set":{"att1": "200", "updated":1697585425844}},
"upsert":true},
}]
node.js for bulkwirte
await dbClient.db(dbName).collection(colName).bulkWrite(bulkWriteList, { ordered: false });