Incredibly slow serverless performance

I’m just switching from a simple docker based node instance with the default sizing to MongoDB Atlas serverless. I have migrated all my data (export then import using Compass), and I have recreated all the indexes as they were on the source database.

However, I am seeing massively slower performance accessing the data from my dev website running locally. I am expecting it to be slower, but not like this. I have a page that runs 4 different aggregate functions across a few different collections. Any fields that need to be are indexed.

On my local Docker instance of MongoDB, the maximum time I am seeing for the page to render is about 500ms. On MongoDB Atlas the same page is taking 45-120 seconds to load!! Looking at my logs from sveltekit, I can see the DB queries genuinley take the time stated above. The Performance Advisor is not suggesting any new indexes or changes.

It shouldn’t be this awful should it?

The really long delays appear to be some sort of timeout on the connection. If I keep clicking links then they load withing a few seconds, so still slower than locally, but not minutes. If I walk away, then come back after 10 mins and click a link, it then can take a minute or more, but the entire time my log is reporting MongoDB is connected and it is waiting for the DB response.

I am using Mongoose version 6.5.2 as my connection library. I’ve enabled connection debugging and events, and the client doesn’t think it disconnects. It is like the serverless instance is going to sleep for 30 seconds after so many minutes of inactivity. I have other processes inserting data so it isn’t because nothing is happening with the DB.

Correction it is 5 minutes. After that time the first aggregation query takes ages.

Hi Stephen,
I work in the MongoDB Atlas Serverless PM team. Based on the what you are describing it seems like there is something on the client side (where mongoose is running) which is stopping the connections. Perhaps check your firewall settings. One way to check this would be to use mongosh on the client machine and test the connections and compare with mongosh running from local. Let us know what you find out.