I am constructing MongoClient Connection in the below manner :
public static synchronized MongoClient getInstance(String mongoDbUri) {
try {
// Standard URI format: mongodb://[dbuser:dbpassword@]host:port/dbname
if( mongoClient == null ){
mongoClient = new MongoClient(
new MongoClientURI(mongoDbUri));
}
} catch (Exception e) {
log.error(
"Error mongo connection : ",
e.getCause());
}
return mongoClient;
}
Over a period of time when multiple transaction is run I am seeing some memory eat up with the application which is not getting released.
When analysed the heap dump saw that there was memory consumption was maximum with the class
com.mongodb.internal.connection.PowerOfTwoBufferPool
The mongo client is trying to connect to a mongos instance.The application has 3 replica sets on 3 shards and one config server to hold the metadata.
To add more details to the same , I have a spring managed bean annotated with @Component.There is an annotation with @PostConstruct for the bean in which the above method is called.In the spring class we are doing insert/update/create using the Mongo Client.
I am kind of stuck with this issue last 2 days. Any pointers/approach to resolve will mean a lot to me.Thanks.