sean-b765 / covid-api

Find current or historical COVID-19 data. Uses JHU and OWID GitHub repositories as source.
0 stars 0 forks source link

Performing DB update still makes requests take too long #3

Closed sean-b765 closed 2 years ago

sean-b765 commented 2 years ago

After heroku has started from being idle, it will perform a DB update if it has been +12 hours since the last update. Heroku service=471ms shows that the request is being handled quickly, but the response must be taking long because MongoDB is being updated with so much data.

sean-b765 commented 2 years ago

As the free MongoDB plan is a replica set, we may be able to set a readPreference to ensure quicker data access. I believe this commit may speed up the response time while updating the DB. More testing will have to be done. Using readPreference: 'secondary' in mongoose connect options on the main thread may allow quicker data access while the DB is updating. The data being read may be stale but the response should be much quicker. Replication MongoDB data replication

May also use readPreference: 'nearest' as it chooses the replica node which has the least latency.