[PERFORMANCE] same query, different execution time

Hi,

i have one query that have execution time different… 49761 millisecond or 4658 millisecond

i have activated profiler and this is that i view

profiler.json (183.3 KB)

both query use the same index

i know that probably i have to change the query for optimize, but i don’t understand because the execution time is real different!

Thank you

Hello @ilmagowalter ,

Upon checking the logs from Profiler, it looks identical only difference it shows is in

 "numYield": 2396 --> When time was "millis": 4658
 "numYield": 26383 --> When time was "millis": 49761

As per the Database Profiler

system.profile.numYield

The number of times the operation yielded to allow other operations to complete. Typically, operations yield when they need access to data that MongoDB has not yet fully read into memory. This allows other operations that have data in memory to complete while MongoDB reads in data for the yielding operation. For more information, see the FAQ on when operations yield.

Did your first run of the query took more time to return results than the second run?

If yes, then I think when you first ran the query it performed the operations and certain things are stored in cache for future use and when you re-ran the query it was faster due to the cache. Also, you can check if there were other operations already running while you ran the query first time and by the time you ran the query second time, the other operations were already complete.

I would recommend you to refer below documents for achieving better performance

Regards,
Tarun

1 Like

Yes the first execution was more slow than second execution.

Thank you

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.