Connection pool problem

14 views
Skip to first unread message

Anders Fredriksson

unread,
Jun 10, 2010, 4:14:54 AM6/10/10
to NoRM mongodb
Hi,

I've implemented a new site in asp.net MVC2 using mongodb as the only
backend database and I'm having big issues with what I think is the
conneciton pool.

Right now the site is up at http://beta.arrivalguides.com and it has
really weird behaviour where it crashes every now and then, only to
recover with a simple reload.

I don't see these problems on my local site, but at the beta we have
about 1-5 simultaneous visitors.

I'm using the new projection-stuff that Andrew put in, and I'm also
using the Unit of work principle that Rob put in the TekPub project.

I'm also using StructureMap for DI and due to that all my controllers
has it's reference to the MongoSession. Before the Provider was set to
internal I was using that, but now I changed it to use the Mongo class
instead in my MongoSession class.

In my parent controller I dispose the mongosession in the
OnActionExecuted method. because before I did that I always got
connection to the connection pool timed out and I had to reset
mongodb.

I'm using the standard mongodb service install with no special
parameters and it's run on the same server as the website.

I think I'm doing something terribly wrong here but I can't quite
figure it out. If any of you has had any similar problems or know
where I should start to look.

At one point I got a system out of memory exception from the driver
but the system was actually not out of memory. really weird.

Please tell me I've made a noob mistake so that I can easily correct
it. :)

Best Regards,

//Anders Fredriksson

Andrew Theken

unread,
Jun 10, 2010, 7:07:46 AM6/10/10
to Anders Fredriksson, NoRM mongodb
Out of Memory exceptions can happen for all sorts of reasons, not always because the process is "Out of Memory" - fragmentation is one cause for these types of issues, but Karl has worked quite a bit on the driver to help avoid this..

Without seeing some code, I am not sure I can be very helpful. can you post the "MongoSession" code you're working from? Are you disposing each "Mongo" object that you create?

//Andrew Theken



--
You received this message because you are subscribed to the Google Groups "NoRM mongodb" group.
To post to this group, send email to norm-m...@googlegroups.com.
To unsubscribe from this group, send email to norm-mongodb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/norm-mongodb?hl=en.


Anders Fredriksson

unread,
Jun 10, 2010, 7:39:21 AM6/10/10
to NoRM mongodb
I finally managed to reproduce the problem and it turned out that I
was returning a non-evaluated query from my service.

The problem was reproduced by making two or more simultaneous requests
and it resulted in really weird problems where the session got shared
between threads and other concurrency problems.

That enumerable was then traversed in the view generating queries in a
loop. My session was already disposed but got picked up again when
evaluating the query.

First I solved the problem by disposing my session in
Application_EndRequest, since that is run after the views are
rendered. but that didn't seem right so then I find the service method
returning the unevaluated enumerable, and did a ToList() on it and now
I can once again dispose my connection in the OnActionExecuted method
in my parent controller.

The code in my session is was not the problem (as it is basically very
similar to the Session class in the NoRM Tests), but I think it would
be good for people doing the same "parent controller" thingy :) that
I've done to recognize this problem. Here's an example:

All my controllers are extending ArrivalguidesController

[Localization]
[HandleError]
public class ArrivalguidesController : Controller
{
protected readonly MongoSession _session;
protected DestinationMenu MainMenu;

public ArrivalguidesController(MongoSession session)
{
//the session class is instantiated using StructureMap
_session = session;
}

protected override void OnActionExecuted(ActionExecutedContext
filterContext)
{
if (ViewData.Model is MasterViewModel)
{
var cachedMainMenu = HttpRuntime.Cache.Get("MainMenu") as
DestinationMenu;
if(cachedMainMenu == null)
{
cachedMainMenu =
_session.All<DestinationMenu>().FirstOrDefault();
HttpRuntime.Cache["MainMenu"] = cachedMainMenu;
}

((MasterViewModel)ViewData.Model).MainMenu = MainMenu =
cachedMainMenu;


if(string.IsNullOrEmpty(((MasterViewModel)ViewData.Model).Language))
((MasterViewModel)ViewData.Model).Language =
CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
}
//disposing in the session
//Make sure not to have any unevaluated linq-expressions that would
be evaluated in the views or you'll be in trouble
_session.Dispose();
base.OnActionExecuted(filterContext);
}
}

So I hope this will help someone in a similar situation.

On Jun 10, 1:07 pm, Andrew Theken <athe...@gmail.com> wrote:
> Out of Memory exceptions can happen for all sorts of reasons, not always
> because the process is "Out of Memory" - fragmentation is one cause for
> these types of issues, but Karl has worked quite a bit on the driver to help
> avoid this..
>
> Without seeing some code, I am not sure I can be very helpful. can you post
> the "MongoSession" code you're working from? Are you disposing each "Mongo"
> object that you create?
>
> //Andrew Theken
>
> On Thu, Jun 10, 2010 at 4:14 AM, Anders Fredriksson <
>
>
>
> anders.fredriks...@visit.com> wrote:
> > Hi,
>
> > I've implemented a new site in asp.net MVC2 using mongodb as the only
> > backend database and I'm having big issues with what I think is the
> > conneciton pool.
>
> > Right now the site is up athttp://beta.arrivalguides.comand it has
> > norm-mongodb...@googlegroups.com<norm-mongodb%2Bunsubscribe@google groups.com>
> > .

karl

unread,
Jun 14, 2010, 2:30:18 PM6/14/10
to NoRM mongodb
In my experimental redis drivers, I've moved all the the connection
stuff inside the framework - removing the need for clients to have to
dispose of anything. it ends up cleaner, but can be slightly slower
for large batch processing.

I think its something we could do in Norm. It would simplify
consumption greatly.

Karl

On Jun 10, 7:39 am, Anders Fredriksson <anders.fredriks...@visit.com>
wrote:
> > > Right now the site is up athttp://beta.arrivalguides.comandit has
Reply all
Reply to author
Forward
0 new messages