I've a multi-threaded (POSIX threads) application written in C++ which now needs to send data to MongoDB. Each thread is supposed to send data independently. Currently, I am making a new connection in each thread- and as expected, the performance is

21 views
Skip to first unread message

gaur hari

unread,
Sep 26, 2012, 1:20:24 AM9/26/12
to mongod...@googlegroups.com
I've a multi-threaded (POSIX threads) application written in C++ which now needs to send data to MongoDB. Each thread is supposed to send data independently. Currently, I am making a new connection in each thread- and as expected, the performance is poor due to overhead in creating TCP connection each time.

What I would like to do is to be able to create connection is main() function and then pass the connection reference to the threads so that they can utilize underlying connection.

My question is- if I go with above plan, I will be creating only one connection. Is it possible to create a pool of connections using MongoDB C++ driver and then pass the pool reference to the individual threads which can then use any of the available connection from the pool to send data to MongoDB?

Will I be re-inventing the wheel? if there is already a sample code available for MongoDB connection pooling using C++ driver, please point me to it.

Thanks!
Reply all
Reply to author
Forward
0 new messages