7

Blocking MongoDB driver has MongoClientOptions, which contains client settings.
Reactive driver's MongoClients.create() expects MongoClientSettings as parameter.
Most settings from MongoClientOptions have their equivalent in MongoClientSettings.

But I can't find connectionsPerHost alternative in MongoClientSettings.
Am I missing something?

alper
  • 322
  • 2
  • 14

3 Answers3

9

I believe the connectionsPerHost parameter was changed to ConnectionPoolSettings.maxSize, as part of the new MongoDB driver design. Please take this with a pinch of salt, as I have not tested whether it is a perfectly equivalent option.

The description for threadsAllowedToBlockForConnectionMultiplier is as follows, from the MongoDB documentation of MongoClientSettings.getConnectionPoolSettings() the Async driver:

Gets the settings for the connection provider in a settings object. This settings object wraps the values for minConnectionPoolSize, maxConnectionPoolSize, maxWaitTime, maxConnectionIdleTime and maxConnectionLifeTime, and uses maxConnectionPoolSize and threadsAllowedToBlockForConnectionMultiplier to calculate maxWaitQueueSize.

This behaviour can be observed in ConnectionPoolSettings.applyConnectionString():

maxWaitQueueSize(threadsAllowedToBlockForConnectionMultiplier * maxSize);

This behaviour appears to be similar, when compared to the description for the original MongoClientOptions.getThreadsAllowedToBlockForConnectionMultiplier():

This multiplier, multiplied with the connectionsPerHost setting, gives the maximum number of threads that may be waiting for a connection to become available from the pool. All further threads will get an exception right away. For example if connectionsPerHost is 10 and threadsAllowedToBlockForConnectionMultiplier is 5, then up to 50 threads can wait for a connection.

SP193
  • 156
  • 2
  • 5
1

Update, in 4.4.X maxWaitQueueSize is gone(it is also marked as @deprecated in 3.12.X), I think maxConnecting had replaced it, so if you are still using the maxWaitQueueSize using old logic, the maxConnecting value should be as in the previous answer

maxConnecting = maxWaitQueueSize(threadsAllowedToBlockForConnectionMultiplier * maxSize);
Roie Beck
  • 1,113
  • 3
  • 15
  • 30
0

Responding to @Sp193. Following

threadsAllowedToBlockForConnectionMultiplier

actually covered here ConnectionString Javadoc

  • maxPoolSize=n: The maximum number of connections in the connection pool.
  • waitQueueMultiple=n : this multiplier, multiplied with the maxPoolSize setting, gives the maximum number of threads that may be waiting for a connection to become available from the pool. All further threads will get an exception right away.
  • waitQueueTimeoutMS=ms: The maximum wait time in milliseconds that a thread may wait for a connection to become available.