2

I have a weird scenario in which the website seems to randomly run out of memory from time to time: it works for weeks then suddenly everything throws an out of memory exception, and it stays so until the server is rebooted. It may happen after weeks or after days. We weren't able to identify a regular pattern.

Here a list of tech stuff used for this site:

  • Net framework 3.5
  • Mvc 2.0 with C#
  • IIS 6.0 on a dedicated server (no policy restrictions, etc)
  • 3 layer architecture (ui - bll - dal)
  • Automapper 1.1.0.118
  • Elmah 1.1
  • FluentValidation 2.0
  • MvcContrib 2.0.95.0
  • MvcSiteMapProvider 3.0.0.1
  • Castle 2.5.2
  • NHibernate 3.0.0.4
  • FluentNHibernate 1.1.0.0
  • PdfSharp 1.31.1789.0
  • MarkdownSharp

Other than this, the site includes (via iframes) some old legacy asp forms. Those forms are the same that were on the old version of the site (which was entirely in asp), they have some problems but the old site never ran out of memory.

I've already checked common stuff, like all IDisposable implementing classes are inside using statements, no infinite loops, etc.

The site doesn't do anything strange, it pulls some data from the DB like news, generates some pdf on the fly after certain form submissions, allows users to subscribe to a newsletter. The usual stuff.

I'm really clueless, I've developed many sites, used the mentioned libraries almost everywhere, but this is the first time I experience this kind of problem.

I know this information isn't enough to "find" the problem, but if anyone can think of something I might have overlooked, or anything, it will be very welcome :)

EDIT: A detail that might be important. We have another website running on the same server (made with old asp) and it runs just fine, while the other is stuck. So it seems like the overall server memory isn't depleted, otherwise it wouldn't work too.

7
  • If you look at the memory consumption of the site does it increase over time in general or is it stable apart form these odd spikes? Commented Jul 20, 2011 at 8:28
  • It's normal. Now the application pool was at 1gb, after restarting the pool I was able to access elmah and I found a lot of outofmemoryexceptions. Still clueless. Commented Jul 20, 2011 at 8:39
  • Does your site have to ability to upload files? I could be the server is just totally overloaded with too many users uploading files at the same time? Commented Jul 20, 2011 at 8:41
  • No file upload functionality on the site. The most exotic thing is pdf generation using PdfSharp Commented Jul 20, 2011 at 8:44
  • is the asp.net process bloating or is it some other process? are you using InProc sessionstate mode? are you placing data in the session? what is the time limit for sessions? Commented Jul 20, 2011 at 9:17

3 Answers 3

3

Install DebugDiag. Trigger it to take dumps of the process as it breaches memory thresholds (say at 300Mb and then at every 100Mb after that).

Comparing the dump files should give you a clue as to what is suddenly occupying all that memory

Sign up to request clarification or add additional context in comments.

3 Comments

It would be a nice option, but I can't install anything on the server, it's a dedicated hosting, not housing.
Is there any way to run the site in house and reproduce the behavior maybe with a load testing tool?
0

I would have a look at how Castle is configured and used, do you use castle to resolve your controller dependencies, using the ControllerBuilder.Current.SetControllerFactory method? If you do, you also have to remember to release the controller instances.

3 Comments

I'm not using Castle to set the controller factory. In fact, now that I'm looking, it's not used at all right now. It was once used for Windsor - IoC but right now it's not used anymore. A dead dependency.
Okay, then you should have a look at the dump files as described by Richard. In the meanwhile look for places where you declare something static(eg. collections), this is a good candidate for leaks
I'll check for anything static in the code, that's a good advice. I don't remember making use of static variables and such, but better be safe than sorry.
0

If your hosting multi application pool on IIS7/7.5 and high load, try change gc mode.

aspnet.config

[ Element](http://msdn.microsoft.com/en-us/library/ms229357.aspx Element)

2 Comments

Sorry! but I think this is available parameter for memory usage on IIS6.
Anyway, I don't think it's a GC issue for the following reason: the advantage of managed languages is that if you handle your memory in a bad manner, when it's running out of resources GC comes to the rescue. I experimented with flawed code, generating endless loop that will result in OOM exceptions. But the next call, GC would pass and clear things up. In this case, the app pool remains in that status until it is restarted. So I am thinking that it's some unmanaged code that is causing the leak, as GC can't handle unmanaged code. Does it sound right or I'm oversimplifing things?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.