All Products
Search
Document Center

How to query and limit the number of connections to an apsaradb for MongoDB instance

Last Updated: Sep 30, 2020

Overview

This topic describes how to query the connection usage of an apsaradb for MongoDB instance and the number of connections in a connection pool.

Description

Alibaba Cloud reminds you that:

  • Before you perform operations that may cause risks, such as modifying instance configurations or data, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.
  • You can modify the configurations and data of instances including but not limited to Elastic Compute Service (ECS) and Relational Database Service (RDS) instances. Before the modification, we recommend that you create snapshots or enable RDS log backup.
  • If you have authorized or submitted sensitive information such as the logon account and password in the Alibaba Cloud Management Console, we recommend that you modify such information in a timely manner.

Query the number of connections to an apsaradb for MongoDB instance

The maximum number of connections depends on the specifications of the ApsaraDB for MongoDB instance you purchased. For more information, see Instance specifications.
Instructions the maximum number of connections measures the maximum number of connections of each node in the instance. For example, if you have purchased a three-node replica set instance with one core and 2 GB memory, the maximum number of connections of the Primary and Secondary nodes of the instance is 500, respectively. The Hidden node does not provide services for external systems due to its special architecture.
  1. Connect to an apsaradb for MongoDB instance through the Mongo Shell. For more information, see connect to an instance.
  2. Run the following SQL statement to query the number of connections of the current MongoDB instance:
    db.serverStatus().connections
     The following command output is returned.
    {
            "current" : 1,
            "available" : 999,
            "internal_current" : 10,
            "internal_available" : 990,
            "totalCreated" : 632
    }             
    Instructions you need to pay attention to the following parameters and their values.
    • current: The number of established connections.
    • available: the number of available connections.

Query connection sources of the current apsaradb for MongoDB instance

  1. Connect to an apsaradb for MongoDB instance through the Mongo Shell. For more information, see connect to an instance.
  2. Run the following SQL statement to switch to the admin database:
    use admin
  3. Run the following SQL statement to query the source MongoDB instance connection:
    db.runCommand({currentOp: 1, $all:[{"active" : true}]})
    Instructions you can query the source IP address of each connection by analyzing the command output. In this way, you can learn the number of connections that have been established between each terminal and the apsaradb for MongoDB instance. For more information, see official documentation

How to query and limit the number of connections

You can use a connection string URI to connect to ApsaraDB for MongoDB. When you connect to the database through the Connection String URI, &maxPoolSize=[$Integer] parameters to set the number of connections in the connection pool. The following example uses the Mongo Shell to connect to IA:

mongo "mongodb://root:xxxxxx@dds-bpxxxxxxxx-pub.mongodb.rds.aliyuncs.com:3717,dds-bpxxxxxxxx-pub.mongodb.rds.aliyuncs.com:3717/admin? replicaSet=mgset-xxxxxx&maxPoolSize=[$Integer]"

Note:

  • For more information about how clients in different programming languages limit the number of connections in the connection pool, see MongoDB API documentation.
  • [$Integer] is the number of connections in the connection pool.

Application scope

  • ApsaraDB for MongoDB