mongodbscalaconnection-poolingmongodb-javacasbah

connectionsPerHost and maxSize returns 10 when instantiating MongoCleint


I am using casbah scala drvier for mongodb here is how i am creating MongoClient instance

val SERVER:ServerAddress = {

val hostName=config.getString("db.hostname")

val port=config.getString("db.port").toInt
        new ServerAddress(hostName,port)
          }

val DATABASE:String   = config.getString("db.dbname")

val connectionMongo = MongoConnection(SERVER)

When I debug this line val connectionMongo = MongoConnection(SERVER) in the variables section inside MongoClient instance I see ConnectionsPerHost is equal to 10 and in Connectio Pool setting variable I see maxSize is 10 ,so I want to know what does it mean ? does its mean we have one connection pool created by MongoClient Instance and we have 10 connection in it ? please explain this ,Thank you

getConnectionPerHost() http://api.mongodb.com/java/current/com/mongodb/MongoClientOptions.html#getConnectionsPerHost--

getMaxSize() http://api.mongodb.com/java/current/com/mongodb/connection/ConnectionPoolSettings.html#getMaxSize--


Solution

  • This is because MongoClient creates a lazy populated internal connection pool. The default size of this pool is 10. Which you must be seeing in your debug. Another observation you may experience is that despite you having just 1 connection you might see more than 1 connection in the server log. The other connection is normally one from the pool and it can be your driver doing routine maintenance on the DB.