I am working on a demo Java application that uses MongoDB for basic retrievals of data and I am using mongodb-driver-sync:4.4.1
Java driver.
In that, I am trying to analyze which operation of MongoDB is taking how much time, so that I can speed up my application by writing code efficiently. After experimenting, I noticed that MongoClients.create()
function is taking about 170ms to execute. After only a few repeated continuous invocations, this time started decreasing to about 130ms. But I performed a brief context switch of applications in the OS (like spending time on browser and other applications). After coming back to the Java application, I noticed that the time taken by the above function increased to around 170ms, which again gradually decreased to about 130ms after repeated execution without any context switch.
This behaviour is affecting the accuracy of my experiments and is causing the total time to vary by +/-40ms because of the MongoClients.create()
function. Can anyone please explain why this behaviour is occurring? Is the OS trying to cache something? If yes, what is it trying to do?
OS version: macOS Catalina, v10.15.7
Any help is appreciated. Thanks.