How is mongodb connection pooling increases memory consumption ?

Connection Creation
MongoClientOptions options = MongoClientOptions.builder()	    
	.threadsAllowedToBlockForConnectionMultiplier(prop.getThreadsAllowedToBlock())
	.connectionsPerHost(10)
	.connectTimeout(1000)
	.maxWaitTime(1000)
	.heartbeatConnectTimeout(prop.getHeartbeatConnectTimeout())
	.socketTimeout(1000)
	.writeConcern(WriteConcern.ACKNOWLEDGED).build();
MongoClient mongoclient = new MongoClient(seeds,credential, options); credential, options);


RAM, mainly. Every connection gets a stack-allocated, at the size of 1MB.The more connections you
have, the more RAM is needed for them and the less RAM is available for keeping indices or the
working set of data in RAM. Number of connections per application must be decided based on 
	1.Amount of memory available at server-side  
	2.Number of aggregation queries fired any given point of time  
	3.Working set at any given point of time 
And most importantly what is the expected performance at the client-side, if client should not wait for the
connections, obviously connections per host must be high, so that no client request waits for the
connection, instead server-side needs to have enough memory for all hungry connections.  When
mentioned connectionsPerHost=10, server allocates 1MB RAM per connection.
db.serverStatus()

And finally, keep checking and tuning the connections based on the availability and server capacity 

Comments