Code Profiling ASP.NET MVC2 applications - c#

The thread here seems close:
Profiling ASP.NET websites with EQATEC Profiler
However, in the free version of Equatec I downloaded today there is no checkboxes for ASP.NET, and ordinary web. I have pointed the App path to my bin directory in my project folder as well as started up the localhost hosting for my application via Visual Studio.
I am open to other free tools as well. I am just looking for someway to profile the code as to optimize some reflection we are using.
I am using the professional edition so unfortunantly do not have access to MS Code Profiling.
I am looking to do performance profiling at this point.
Is the free version of Equatec capable of doing ASP.NET applications?
Is there a free profiler (I realize this has been asked before, and little seems to have surfaced but paid apps, but might as well ask)?
Is MVC a special thing to look for in a profiler?

Comprehensive profiling tools still seem to be quite expensive. I like the dotTrace family, but they're not free.
You haven't specified what kind of profiling you want to do. Are you trying to understand more about the memory usage of your application, or CPU usage?
There is nothing special about MVC applications when it comes to profiling. You will need a profiler that's capable of launching ASP.NET. Beyond that, MVC is just a regular bunch of class libraries.
Have you tried the free CLR Profiler? It handles ASP.NET and will show both memory and some method call activity. It's not as comprehensive as say dotTrace, but it is a great free alternative if you're starting out.

The guide is actually not out of date: the few steps described in the stackoverflow duplicate question (last edited April 8th) still describes best how you should profile ASP.NET apps. Note that you should look at the accepted answer, the one with currently 16 upvotes.
After you've build the instrumented app the important thing to note in the stackoverflow-answer above is step 3: "load your app". It means that you should cause your app to be loaded and is the only step the profiler can't do automatically for ASP.NET apps.
You typically load the app simply by navigating to it in a browser so you simply need to do that after the build-step. When your (instrumented) code is activated the profiling part of it will spring into life and connect to the profiler and then you can take snapshots.
Note that ASP.NET doesn't need a main entry point. That's just an added convenience for automatically taking snapshots for real executables that has a Main method.

You just need a .NET profiler.
Profiling WebForms, MVC, SharePoint, Sitecore, Ektron, Sitefinity, or any other product that runs on .NET doesn't change that.

Related

How to fine tune an asp.net application and find bottlenecks

How can I test performance of an asp.net mvc application and understand where exactly the bottlenecks are? I see some tools from redgate but to get the package is about $700. Are there any cheaper alternatives that may work? Or simple ways to really fine tune the application to maximize performance in a less expensive manner?
Thanks.
Sure. There is one stackoverflow created called MiniProfiler.
http://code.google.com/p/mvc-mini-profiler/
http://www.hanselman.com/blog/NuGetPackageOfTheWeek9ASPNETMiniProfilerFromStackExchangeRocksYourWorld.aspx
If you're using VS 2010 Ultimate you have access to some decent performance testing tools that are included. Many time bottlenecks only show themselves when the application is under load. The tools in VS let you correlate the load test with performance counters on the server hosting the app. This in combination with the MiniProfiler tool mentioned in another answer would be a good combo for finding bottlenecks.
http://msdn.microsoft.com/en-us/library/dd293540.aspx

Lightweight profiling for Silverlight?

I would like to profile certain actions in my application in a production environment.
I have previously used Stopwatch in .NET
It does not seem to exist in Silverlight (despite being in the documentation).
Can anyone suggest some alternatives? Is there anything better than DateTime.UtcNow?
I have used Yourkit and use ANTs in development, but I would like to gather information about performance of deployed software. I do not have access to the kind of data the users have, but can gather some logging.
Is this post any use at all?
It sounds like you want to deploy profiling IN your application so you can see how it performs on the user's PC?
Firstly you could have a look at this answer. Standard timers (eg looking at the value of DateTime.Now) are only going to give you rough resolution, which seems to be around 16ms at best.
Otherwise you can grab a performance profiling tool, there are several now which work out of the box with Silverlight, are easy enough to use and don't really take that long to get started with, with free evaluations. Two such tools JetBrains dotTrace and RedGate ANTS
Have you looked at this question: How to profile a silverlight application?
Are you looking for something other than this?
Telerik also has a pretty fantastic product for profiling named : JustTrace
JustTrace enables the profiling of local applications, running applications, Silverlight applications and local ASP .NET web site.

Asp.net Mvc site running out of memory

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.
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
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.
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)

C# Application Cache Block

I am looking for an efficient cache strategy for C#. I am constructing an MVC application however one of my queries targets a historical table with states, etc. Needless to say, the query is highly nested and complex, and I do not want to run it every time a person hits the site, so I decided to cache the data (either the results or the tables themselves). I dont want to store my cache in the Managed heap due to the stop-the-world garbage collection problem which is common with generational GC's and Caches. I was wondering, does the Cache Application Block (http://msdn.microsoft.com/en-us/library/ff650180.aspx) use Unmanaged memory (off the managed heap?). Is there a way to access memory directly via native IO? Any other cache tools worth looking into?
I highly suggest you look at AppFabric Caching. I just implemented for my MVC app and it worked great.
I used this blog to get started:
http://www.hanselman.com/blog/InstallingConfiguringAndUsingWindowsServerAppFabricAndTheVelocityMemoryCacheIn10Minutes.aspx
Let me know if you need some code samples.
.Net caching frameworks that I am aware of:
The built in ASP.Net System.Web.Caching (which can be used in non-web applications as long as you don't mind referencing System.Web)
NCache
The Microsoft Caching Application Block
Built in Systen.Runtime.Caching (.Net 4.0 only)
Windows Azure AppFabric Caching (How to: Configure ASP.NET to use Windows Azure AppFabric Caching)
Although I've looked into various caching frameworks I'm afraid I don't have very much experience with any of them except for System.Web.Caching - this works fine for our purposes.
You can as well explore the distributed caching options like Memcached or SharedCache. We had used SharedCache for one of our project and it worked well. As suggested in one of the answers you could also try AppFabric. If you are looking at Microsoft based solution then there is a distributed caching famework by Microsoft called Velocity.
Hope this helps.

Is there any way to profile performance of a WCF Application?

We're trying to measure performance of our system, which is a .NET 3.5 application that uses WCF calls.
Problem is until now, we weren't able to profile the methods inside these calls. A winforms client application was coded to test our system. We tried using ANTS 4 Profiler and VS2008 built-in Performance Analyzer, but we only got the total time of the WCF call. We would like to be able to measure all the calls that are being made inside of the WCF call.
Does anybody know if that's possible?
Thanks in advance.
There is quite a bit of performance testing functionality built into Visual Studio Team System Test Edition.
Take a look on this page and scroll down to the section Introduction to Load Tests.
Also this WCF Load Test application on codeplex might be helpful
So your application can run under VS, but WCF calls off to an environment where you cannot get profiling visibility, but you want to know what goes on in there?
Even if you find out how WCF uses time inside itself, any changes you make will have to be in your code. If you want to find out where in your code you can do something about performance, you can use the VS profiler. Personally, I just use stackshots, which are very effective at finding out what code to optimize under any environment, including C#.

Categories

Resources