Hello there, I will highly appreciate the community advice.
I’m running MongoDB atlas version 3.6.21 and using an open-source package called agenda that using mongo as its backend. once I upgrade the package (v2.0.2 to v4.0.1), the CPU spiked to 100%. according to the atlas profiler, I identified a possible ‘bad’ query causing the issue, but I can’t figure out what’s wrong.
The ‘bad’ query is findAndModify and runs the following:
db.getCollection('agendaJobs').findAndModify({"query": {
$or: [
{
name: 'webhook',
disabled: { $ne: true },
lockedAt: { $eq: null },
nextRunAt: { $lte: new Date() },
},
{
name: 'webhook',
disabled: { $ne: true },
lockedAt: { $lte: new Date() },
},
],
},
"sort": { "nextRunAt" : 1, "priority" : -1 },
"update": { $set : { "lockedAt" : new Date() }}
})
from the profiler, those are the most suspicious fields I see:
"millis": 471830
"protocol": "op_msg",
"locks": {
"Global": {
"acquireCount": {
"r": 146620,
"w": 146618
}
},
"keysExamined": 405712,
"docsExamined": 2,
"nMatched": 1,
"nModified": 1,
"keysInserted": 1,
"keysDeleted": 1,
"writeConflicts": 14,
"numYields": 146600,
"planSummary": [
{
"IXSCAN": {
"name": 1,
"nextRunAt": 1,
"priority": -1,
"lockedAt": 1,
"disabled": 1
}
},
{
"IXSCAN": {
"name": 1,
"nextRunAt": 1,
"priority": -1,
"lockedAt": 1,
"disabled": 1
}
}
],
Is there anything I’m missing? maybe I should create an additional index? how would you suggest continuing the investigation?
I will highly appreciate your support and opinion!
Tal