I am running a free tier Heroku app in the cloud using Node.js, alongside a free tier MongoDB cluster. I recently deployed my web server (used by our game for scores submission and retrieval), and it ran fine for the first night. The following day, I played our own game and noticed that the leaderboards were loading extremely slow. Sometimes, it wouldn't load at all. I went to the logs and saw that service
times were through the roof, sometimes reaching ~30 sec. I increased the poolSize
on the connection but it still ran slow. Today, it has run well with few issues, albeit still riddled with absurdly slow response times, hanging around the ~20 sec area. This feels so random. I looked into mongoose, based off this answer, but according to MongoDB's Node.js driver docs, a single connection is in itself a pool... What could be happening? My client connection is obtained as follows:
var DB = null;
mongodb.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true, poolSize: 70 }, (err, cli) => {
if (err) {
console.log("Error connecting to MongoDB Client: " + err);
return null;
}
client = cli;
DB = client.db(<database>);
});
This is a live server, with a live game depending on it, and timely responses would be greatly appreciated. Thanks for any help I can get.
EDIT: Will switching to mongoose help me in this situation?