Issue
I have an Express (Node.JS) + MongoDB app with a server response load time of 4 - 7 seconds on average (slow).
I understand that the average server response time is under 200ms as per google pagespeed tools.
This app is fetching data from a mongoDB asynchronously but the roundtrip times to the database is extremely slow with each call averaging about 500ms - 1s. These calls are simple findAll calls to retrieve data of less than < 100 records.
Context
- Mongoose version: 4.13.14
- DB server's MongoDB version is 3.4.16
- DB server is hosted on MongoDB Atlas M10 in AWS / Oregon (us-west-1)
- Web server is hosted with now.sh in SFO1 (us-west-1)
- Have performed recommended indexes as advised by MongoDB Atlas's performance advisor
- Data fetching perfectly fine in local environment (local server + local db) as data is queried in a matter of few ms
- Mongoose logs for the affected page can be found in this gist
Mongo Server configuration
- Mongo Atlas M10
- 2GB Ram
- 10 GB Storage
- 100 IOPS
- Encrypted
- Auto-expand storage
Attempted solutions:
I have checked my DB metrics, they looked fine. There are also no slow queries. These are simple findAll queries. Performance advisor on mongo atlas reports nothing unusual.
The production application and database are both hosted in the same region.
I have already tried optimising the application layer of the query (mongoose) by running .lean()
Question:
Where else should i look to improve the database latency? How can a simple query take so long? Otherwise, why is my server response time taking up to 4s when the expected is about 200ms?