How can we restrict number of connections through each IP Address (defined in Network Access)?
For ex:
I have 5 IP-Addresses that I have given access, with respective threshold of number of connections can be active at a time:
IP-A – 1000
IP-B – 1000
IP-C – 1000
IP-D – 1000
IP-E – 1000
Now I have maximum 32000 connections that could parallely extablish the connection to my database. And I need to establish an automat system that could basically delete or deactivate all old connection that are trying to connect to my database if each IP has exceeds its given threshold limit.
How could I do that? Please help me
Hi @Mehul_Sanghvi,
Welcome to the MongoDB Community forums
There’s no any specific Atlas-side mechanism to limit the number of connections by IP.
However, you can use maxPoolSize option in connection string to limit the number of connection in the connection pool. The default value is 100
.
May I ask, why you specifically intend to do that?
As per my understanding, the application’s client gracefully uses a connection from the pool, and return it once its purpose is served. No explicit closure of connections is necessary, thereby sparing the application from the overhead of repeatedly creating and closing connections, is an expensive operation.
Best regards,
Kushagra
You can restrict the number of connections through each IP address by configuring your server settings or using a firewall to set connection limits per IP address. Additionally, some web server software like Apache and Nginx have built-in features or modules that allow you to limit connections per IP address.Hair Spray Packaging Boxes
Hello @Kushagra_Kesav
Thanx for your reply. To answer your question, basically I intend to do this because there was an issue raised on my database that leads to shutdown of my Primary Node. This issue was raised because multiple connections were opened and later they should be close immediately but they weren’t closed, because of which multiple operations were waited in execution queue and increased the load on my database cluster.
And as mongodb doesn’t automatically closes these connections, I thought to build a system that could help me on closing those connections by restricting each IP Addresses to certain amount of connections, if exceeds than needed to be killed.
@Custom_Boxes_Shop
Thanx for your reply. I will try to implement this solution on my MongoDB Cluster, if this helps will mark it as a solution.