I have a very simple collection with no indexes except _id.
Each document contains a single array field, mies
.
Current collection size is around 100 millions, and I can see the following anomalies in the profiler:
{
"op": "update",
"ns": "DB.links",
"command": {
"q": {
"_id": "f1b54f37-7f92-4e75-9ec6-5329349ce792_eb370c8a-6f33-4989-aa59-a26e1c9df46c"
},
"u": {
"$push": {
"mies": {
"$each": [
{
"$oid": "5e39d07bec34b8000e7f86b7"
}
]
}
}
},
"multi": true,
"upsert": true
},
"keysExamined": 0,
"docsExamined": 0,
"nMatched": 0,
"nModified": 0,
"upsert": true,
"keysInserted": 1,
"numYield": 0,
"locks": {
"Global": {
"acquireCount": {
"r": 2,
"w": 2
}
},
"Database": {
"acquireCount": {
"w": 2
},
"acquireWaitCount": {
"w": 1
},
"timeAcquiringMicros": {
"w": 19486143
}
},
"Collection": {
"acquireCount": {
"w": 1
}
},
"oplog": {
"acquireCount": {
"w": 1
}
}
},
"millis": 19490,
"planSummary": "IDHACK",
"execStats": {
"stage": "UPDATE",
"nReturned": 0,
"executionTimeMillisEstimate": 0,
"works": 2,
"advanced": 0,
"needTime": 1,
"needYield": 0,
"saveState": 0,
"restoreState": 0,
"isEOF": 1,
"invalidates": 0,
"nMatched": 0,
"nWouldModify": 0,
"nInvalidateSkips": 0,
"wouldInsert": true,
"fastmodinsert": false,
"inputStage": {
"stage": "IDHACK",
"nReturned": 0,
"executionTimeMillisEstimate": 0,
"works": 1,
"advanced": 0,
"needTime": 0,
"needYield": 0,
"saveState": 0,
"restoreState": 0,
"isEOF": 1,
"invalidates": 0,
"keysExamined": 0,
"docsExamined": 0
}
}
}
As you can see, a simple upsert with a single $push to array took 19 seconds. I believe most of the time was spent here:
"timeAcquiringMicros": {
"w": 19486143
}
What should I check? How can I improve the performance?