Finding out what's slowing down ASP.NET pages - c#

I have a rather 'heavy' ASP.NET page, and currently the speed is fairly unacceptable - there is a lot of database communication, and displaying large grids. But I effectively want to find out what's actually causing the most slowdown, and working from there.
Are there any tools built into Visual Studio 2008, or any third party tools, that'll allow me to do this?

You could use ASP.Net Trace to figure out what is slowing down in the page.

Another good tool and easy to use, https://addons.mozilla.org/en-US/firefox/addon/yslow/
Not aimed directly at code, but is very helpful with resources

Have you heard about profiling?
My favorite tool is RedGate's Ants Performance Profiler.

An easy approach is using Stopwatch. Something like this:
void SlowMethod()
{
Stopwatch timer = new Stopwatch();
timer.Start();
//a lot of DB operations
timer.Stop();
//record timer.Elapsed
//restart the timer and check another piece of code
//at last find the bottle neck of the method
}

What Muhammad said - add tracing to your code to identify the slowest bits.
Also if you think db activity could be responsible, you could run SQL profiler to identify any long running queries - this will also help you correct indexes.

Some ideas:
Visual Studio Team System has a built in profiler. In VS 2010 this is available in premium and above.
Otherwise red-gate has a good profiler available. (for a fee).
Try using the tracing functionality built into asp.net.
Try using client side developer tools like Yslow and Page Speed or fiddler to see the requests for a page and their size and timings.
If you haven't already done so, make sure your server is serving gzipped content. This is an easy win.
Use SQL Server Profiler to profile your database requests.

There are many profiling tools available, I personally like ANTS Profiler, it is quite good. Check out the following link for more information on out to use it: ANTS Profiler
And here is a link to the ANTS Profiler download: 14 Day Free Trial
But if there is a lot of database communication, it is most likely the cause. Try minimizing the number of database calls and improving the performance of your database queries.
Also make good use of cacheing!

Related

Anyone know of a good C# code Profiler / Analizer to help optimize a webservice

I have a webservice that is in much need of some optimization. It's on an enterprise application the resides on a virtual server machine and is getting a huge bottle neck. I'm confident in my skills and being able to make this more efficient, but I was wondering if anyone out there has had a good experience with a profiler or optimization tool that would help point me to trouble spots.
The webservices main function is to generate PDFs which are created using Sql Reports and a third party PDF Writer utility. Basically it gets an ID and creates X number of PDFs based on number of Forms that are associated to that ID. So it has a loop which can run an average of 8 times / ID, and there are thousands of IDs sent daily. Needless to say there is always a back log of PDFs to be created, which the client would rather not see.
I have also thought about running multi-threads to asynchronously generate the PDF pages but I'm hesitant because they said they had issues with multi-threading on the "Virtual Server". So if anyone can point me to a good tutorial or advise about multi-threading on a Virtual Server I would appreciate that too.
Thanks for any help you can give.
I've used this one before and it's great:
JetBrains dotTrace
http://www.jetbrains.com/profiler/whatsnew/
Try Telerik's JustTrace, it has alot of neat stuff. It has 60 days free trial with support, so you can try it out first.
Fast Profiling
JustTrace aims to redefine fast memory and performance profiling. It adds minimal overhead to the profiled application, allows near seamless execution, and enables analysis-in-place, thus eliminating the need to move the application from its environment. The user can examine different stages of the application’s behavior by swiftly taking multiple snapshots throughout its lifetime.
Made-to-Measure Profiling
JustTrace offers three distinct profilers – Sampling, Memory and Tracing – to meet even the most demanding profiling requirements.
Profiling of Already Running Processes
JustTrace allows for unobtrusive attaching to live processes. Should an application start experiencing higher memory or CPU consumption, analysis on its state gives the opportunity to handle scenarios that are otherwise hard to reproduce.
Simple yet Intuitive UI
By definition, a memory and performance profiling tool should enable you to speed up the performance of your apps without slowing you down or getting into your way. JustTrace employs a minimalistic yet highly intuitive user interface that allows for easy navigation of the performance and memory results. A few effortless steps take you from choosing the application being profiled to an in-depth analysis of the profiling insights made by JustTrace. Memory and performance profiling has never been easier.
Live Profiling
JustTrace enables real-time monitoring of the application’s execution. The close-up watching of the application’s behavior brings out potential performance bottlenecks to the surface, and provides reliable hints of the application’s stages that are worth investigating.
Stand-alone Tool and Seamless Visual Studio Integration
JustTrace offers seamless integration with Visual Studio and can also be used as a stand-alone tool. The integration of JustTrace into Visual Studio’s UI removes a burdensome step by cutting the time needed to jump between the development environment and the tool to test the resulting memory and CPU utilization improvements. Simply modify the code, then run it through the Visual Studio UI and get JustTrace’s core capabilities in a single tool window.
Profiling of Multiple Application Types
JustTrace enables the profiling of local applications, running applications, Silverlight applications and local ASP .NET web site.
I would suggest taking a look at ANTS Memory & Performance Profiler from Red Gate:
ANTS Memory Profiler
ANTS Performance Profiler
The ANTS profilers do a fantastic job of identifying bottlenecks and memory leaks. They're not free, but they're very affordable and offer fully functional trials so you can evaluate the products.
There are other profilers:
ANTS: http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/
Which can also profile SQL calls. They also have an EAP open at the moment which gives you more functionality for database calls, that is here:
http://help.red-gate.com/help/ANTSPerformanceProfiler/download_eap.html
There is YourKit:
http://www.yourkit.com/
Visual Studio has a profiler too but not as good.

library/API recommendation for adding instrumentation in code

If I want to add some instrumentation in my code for getting metrics like how long a particular method took to execute, anyone has recommendation for either windows build-in or any 3rd party library?
I've seen this done with PostSharp AOP framework, hooked into Windows Performance Counters (System.Diagnostics.PerformanceCounter). One of their introductory pieces of sample code shows how to do this:
http://www.sharpcrafters.com/solutions/performance
This might be a good option if you want to deploy these measurements to production and measure performance in a live manner (to do diagnosis of a running system).
If you just want to locate bottlenecks in your code, and don't need to do live diagnosis, I suggest you simply use a profiler, such as the one built into VS or Ants Profiler (as Chris already suggested). Then run a redacted copy of your production data against your code so your performance measurements match production.
If you want this at runtime, you should probably use a profiler offline. I'd avoid doing any instrumentation where possible as it takes time and therefore causes more performance problems.
Google for RedGate ANTS Profiler or JetBrains dotTrace. If you have VS2010 Premium, it has one built in. That will give you a method-level breakdown of what is happening time-wise.
Generally a profiler will take care of measuring performance.
If you need to measure time yourself StopWatch with some sort of tracing is often enough.

Software for testing applications to increase performance

I'm searching for software to do benchmarking, analysis, performance of code and apps.
Something like Intel VTune.
Can anyone give me some names, free or payed, targeting c# apps.
thanks
Redgate Performance Profiler
...their Memory Profiler will undoubtedly help as well.
It sounds like you have multiple purposes.
If you want to monitor the performance health of programs, benchmarks and profilers that measure are probably what you want.
If you need to make a program faster, and you have the source code for it, I think your best bet is to get something that samples the call stack and gives you line-level percent of wall-clock time. For this, don't look for high precision of timing. Look instead for high precision of pinpointing code that is responsible for high percentages of time. Especially in larger programs, these lines are function or method calls that you can find a way to avoid. Don't fall into the myth of thinking that the only problems are hotspots where the program counter lives, and don't fall into the myth that all I/O is necessary I/O.
There's a totally manual method that a few people use and works very well.
Visual Studio, in it's higher SKUs, includes multiple profilers which can be used for this purpose. If your application is using multiple threads, VS 2010's new Concurrency Profiler is incredible for profiling C# concurrent code.
There are many other performance profilers on the market which are useful for performance profiling as well. I personally like dotTrace and think it's a very clean interface.
Such a tool is usually called a Profiler.
The (free) MS CLR Profiler (up to Fx 3.5) isn't bad, and a good place to start.
Update: a 2022 Blog about this.
I've used the EQATEC profiler which is free for personal use. It benchmarks run time and helped point out the inefficiencies that were causing bottlenecks in my code.

Performance and monitoring .NET Apps

We've build a Web Application which is performing horrible even with alot of resources available. My boss doesn't believe me that the application is consuming alot of Hardware IO, so I have to prove that the hardware is ok, but the web app is really crap.
The app is using:
SQL Server 2000 with SP4
The main web application (.NET 3.5)
Two Web Services (.NET 1.1)
Biztalk 2004
There are 30 people using this apps.
How can I prove I am right?
You can hook up a profiler like ANTS profiler or JetBrains DotTrace and see where the application's performance bottlenecks are.
One place you could start is getting a performance profiler like Red-Gate ANTS profiler. I've used this tool and it's very useful is weeding out performance bottlenecks.
Randy
You could start by using SQL Server Profiler to get an impression of the amount of database traffic that is going on.
I'm not saying that database interaction is the bottleneck, but it often is, and the tool is already there if you are using SQL Server, so it may be a good idea to take a look at that before you go out and buy a lot of profiling tools.
Visual Studio 2008 also have built-in performance analysis tools.
Windows performance counters are a good way to get some basic information about general system performance. Proper counters will show you if it's really the IO that's doing lots of stuff. If you take out the numbers from the counters and compare those to the specs, you should be able to tell if the system is maxing out or not.
If the system is maxing out, it's a problem with the web application, and it should be profiled to find out where to start optimizing.
You could use the system performance monitor built into windows since at least XP. You can get almost any information you could possibly need. This includes CPU time, .NET memory usage (include gen0 gen1 and gen2), native memory usage, amount of time spent garbage collection, disk access time, etc. If you just search codeproject or just the web there are many examples of using these counter to test for just about anything you want.
One of the benefits of this is you don't have to change your code and can be used with existing system.
I find this is the best starting point to point you to where you should look for bottle necks and issues.

C# runtime application Diagnostics

I am developing a c# GUI and was wondering if there were any (preferably free) runtime diagnostic programs available.
What Im looking for is a way to monitor user interactions with my GUI and what functions are called when. Preferably I do not want to add stacks of debug code as this has the potential to change the behaviour of the bug I am looking for.
Currently Im using Spy++ but am finding it a little heavy going as Im kinda new to this and its generating stacks of data.
EQATEC profiler is pretty simple to use. Free too. Started life targetting Compact Framework but since 2.00 is now geared more towards Desktop too.
I recommend ANTS profiler.
There is a trial available, first two weeks free.
In addition to ANTS profiler have a look at JetBrain's dotTrace

Categories