Hi! Wanted to know why am I getting different execution times for the same query I ran on different servers and on my local machine. For instance, I am getting 0.3 seconds on my laptop, 4 seconds on an ubuntu server and 1.8 seconds on another ubuntu server. All of them ran the same code on the same Atlas instance and same database. The time remains the same (±0.2 seconds) on multiple tries, for all of them.
Shouldn’t it take the same amount of time regardless of where it is run from since the actual execution takes place on cloud server? Or does it depend on something?
But hardware shouldn’t have any effect right? Since query execution takes place on Atlas servers?
I am running the queries from Django/Celery using pymongo (pymongo · PyPI), using the Atlas connection url (mongodb+srv://username:*******@clustername.abcd.mongodb.net/?retryWrites=true&w=majority)
Yes, the processing is happening on the Atlas instance but a few things need to be considered.
The results are still sent over the wire. So network topology and network usage has an impact.
Depending of the size of the result sets, memory size on the client side has an impact. Your numbers seem to indicate such a impact. More RAM is faster and less RAM is slower. And frankly, a server with 2GB and 2 cores is under powered.
The current load on the client (the laptop and the 2 servers) has an impact. The 2 slow configurations are servers. What they were doing at the time has an impact, a bigger one on the server with less core and less memory.
The type of Atlas cluster. Some are shared clusters and you cannot depend on having all the same resources at different test period.
The order of the tests and the state of the cluster might have an impact. On a cold server where the working set is not yet in cache, the first test will be slower has as the data has to be loaded from permanent storage.