What Can I Do If the Number of Connections of an Instance Reaches Its Maximum?
- 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.
Symptom
- If the following information is displayed when you use Mongo Shell to connect to an instance, no more connections can be established.
- 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
- You can also view the instance monitoring metrics to check whether the number of instance connections is used up.
Solution
- If the number of connections reaches the upper limit due to burst traffic, restart the instance or node to release the current connections. Also, check whether there is a large number of retry requests on the client. If the number of retry requests is used up, modify the client parameters to prevent the number of connections from being stacked. You need to modify the retry logic and increase the timeout retry duration.
Restarting an instance will restart the nodes of the instance in turn. Each node will be intermittently disconnected for about 30 seconds. If the number of collections exceeds 10,000, the intermittent disconnection duration will be prolonged. Before restarting an instance, arrange workloads and ensure that the application supports automatic reconnection.
- If the number of connections is used up due to long-term workloads, increase the maximum number of connections by changing the value of net.maxIncomingConnections. The change takes effect immediately. Ensure that a changed value is within 20% of the original value each time. After the value change, observe the load changes. If the load is too high after the number of connections is increased, the instance load has reached the bottleneck. In this case, upgrade the instance specifications in a timely manner.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot