Abel
Abel

Reputation: 57159

How to do non-invasive profiling of a running ASP.NET application?

Situation: ASP.NET live website that's occasionally too busy.

Adding full profiling to the code will be too heavy an impact on the performance. Using performance monitor, we've quickly find a saw-teeth figure in the "bytes in all heaps" counter, which pair with the GC counters. We consider certain pieces of code as being the culprit.

Is there a way or possibility to temporarily "inject" profiling, either for certain pages, libs, functions or whatever? Preferably as lightweight as possible, as any additional overhead might bring down this fragile system. I'm aware that .NET does not support method callback hooks (as is common with AOP).

Upvotes: 2

Views: 1083

Answers (4)

RickNZ
RickNZ

Reputation: 18654

A few ideas:

  1. Use custom Windows performance counters. They are very lightweight (1 to 2%), and you can use them not just to count, but also for timing measurements, to look at how often certain operations are slower than a threshold, etc.
  2. If you're using IIS 7, you can enable Failed Request Tracing. To limit the perf impact, be careful to not enable it for too many pages. Those traces can provide lots of detail, and you can inject more info into them programmatically if you need to.
  3. Use the Windows Event log to write custom details under exceptional conditions. Perf impact is minimal as long as you don't over-do it.
  4. One cause of sawtooth memory behavior can be not calling Dispose() when you should (or wrapping IDisposable objects in using statements, which will call it for you); you might want to review your code to look for that.

In case it's helpful, you might also be interested in the performance tips from my book: Ultra-Fast ASP.NET.

Edit: you might also try using .NET Memory Profiler (free trial available) to attach to the running process. It's fairly invasive compared to counters, but if you need to capture a snapshot of the current state of memory to debug your problem, there may not be a better choice.

Upvotes: 2

arielf
arielf

Reputation: 5952

I recently posted a possible solution to a similar challenge:

Profiling a multi-tiered, distributed, web application (server side) shows a high level approach (profiling on the URL level) that is:

  • platform and language independent
  • completely non invasive
  • gives a high-level picture of where your application is spending most of its time

The idea is to use existing web logs and convert them into a "one-picture is worth a 1000 words" kind of chart.

This approach is not sufficient for use-cases requiring more fine-level detail, but it helped me personally, and may be worth exploring in your case.

Upvotes: 1

Mike Dunlavey
Mike Dunlavey

Reputation: 40659

Can you do this on ASP .NET? It's a good quick way to find out what's going on.

Upvotes: 0

Tom Ritter
Tom Ritter

Reputation: 101330

Yes, you can take a memory dump of the application as it's running and see what it's holding in memory. This should reinforce or deny your assumptions.

Upvotes: 1

Related Questions