Allanbank java async driver for MongoDB - connection leak?

87 views
Skip to first unread message

Archanaa Panda

unread,
Jan 30, 2016, 2:59:49 AM1/30/16
to mongodb-user
Hi,

I am currently using Allanbank's mongoClient particularly for asynchronous updates and batched inserts/updates in our spring web services application while using Spring Data mongodb for simple CRUD scenarios, which is based on the traditional mongodb java driver 2.13.0. Is it correct to use MongoClient as a connection pool to the database and keep the MongoClient open for the lifetime of a server-side application? Eg, in our spring application, we set the mongoClient in the constructor of our DAO class and then keep using the same for doing individual operations across multiple threads. Is there some operation we need to do return a connection to the connection pool of MongoClient.

Also, I have followed the example given in 
http://www.allanbank.com/mongodb-async-driver/userguide/batched.html and there seems to be no try-finally block to close any Closeable resource.

Snippet of my code

MongoCollection collection = mongoDatabase.getCollection("WSAccessThrottle");
BatchedWrite.Builder writes = BatchedWrite.builder();
DocumentBuilder queryBuilder = BuilderFactory.start();

DocumentBuilder updateBuilder = BuilderFactory.start();

for (WSAccessThrottle entry : changedEntries) {

queryBuilder.push("_id").add("endPt", entry.getId().getEndPt())

                       .add("url", entry.getId().getUrl());                   updateBuilder.push("$set").add("lastModfDt",entry.getLastModfDt()).add("expireAt",entry.getExpireAt()).add("numAccess", entry.getNumAccess());

writes.update(queryBuilder.build(), updateBuilder.build(), false, true);

queryBuilder.reset();

updateBuilder.reset();

}

collection.write(writes);



Of late I have been seeing too many connections open for MongoDB although I have set the max connections to 100, and the primary mongodb of our replicaset becomes unresponsive. Is there something fundamentally wrong in my understanding of allanbank ? Am i using it incorrectly?
I am also curious to know - how does the connection pool work for MongoClient. If I set the maxConnections to 100, does it acquire 100 connections right away? If there is a socket exception, are connections properly closed and the pool size reduced?

Stephen Steneker

unread,
Feb 1, 2016, 6:00:00 PM2/1/16
to mongodb-user

On Saturday, 30 January 2016 18:59:49 UTC+11, Archanaa Panda wrote:

I am currently using Allanbank’s mongoClient particularly for asynchronous updates and batched inserts/updates in our spring web services application while using Spring Data mongodb for simple CRUD scenarios, which is based on the traditional mongodb java driver 2.13.0.

Hi Archanaa,

As far as I’m aware the Allanbank driver does not have any dependencies on the standard MongoDB Java driver so it’s unclear if it implements similar connection management or server discovery and monitoring method. The Allanbank driver author does participate in this forum, but you may want to try asking the question directly in the Github issue queue for Allanbank async driver.

FYI, starting with the MongoDB 3.0 Java driver release there is also an officially supported asynchronous Java driver.

Regards,
Stephen

Reply all
Reply to author
Forward
0 new messages