How do connections/pooling work within driver

649 views
Skip to first unread message

Adam Geiger

unread,
Aug 1, 2018, 3:25:29 PM8/1/18
to mongodb-go-driver
I am taking a look at a problem I am seeing where a new connection is established to a cloud Mongo DB and every so often it fails due to:

dial tcp [ip:port]: i/o timeout 
or
dial tcp [ip:port]: getsockopt: connection timed out

I have taken a look in the connection package and put some print statements in pool.go under the get(...) function.  I see it use existing connections for a little and then create a new connection every so often, leading to my problem above.
I was wondering how connection and pooling logic works and if I can do anything from it creating new connections.  The longest time I wait before issuing a function from a collection is 1 minute. 

Any documentation or guidance will greatly be appreciated

Thanks

Kris Brandow

unread,
Aug 3, 2018, 11:34:14 AM8/3/18
to mongodb-...@googlegroups.com
Hi Adam,

What version of the driver are you using and are you using Atlas? If so, are you using the free tier or do you have a paid plan?

Thanks,
Kris

--
You received this message because you are subscribed to the Google Groups "mongodb-go-driver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-go-driver+unsubscribe@googlegroups.com.
To post to this group, send email to mongodb-go-driver@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-go-driver/edb82e34-972c-4f27-bfee-e2d43f24913e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Geiger

unread,
Aug 3, 2018, 5:12:09 PM8/3/18
to mongodb-go-driver
Hi Kris, 

Thanks for the reply.  I am using Alpha10 of the driver.  I am connecting to a MongoDB hosted by Compose.  It is strange that new connections are being established vs utilizing the existing ones which it does sometimes.  I am trying to debug why the new connections but haven't had any luck


On Friday, August 3, 2018 at 11:34:14 AM UTC-4, Kris Brandow wrote:
Hi Adam,

What version of the driver are you using and are you using Atlas? If so, are you using the free tier or do you have a paid plan?

Thanks,
Kris
On Wed, Aug 1, 2018 at 3:25 PM, Adam Geiger <arge...@gmail.com> wrote:
I am taking a look at a problem I am seeing where a new connection is established to a cloud Mongo DB and every so often it fails due to:

dial tcp [ip:port]: i/o timeout 
or
dial tcp [ip:port]: getsockopt: connection timed out

I have taken a look in the connection package and put some print statements in pool.go under the get(...) function.  I see it use existing connections for a little and then create a new connection every so often, leading to my problem above.
I was wondering how connection and pooling logic works and if I can do anything from it creating new connections.  The longest time I wait before issuing a function from a collection is 1 minute. 

Any documentation or guidance will greatly be appreciated

Thanks

--
You received this message because you are subscribed to the Google Groups "mongodb-go-driver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-go-dri...@googlegroups.com.
To post to this group, send email to mongodb-...@googlegroups.com.

Kris Brandow

unread,
Aug 3, 2018, 6:56:12 PM8/3/18
to mongodb-...@googlegroups.com
If you want the driver to only use the connections that are in the pool you need to set the maxIdleConnsPerHost and maxConnsPerHost to the same number, so when the driver needs another connection it will wait until one is returned to the pool. If you don’t set maxConnsPerHost, the driver will dial a new connection whenever there isn’t one available in the pool.

—Kris

To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-go-driver+unsubscribe@googlegroups.com.
To post to this group, send email to mongodb-go-driver@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-go-driver/505aa94c-da4a-4096-b399-7965bfd061af%40googlegroups.com.

Adam Geiger

unread,
Aug 7, 2018, 10:29:08 AM8/7/18
to mongodb-go-driver
Kris,

Appreciate the responses.  I think I narrowed down the dial/timeouts to a mongo replia problem.  After removing the one with problems, the errors went away. 
Reply all
Reply to author
Forward
0 new messages