- Netlify site name: hardcore-wiles-fbe1f0.netlify.app
- Custom domain: https://app.squishalert.com/ , Native IOS/Android App
- Issue: My mobile app is getting around a few thousands of requests (I have 8000+ users) at some point and I notice my Mongodb connection (I’m using a free cluster right now) is reaching 500 connections which causes timeout issue.
I’m new to serverless. I’m just here to ask whether this a normal behavior that Netlify serverless is generating over 500 database connections. When there isn’t a lot of traffic, I still get over 400 open connections. I do cache my mongo connection (code attached) but I understand that I’m getting thousands of requests so I wonder if it’s the right behavior that Netlify serverless is generating a lot of connections or my caching/logic for Netlify serverless is incorrect at some point. What is the maximum request can one Netlify function container handle. I’m using Netlify function free tier (level 0)
Thank you very much
const mongoose = require("mongoose");
let cachedMongooseDb = null;
async function connectToDB() {
const uri = "mongodb://127.0.0.1:27017/databasename";
if (cachedMongooseDb && cachedMongooseDb._readyState === 1) {
return cachedMongooseDb;
} else {
const connect = await mongoose.connect(uri, {
useNewUrlParser: true,
useFindAndModify: false,
useCreateIndex: true,
useUnifiedTopology: true,
});
cachedMongooseDb = connect.connection;
console.log("--Connected to the db--");
return cachedMongooseDb;
}
}