Help Center/ Document Database Service/ FAQs/ Database Connection/ What Can I Do If the Number of Connections of an Instance Reaches Its Maximum?
Updated on 2023-03-15 GMT+08:00

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 mongos.
  • For a replica set instance, the number of connections is the number of connections between the client and the primary and secondary nodes.
  • For a single-node instance, the number of connections is the number of connections between the client and the node.

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

  1. Check what applications are connected, optimize the connections, and release any that are not necessary.
  2. Check the value of the net.maxIncomingConnections parameter and the instance specifications. Change the parameter value or the database specifications.
  3. 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

  1. Release unnecessary connections.
    1. You can restart the instance to release all of the connections. For details, see Restarting an Instance or a Node.
    2. 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?
  2. Change parameter values or database specifications.
    You can change the maximum number of connections of a DB instance by modifying the net.maxIncomingConnections parameter. Then, restart the DB instance for the modification to take effect. For details about how to change parameter values, see Editing a Parameter Template.
    • If the value is default, the maximum number of connections is the default value and is related to the instance specifications. For details, see Instance Specifications.
    • If there are too many connections, the service may break down. In this case, you can increase the number of connections by changing the instance specifications. For details, see Changing a Cluster Instance Class.

    If 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.

  3. Check whether there are . You can add indexes to improve queries.