@@ -575,6 +575,11 @@ Ruby Options
575575 - ``Object``
576576 - ``Logger``
577577
578+ * - ``:max_connecting``
579+ - The maximum number of connections that the connection pool will try to establish in parallel.
580+ - ``Integer``
581+ - 2
582+
578583 * - ``:max_idle_time``
579584 - The maximum time, in seconds, that a connection can be idle before it
580585 is closed by the connection pool.
@@ -1018,6 +1023,9 @@ URI options are explained in detail in the :manual:`Connection URI reference
10181023 * - localThresholdMS=Integer
10191024 - ``:local_threshold => Float``
10201025
1026+ * - maxConnecting=Integer
1027+ - ``:max_connecting => Integer``
1028+
10211029 * - maxIdleTimeMS=Integer
10221030 - ``:max_idle_time => Float``
10231031
@@ -1551,6 +1559,14 @@ maximum size, the thread waits for a connection to be returned to the pool by
15511559another thread. If ``max_pool_size`` is set to zero, there is no limit for the
15521560maximum number of connections in the pool.
15531561
1562+ Each pool has a limit on the number of connections that can be concurrently
1563+ connecting to a server. This limit is called ``max_connecting`` and defaults to
1564+ 2. If the number of connections that are currently connecting to a server
1565+ reaches this limit, the pool will wait for a connection attempt to succeed or
1566+ fail before attempting to create a new connection. If your application
1567+ has a large number of threads, you may want to increase ``max_connecting`` to avoid
1568+ having threads wait for a connection to be established.
1569+
15541570The number of seconds the thread will wait for a connection to become available
15551571is configurable. This setting, called ``wait_queue_timeout``, is defined in
15561572seconds. If this timeout is reached, a ``Timeout::Error`` is raised. The
@@ -1595,6 +1611,14 @@ process, increase ``max_pool_size``:
15951611
15961612 client = Mongo::Client.new(["localhost:27017"], max_pool_size: 200)
15971613
1614+ To support extremely high numbers of threads that share the same client
1615+ within one process, increase ``max_connecting``:
1616+
1617+ .. code-block:: ruby
1618+
1619+ client = Mongo::Client.new(["localhost:27017"], max_pool_size: 200, max_connecting: 10)
1620+
1621+
15981622Any number of threads are allowed to wait for connections to become available,
15991623and they can wait the default (1 second) or the ``wait_queue_timeout`` setting:
16001624
@@ -1627,7 +1651,7 @@ such as Unicorn, Puma or Passenger, or when the application otherwise forks,
16271651each process should generally each have their own ``Mongo::Client`` instances.
16281652This is because:
16291653
1630- 1. The background threads remain in the parent process and are not transfered
1654+ 1. The background threads remain in the parent process and are not transferred
16311655 to the child process.
163216562. File descriptors like network sockets are shared between parent and
16331657 child processes.
0 commit comments