Database: Is it necessary to use Copy() function? #6

Closed
opened 2014-04-26 09:40:11 +00:00 by thorsten · 6 comments
thorsten commented 2014-04-26 09:40:11 +00:00 (Migrated from devops.tsommer.org)

Is it necessary to create for any database call a copied database session or is it fine to use the global session?

At the Gophercon, Gustavo Niemeyer said this:

Manipulating MongoDB using mgo
Gustavo described how to use mgo.Dial to connect to MongoDB. Once connected, the caller receives a session. Concurrent callers typically use copied sessions (obtained using the Copy() method).

[...]

Concurrency using separate (Copy’d) sessions
If you use a global session with the mgo driver, each query will wait for the previous query to return. The mgo driver lets you perform concurrent operations against the database by using separate, copied sessions. When you use a separate session, the query is issued without waiting.

Is it necessary to create for any database call a copied database session or is it fine to use the global session? <b>At the Gophercon, Gustavo Niemeyer said this:</b> <b>Manipulating MongoDB using mgo</b> Gustavo described how to use mgo.Dial to connect to MongoDB. Once connected, the caller receives a session. Concurrent callers typically use copied sessions (obtained using the Copy() method). [...] <b>Concurrency using separate (Copy’d) sessions</b> If you use a global session with the mgo driver, each query will wait for the previous query to return. The mgo driver lets you perform concurrent operations against the database by using separate, copied sessions. When you use a separate session, the query is issued without waiting.
thorsten commented 2014-04-26 09:40:45 +00:00 (Migrated from devops.tsommer.org)
Source: http://gophercon.sourcegraph.com/post/83822679358/gustavo-niemeyer-and-steve-francia-painless-data
thorsten commented 2014-06-04 12:18:38 +00:00 (Migrated from devops.tsommer.org)

Yes, this is a bug!

Yes, this is a bug!
thorsten commented 2014-06-04 12:39:20 +00:00 (Migrated from devops.tsommer.org)
http://www.youtube.com/watch?v=9OkclcLgR0U
thorsten commented 2014-06-04 12:39:56 +00:00 (Migrated from devops.tsommer.org)

It is necessary to call Close() for the copied session!

It is necessary to call Close() for the copied session!
thorsten commented 2014-06-04 13:55:21 +00:00 (Migrated from devops.tsommer.org)

Done. The DB() and GridFS() functions are returning now also the copied session. All Ocean's internal packages are using this new implementation and they are also closing the sessions!

Done. The DB() and GridFS() functions are returning now also the copied session. All Ocean's internal packages are using this new implementation and they are also closing the sessions!
thorsten commented 2014-06-05 09:23:26 +00:00 (Migrated from devops.tsommer.org)

Tests passed :)

Tests passed :)
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Go/Ocean#6
No description provided.