What Can I Do If the Number of Connections of an Instance Reaches Its Maximum?
The number of connections indicates the number of applications that can be simultaneously connected to the database. The number of connections is irrelevant to the maximum number of users allowed by your applications or websites.
- For a cluster instance, the number of connections is the number of connections between the client and the dds mongos nodes.
- For a replica set instance, the number of connections is the number of connections between the client and the primary and secondary nodes.
When the number of connections to a DDS instance reaches the maximum supported, new connection requests cannot be responded to, and the connection attempt fails.
Symptom
Some common errors:
- If the following information is displayed when you use Mongo Shell to connect to an instance, no more connections can be established.
Figure 1 Message displayed
- If the following information is displayed when you use Python to connect to an instance, the number of connections reaches its maximum.
pymongo.errors.ServerSelectionTimeoutError: connection closed, connection closed
Handling Method
- Check what applications are connected, optimize the connections, and release any that are not necessary.
- Check the value of the net.maxIncomingConnections parameter and the instance specifications. Change the parameter value or the database specifications.
- Check for abnormal metrics and alarms on the Cloud Eye console. Cloud Eye monitors database metrics, such as the CPU usage, memory usage, storage space usage, and database connections, and allows you to set alarm policies to identify risks in advance if any alarms are generated. For details, see the Cloud Eye User Guide.
Solution
- Release unnecessary connections.
- You can restart the instance to release all of the connections. For details, see Restarting an Instance or a Node.
- You can query the current number of connections on a node and the connection source, analyze the number of connections established between each client and the instance, and adjust the number of connections. For details, see How Do I Query and Limit the Number of Connections?
- Change parameter values or database specifications.
You can change the maximum number of connections allowed for an instance by modifying the net.maxIncomingConnections parameter. Then, restart the instance for the modification to take effect. For details about how to change parameter values, see "Parameter Template Management" > "Modifying a Parameter Template" in the Document Database Service User Guide.
- If the value is default, the maximum number of connections depends on the instance specifications. For details, see Cluster.
- If the number of connections is too large, the service may break down. In this case, you can only change the DB instance class to increase the number of connections. For details, see "Instance Modifications" > "Changing an Instance Class" > "Changing a Cluster Instance Class" in the Document Database Service User Guide.
NoteIf a default parameter template is used, you cannot change its settings. You can create a parameter template and change the corresponding parameter values. After the change, associate the new parameter template with the instance.
- Check whether there are slow queries. You can add indexes to improve queries.
- Symptom
- Handling Method
- Solution