MongoDB Atlas - Different execution times when query is run from different servers

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?

Hello Amin,
Could you provide some more information…
Are the specs for each machine you ran it on the same? For example RAM/CPU.

What were you running the query from? Were you connected to the Mongo shell, Compass, or through an application?

If you are running from the shell you could add the .explain(“executionStats”) to the end of the query to get a more detailed breakdown.

1 Like

No. The specs are different:

  1. Local - 16GB RAM / 6-Core CPU - 0.3 seconds
  2. Server1 - 2 GB RAM / 2-Core CPU - 4 seconds
  3. Server2 - 4 GB RAM / 2-Core CPU - 1.8 seconds

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:*******

I’ll see if I can do this from pymongo

How did you determine your execution time?

Yes, the processing is happening on the Atlas instance but a few things need to be considered.

  1. The results are still sent over the wire. So network topology and network usage has an impact.
  2. 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.
  3. 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.
  4. The type of Atlas cluster. Some are shared clusters and you cannot depend on having all the same resources at different test period.
  5. 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.
1 Like