Hi everyone,
I dont know why but my numbers of connections keep increasing with time, i have multiple servers using the database but each server make only one connction (with a max connections pool of 100 ) and my number of connections keep increasing by 500 every day.
here is my node.js code to start the connection
const isDevelopment = process.env.NODE_ENV != 'production';
const maxPoolSize = isDevelopment ? 5 : 100;
const httpServer = createServer(app);
httpServer.timeout = 120000;
mongoose
.connect(MONGODB_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
maxPoolSize,
maxIdleTimeMS: 30000,
} as mongoose.ConnectOptions)
.then(() => {
logger.info(`Connected to the database:${MONGODB_URL}`);
const maxPoolSize = (mongoose.connection as any).client.options.maxPoolSize;
logger.info(`Max Pool Size: ${maxPoolSize}`);
const io = createSocketServer(httpServer, {
cors: corsOptions,
});
app.set('socketio', io);
httpServer.listen(PORT, () => {
logger.info(`Server is running on port ${PORT}.`);
});
})
.catch((err: any) => {
logger.error('DB_ERROR', 1, err);
process.exit(1);
});
and the one in C#
builder.Services.AddSingleton<IMongoClient>(x =>
{
var env = x.GetRequiredService<IWebHostEnvironment>();
bool isDevelopmentEnvironment = env.IsDevelopment();
var settings = x.GetRequiredService<IOptions<DatabaseSettings>>().Value;
var clientSettings = MongoClientSettings.FromUrl(new MongoUrl(settings.ConnectionString));
clientSettings.MaxConnectionPoolSize = isDevelopmentEnvironment ? 5 : 100;
return new MongoClient(clientSettings);
});
Any ideas of what I am doing wrong ?
Appreciate your help !