AFAIK the MongoConnection class actually represents a connection pool so what I've done so far is to initialize the MongoConnection and MongoCollection instances when my repository actor is created and to make sure the connection is closed when the actor dies. In other words, I'm using a MongoConnection for potentially days/weeks/months.
If that is not the intended usage pattern and we should really be creating and closing connections for every single interaction with Mongo, then I'd love to hear about it.
On Wednesday, October 24, 2012 11:13:49 AM UTC+3, Age Mooij wrote:
> Interesting question!
> AFAIK the MongoConnection class actually represents a connection pool so > what I've done so far is to initialize the MongoConnection and > MongoCollection instances when my repository actor is created and to make > sure the connection is closed when the actor dies. In other words, I'm > using a MongoConnection for potentially days/weeks/months.
> If that is not the intended usage pattern and we should really be creating > and closing connections for every single interaction with Mongo, then I'd > love to hear about it.
> Age
> On Tuesday, October 23, 2012 12:52:15 PM UTC+2, iwein...@gmail.com wrote:
>> Is there a fix for the connection leaks that casbah is prone too? I've >> written my own template, and so has at least one other:
Which of the two usage patterns would you advise? keeping a connection/collection open for long periods or opening them for each individual interaction with Mongo?
Age
On Oct 24, 2012, at 11:14, "Brendan W. McAdams" <bwmcad...@gmail.com> wrote:
> I wasn't aware of any connection leaks, but I do find the current Java driver connection pool to be atrocious.
> I'm working on the 2.5.0 release this week, and I'll see if I can't integrate a change along these lines to mitigate some of the pooling problems.
> I know in 2.9.x java driver there have been some tweaks to the pool as well that may fix some of this.
> On Wednesday, October 24, 2012 11:13:49 AM UTC+3, Age Mooij wrote:
> Interesting question!
> AFAIK the MongoConnection class actually represents a connection pool so what I've done so far is to initialize the MongoConnection and MongoCollection instances when my repository actor is created and to make sure the connection is closed when the actor dies. In other words, I'm using a MongoConnection for potentially days/weeks/months.
> If that is not the intended usage pattern and we should really be creating and closing connections for every single interaction with Mongo, then I'd love to hear about it.
> Age
> On Tuesday, October 23, 2012 12:52:15 PM UTC+2, iwein...@gmail.com wrote:
> Is there a fix for the connection leaks that casbah is prone too? I've written my own template, and so has at least one other:
I don't know, as I'm not aware of any actual connection leaks.
There is a pool, so it should return to the pool. I doubt it's a Java
issue, there may be something I'm doing wrong on the Scala end that is
causing references to be held on ot… need tos ee if there's an easy way to
track that down.
On Wed, Oct 24, 2012 at 12:21 PM, Age Mooij <age.mo...@gmail.com> wrote:
> Which of the two usage patterns would you advise? keeping a
> connection/collection open for long periods or opening them for each
> individual interaction with Mongo?
> Age
> On Oct 24, 2012, at 11:14, "Brendan W. McAdams" <bwmcad...@gmail.com>
> wrote:
> I wasn't aware of any connection leaks, but I do find the current Java
> driver connection pool to be atrocious.
> I'm working on the 2.5.0 release this week, and I'll see if I can't
> integrate a change along these lines to mitigate some of the pooling
> problems.
> I know in 2.9.x java driver there have been some tweaks to the pool as
> well that may fix some of this.
> On Wednesday, October 24, 2012 11:13:49 AM UTC+3, Age Mooij wrote:
>> Interesting question!
>> AFAIK the MongoConnection class actually represents a connection pool so
>> what I've done so far is to initialize the MongoConnection and
>> MongoCollection instances when my repository actor is created and to make
>> sure the connection is closed when the actor dies. In other words, I'm
>> using a MongoConnection for potentially days/weeks/months.
>> If that is not the intended usage pattern and we should really be
>> creating and closing connections for every single interaction with Mongo,
>> then I'd love to hear about it.
>> Age
>> On Tuesday, October 23, 2012 12:52:15 PM UTC+2, iwein...@gmail.com wrote:
>>> Is there a fix for the connection leaks that casbah is prone too? I've
>>> written my own template, and so has at least one other:
Reading through the linked post, I still don't see leakage happening.
Casbah provides you with a connection *POOL*, not an individual connection.
calling close() shuts down the *entire connection pool*. This is the "leakage" you are observing: The connection pool opens a pool of connections, not an individual connection.
This is incorrect usage, and you should be utilizing the pool. The Connection objects will be released back into the pool when unused and you don't need to close them manually.
I just went over this with Age. It seems that indeed I was using the
pool in the wrong way (although we didn't reproduce that). I'll get
back to this if I can confirm a problem, otherwise I'd assume
everything is fine.
Thanks!
On Wed, Oct 24, 2012 at 2:49 PM, Brendan W. McAdams <bren...@10gen.com> wrote:
> Reading through the linked post, I still don't see leakage happening.
> Casbah provides you with a connection *POOL*, not an individual connection.
> calling close() shuts down the entire connection pool. This is the
> "leakage" you are observing: The connection pool opens a pool of
> connections, not an individual connection.
> This is incorrect usage, and you should be utilizing the pool. The
> Connection objects will be released back into the pool when unused and you
> don't need to close them manually.
> I will update the docs to clarify that.
> On Tuesday, 23 October 2012 13:52:15 UTC+3, iwein...@gmail.com wrote:
>> Is there a fix for the connection leaks that casbah is prone too? I've
>> written my own template, and so has at least one other:
FWIW, I wrote the article at alvinalexander.com mentioned near the beginning of this discussion. I just figured out what I was doing wrong, and posted a small sample project at Github that shows how to insert objects into MongoDB with Casbah without leaking connections:
There may be a better way to do this, but I want to use Casbah with Scalatra, and using the MongoFactory and DAO approach in my Stock class seems like what I want.
I just wanted to let you know that this was user error (me), and I'll update or delete the article on alvinalexander.com tonight.
On Wednesday, October 24, 2012 6:49:49 AM UTC-6, Brendan W. McAdams wrote:
> Reading through the linked post, I still don't see leakage happening.
> Casbah provides you with a connection *POOL*, not an individual connection.
> calling close() shuts down the *entire connection pool*. This is the > "leakage" you are observing: The connection pool opens a pool of > connections, not an individual connection.
> This is incorrect usage, and you should be utilizing the pool. The > Connection objects will be released back into the pool when unused and you > don't need to close them manually.
> I will update the docs to clarify that.
> On Tuesday, 23 October 2012 13:52:15 UTC+3, iwein...@gmail.com wrote:
>> Is there a fix for the connection leaks that casbah is prone too? I've >> written my own template, and so has at least one other:
Kudos for posting back here. Please update the article (don't delete
it), you're not the first to fall into this and people (like me :p)
could really use the background.
On Tue, Nov 13, 2012 at 8:22 PM, Alvin Alexander <devda...@gmail.com> wrote:
> FWIW, I wrote the article at alvinalexander.com mentioned near the beginning
> of this discussion. I just figured out what I was doing wrong, and posted a
> small sample project at Github that shows how to insert objects into MongoDB
> with Casbah without leaking connections:
> There may be a better way to do this, but I want to use Casbah with
> Scalatra, and using the MongoFactory and DAO approach in my Stock class
> seems like what I want.
> I just wanted to let you know that this was user error (me), and I'll update
> or delete the article on alvinalexander.com tonight.
> On Wednesday, October 24, 2012 6:49:49 AM UTC-6, Brendan W. McAdams wrote:
>> Reading through the linked post, I still don't see leakage happening.
>> Casbah provides you with a connection *POOL*, not an individual
>> connection.
>> calling close() shuts down the entire connection pool. This is the
>> "leakage" you are observing: The connection pool opens a pool of
>> connections, not an individual connection.
>> This is incorrect usage, and you should be utilizing the pool. The
>> Connection objects will be released back into the pool when unused and you
>> don't need to close them manually.
>> I will update the docs to clarify that.
>> On Tuesday, 23 October 2012 13:52:15 UTC+3, iwein...@gmail.com wrote:
>>> Is there a fix for the connection leaks that casbah is prone too? I've
>>> written my own template, and so has at least one other:
This matches how I use Casbah. I set up the MongoConnection and the required MongoCollections when my repository (actor) gets created (started) and I just reuse the collections until it's time to shut down. Casbah should take care of the connection pooling.
One important thing to think about though is that by default Casbah (or the underlying Java driver) does not retry after a connection failure. so if there is a brief network outage between your code and the Mongo server, your app won;t be able to recover. There's an easy fix for this (which I think should be default): set the correct option:
MongoOptions(autoConnectRetry = true)
And then use one of the MongoConnection apply methods that supports the MongoOptions argument.
If, like me, you are using Casbah from an Akka actor, you should also make sure your actor is restartable without leaking connections. I do this by calling close() on my MongoConnection in the actor postStop method.
Age
PS
Congratulations to Brendan for the new job at TypeSafe! I'm still patiently waiting for Casbah 2.5 ;)
On Nov 14, 2012, at 11:53, Iwein Fuld <iwein.f...@gmail.com> wrote:
> Kudos for posting back here. Please update the article (don't delete
> it), you're not the first to fall into this and people (like me :p)
> could really use the background.
> Iwein
> On Tue, Nov 13, 2012 at 8:22 PM, Alvin Alexander <devda...@gmail.com> wrote:
>> FWIW, I wrote the article at alvinalexander.com mentioned near the beginning
>> of this discussion. I just figured out what I was doing wrong, and posted a
>> small sample project at Github that shows how to insert objects into MongoDB
>> with Casbah without leaking connections:
>> There may be a better way to do this, but I want to use Casbah with
>> Scalatra, and using the MongoFactory and DAO approach in my Stock class
>> seems like what I want.
>> I just wanted to let you know that this was user error (me), and I'll update
>> or delete the article on alvinalexander.com tonight.
>> On Wednesday, October 24, 2012 6:49:49 AM UTC-6, Brendan W. McAdams wrote:
>>> Reading through the linked post, I still don't see leakage happening.
>>> Casbah provides you with a connection *POOL*, not an individual
>>> connection.
>>> calling close() shuts down the entire connection pool. This is the
>>> "leakage" you are observing: The connection pool opens a pool of
>>> connections, not an individual connection.
>>> This is incorrect usage, and you should be utilizing the pool. The
>>> Connection objects will be released back into the pool when unused and you
>>> don't need to close them manually.
>>> I will update the docs to clarify that.
>>> On Tuesday, 23 October 2012 13:52:15 UTC+3, iwein...@gmail.com wrote:
>>>> Is there a fix for the connection leaks that casbah is prone too? I've
>>>> written my own template, and so has at least one other:
I read on Mongo's site that they've release a change that allows writes to returns a status (especially an error) that wasn't present before.
They claimed to have support across the drivers.
Does this latest version of Casbah support this feature?
Writes always returned a status in casbah. See all write methods - they
return WriteResult and always have.
We simply changed the default. In previous releases you had to specifically
turn on "safe" writes.
In the new driver releases it is on by default *if you use the new
MongoClient class*. Casbah will eventually reflect this behavior.
On Nov 30, 2012 1:00 AM, "tigerfoot" <gzol...@gmail.com> wrote:
> I read on Mongo's site that they've release a change that allows writes to
> returns a status (especially an error) that wasn't present before.
> They claimed to have support across the drivers.
> Does this latest version of Casbah support this feature?
> Thanks for the fantastic code!
> On Friday, July 6, 2012 9:42:44 AM UTC-5, Brendan W. McAdams wrote:
>> Only one minor fix in this release, to correct an import issue from the
>> previous release.
>> Fixed QueryDSL imports for “default” (com.mongodb.casbah.Imports) import
>> so that bareword ops like $set and $inc are available.