Queries by ID taking a long time

Hello! I am in need of the wisdom of the community on this one.

My app in production is showing some odd things on kadira (MontiAPM). I see these random spikes for queries by _id, which I would expect to take a few ms, but takes several seconds. Most of my other queries are really fast, but sometimes I get these odd spikes apparently, according to kadira. Are anyone else experiencing the same thing? Any idea of what might cause it?

There are several things that can cause these types of spikes -

If the documents aren’t frequently accessed (e.g., not in the working set) mongo would load the documents from disk - depending on how your mongodb is hosted, this might be quite slow.
Similarly, depending on how your app is hosted you can face unbound network delays.
Thirdly, the time recorded for fetch by APMs is heavily impacted by the app servers CPU - was there high CPU load at the time?

1 Like

These spikes are random, it happens both during peak and lows. Loading from memory might be a culprit, sure.