Number of current connections to MongoDB

Please refer to below Problem-Solution from Tuning Connection Pool settings:

Problem Solution
Database CPU usage is higher than expected. The server logs or real time panel show more connection attempts than expected. Decrease the maxPoolSize or reduce the number of threads in your application. This can reduce load and response times.
  • 300 different clients does not necessarily mean that it will only use 300 connections. Please see below for more details.
  1. max_pool_size : The maximum allowable number of concurrent connections to each connected server. Requests to a server will block if there are maxPoolSize outstanding connections to the requested server. Defaults to 100. Cannot be 0. When a server’s pool has reached max_pool_size, operations for that server block waiting for a socket to be returned to the pool. If waitQueueTimeoutMS is set, a blocked operation will raise ConnectionFailure after a timeout. By default waitQueueTimeoutMS is not set.

  2. min_pool_size : The minimum required number of concurrent connections that the pool will maintain to each connected server. Default is 0.

so, 300 clients * (max connection pool size default which is 100) == 30,000 connections max possible.

  • The connection pool is automatically managed by pymongo itself, so it will create connections as required by the workload.

  • As per documentation on Connection Pool

Definition

A connection pool is a cache of open, ready-to-use database connections maintained by the driver. Your application can seamlessly get connections from the pool, perform operations, and return connections back to the pool. Connection pools are thread-safe.

Benefits of a Connection Pool

A connection pool helps reduce application latency and the number of times new connections are created. A connection pool creates connections at startup. Applications do not need to manually return connections to the pool. Instead, connections return to the pool automatically. Some connections are active and some are inactive but available. If your application requests a connection and there’s an available connection in the pool, a new connection does not need to be created.

Note: To handle the increase in workload, sufficient hardware resources are required by the database instance also.