In the article running-mongodb-queries-concurrently-with-go said that mgo.DialWithInfo : Create a session which maintains a pool of socket connections to MongoDB, but when I looking for in the documentacion of the function DialWithInfo I do not find something that talk me about pool connection, only I find something in the Dial Function Dial Function that said : This method is generally called just once for a given cluster. Further sessions to the same cluster are then established using the New or Copy methods on the obtained session. This will make them share the underlying cluster, and manage the pool of connections appropriately.
Thanks in Advance
Looking into the source code for the Dial function calls, you can see that the Dial
function calls the DialWithTimeout
function which calls the DialWithInfo
function. So to answer your question about the differences between the functions, it seems like Dial
is a convenience wrapper for DialWithTimeout
, which in turn is a convenience wrapper for DialWithInfo
, so they result in the same connection pool.
As to how to manage that connection pool, you've got it right in your question.
Further sessions to the same cluster are then established using the New or Copy methods on the obtained session. This will make them share the underlying cluster, and manage the pool of connections appropriately.
So a single call to Dial
or DialWithTimeout
or DialWithInfo
will establish the connection pool, if you require more than one session, use the session.New()
or session.Copy()
methods to obtain it from the session returned from whichever Dial function you chose to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With