7

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.

  • Can someone say me how works the pool connections on MGO and if is possible set up this pool?
  • Is it true that DialWithInfo create a Pool Connection or is only the Dial function that create this pool?

Thanks in Advance

1 Answer 1

10

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.

1
  • 1
    However, .Copy() should be used since it retains authentication, if applicable. Commented Nov 30, 2015 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.