MongoDB: Queries running twice slow on NEW server compared to OLD server

163 Views Asked by At

I transferred current/old running DB into a new standalone server for MongoDB. To do this, I performed the following:

  1. Took dump of data from OLD server
  2. Restored data from the generated dump into NEW server
  3. Configured the server for authentication

Issue:
I noticed that after performing the above, few queries on the NEW server were running slow almost twice the time compared to their performance on the OLD server.

Configurations:
The configurations of both the servers are same however the NEW server has 32 GB RAM while the OLD server had 28GB RAM. OLD server had other applications and servers running as well. While the NEW server is a dedicated server only for this DB.

CPU consumption is similar however RAM is heavily occupied in the OLD server while it is comparatively less occupied on NEW server.

Therefore, NEW server is better equipped in hardware and RAM consumption. Also NEW server is standalone dedicated to only this DB.

Question:
Why could my NEW server even though it is standalone be slow compared to OLD one? How can I correct this?

1

There are 1 best solutions below

1
On

MongoDB keeps the most recently used data in RAM. If you have created indexes for your queries and your working data set fits in RAM, MongoDB serves all queries from memory.

So your OLD DB has cached data in memory and whenever you are performing the query your results may be coming from memory.

Also by default wired tiger consumes 50% of memory for internal cache. Hence, the heavy memory consumption and better performance for your OLD DB.

Since you just restored the dump on your NEW DB, it doesn't have any recent data cached into the memory.

So whenever you perform a query it is hitting the disk and performing the I/O operations, which impacts your query performance.

If you fire a set of queries a couple of times, MongoDB will cache the result if it fits in your memory and it will give you better performance on your queries on NEW DB

Here are some docs that may help you get more information https://docs.mongodb.com/manual/core/wiredtiger/#wiredtiger-ram https://docs.mongodb.com/manual/faq/fundamentals/#does-mongodb-handle-caching