tracking down slow performance of an ASP.NET web page - asp.net

I want to find out the reason for slow performance of some web pages of an ASP.NET intranet website. the reasons could be many like large view state, number of round trips to the server and database, inefficient code in UI/middle tier etc. most of these slow pages are complex web pages with some third party controls, user controls.
what is the quickest way to find out what is causing the page to slow down without debugging each and every interaction on the web page and stepping through lines of code. will the code profilers like ANTS be of any help? or are there any better ways? there could be many factors for slow performance of a page, but I want to fix them in priority order.
thanks,
Rama

You can use a firefox addon named yslow whcih analyzes web pages based on Yahoo's performance rules.
If you want to check code performance then you can use a profiling tool.
For SQL there is SQL Server Profiler.
For .Net you can use ANTS Performance Profiler

Use Fiddler or HTTPWatch to profile the web application, this works with IE too..
And
I just came across a interesting post by john resig - deep tracing IE about the new client side profiler tool for IE. It is awsome & Its free.
You can get it here

If your web application is creating trace files then stop the web site, delete all archive trace files and restart the web site. It helped me to resolve the issue.

Try FastSQLDataSource. It helps when you need faster display of large amounts of data in your web application using grids, lists and other bound controls.
http://www.nitrosbase.net
It can work almost without coding or sometimes with no coding at all.

Some addtions:
Search for unproper Exception handling / throwing etc.
Search for left debugging code - one System.Diagnostics.Debug.WriteIf in a large loop or dataset is devastating
search for multiple databinding - broken page life cycle
search for code smell - the shit smells before hitting the fan ...

Related

Page loading issue in asp.net mvc3

My website has a lot of menus and submenus in its index page and these submenus are loaded from the db.Ajax is used to load the submenus. So its taking a lot of time to load the full page. How will i reduce the loading time.I am using asp.net mvc3 and sql server 2008 database
It's very hard to tell what could be the bottleneck in your solution without actually seeing it, but it sounds that you can benefit greatly by doing caching, in ASP.NET MVC it's quite easy to do, here is another great tutorial on the subject. Oh and remember -> “There are 2 hard problems in computer science: caching, naming, and off-by-1 errors” ;)
There are many things that could be going wrong and causing your application to run slowly.
I’d recommend you turn the trace feature on because that will tell you what may be wrong. As Dimitar Dimitrov already mentioned you can try to cache the query in some way so you don’t have to retrieve it every time.
Another option would be to optimize the query so that it fetches all menus and submenus in one query.
But again, don’t do anything specifically until you’ve profiled your application to see where specifically is the issue.

How to make asp.net web forms application faster?

My last project is a medium size asp.net web forms application. It is built using:
asp.net 3.5
ling to sql dbml --> sql server database (9 tables)
ext.net 1.6 (www.ext.net)
structuremap 2.5.3.0
This time I believed I did my best in terms of architectural design, code and data transfer optimizations. I followed all advice I could to work with the database efficiently through linq to sql and I built layers (model, repository, service, presentation) to separate concerns and lightweight the code in the aspx code behind files.
The problem is: I've installed the application in various web hosting servers with the same pitiful result: the application is struggling to work... pages are loading like in slow motion...
In the past I would say 'OK, I didn't do all I could to speed things up' but in this case I really tried to apply the best practices...
Is there anything else I can do about it? Or is it just asp.net for really small projects only?
thank you.
ASP.NET is fine for building large scale websites. As Brad mentioned, StackExchange sites are built using it, and StackOverflow is a very busy site indeed.
What you need to do first is measure performance; until you do that, you're just guessing at where the problem areas are.
So start with the browser - use a tool such as Firebug, or YSLOW, Google Chrome dev tools, whatever takes your fancy and run your site using the tool enabled. The tools can let you know how long things are taking to process eg requests, how long content is taking to download etc.
YSLOW will also give you some tips on anything it finds as being a bit slow e.g. you're making to many HTTP requests, you should consider minifying your CSS/JS files. You will get a general overview of how the site is performing and where problems could be.
To dig a bit deeper, use a tool like RedGate's ANTS Profiler, use the trial version and measure your website, and server side code, with that tool. There are other tools, though I'm not aware of any free ones.
My first question is that when its slow. Did you try your project in Local area network. Please check first there. If there slow then you need to improve little bit.
This slow performance depends on many things
such as large data load, multiple logic on one page etc.
Please let me know.
Thanks
Basit.

What is the best tips to improve the Application Performance in Asp.Net?

Can any help regarding the performance improvement in Asp.Net?The best practise tips for asp.net performance improvement?
This is a very broad question to answer because the Performance of an ASP.Net application is not only bound to page processing or bandwidth usage but also in the code and Algorithms you have written. If you use data source then the Performance of the Queries and ADo.Net. The Basic thing you might be asking is to improve page processing by Caching, etc..
Have a look here for a detailed description of Best Patterns and Practice (Though its old ..published in 2004 but still helps).
http://msdn.microsoft.com/en-us/library/ff647215.aspx
Or better consider this (For .Net4) . It list all performance related Documentation
http://msdn.microsoft.com/en-us/library/cc668225.aspx
Update
If you are looking for specific stuff slowing your page load
Use firebug's Net panel and monitor which resource is taking more time. Or as suggested by another answer use Tracing to check this out.
What is the best drug to get healthier? It all depends on what is your health problem. The same thing is with ASP.NET performance. First, find what is your bottleneck, a single most slow down factor. Then fix it, retest performance and, if more speed is necessary, go to the previous step.
How to find a bottleneck? If you really have no clue where to start, then start from analyzing your waterfall diagram. To create one from your client, use Fiddler or Firebug. To create it from different Internet geographies use WebPagetest. The waterfall will show whether the bottleneck is on the server or network, and also whether it is caused by main ASPX page or by resources (scripts, images, CSS). If the server and network are fast enough, then check slowness in the browser using Firebug or dynaTrace Ajax edition that can trace DOMContentLoaded/load events in browser. If the bottleneck is on the server, find out whether it is the database or application. Use database profiler and .NET profiler, for example from this question.
How to fix bottlenecks? Check this Microsoft resource, but there are many others for each type of bottlenecks.
If you add the “performance“ tag to your question you may get more answers.
Set trace="true" in the page directive. Reload the page and look for any obvious delays in the page life-cycle event handlers, particularly where you are accessing a database.
Also, use the Firefox Web Developer toolbar to obtain a friendly overview of the image file sizes and other static file sizes, CSS, JS, etc.
There are lots of questions and answers on ASP.NET performance here on Stackoverflow. Here's one of my previous answers and a quick search on the ASP.NET and Performance tags yields plenty of results.
What problems are you facing exactly?

ViewState and Web Load Testing

I'm trying to do load testing against an ASP.NET web site and I need to be able to parametertise field value of a page to test different code paths.
I had great success with JMeter when load testing a JSP web site before. However, because ASP.NET encodes all form values in the ViewState, changing control values does not really work.
I Googled this problem and people said the web testing tool in Visual Studio Team Tester Edition works well with ASP.NET pages. However, it cost quite a bit so I am just wondering does anyone know how to get around the ViewState issue with JMeter or WAPT?
I've used WebLoad before. Its scripting language is basically JS, so you may be able to find controls on the page using JS and invoke them as part of your load script.
WebLoad is free.
I've figured out how to do this, basically you cannot simply record a static script with JMeter. What you need to do is to record a request, send it, capture the viewstate in the response and send the viewstate back in next request.
If you need more details, I've documented how to do this along with some screenshots on my blog post
As webapps get more complex (ViewState, AJAX, etc) it is tougher and tougher to use traditional load testing tools. That's because they try to jam a ton of virtual users on a very small amount of hardware resources.
My company, BrowserMob, took a different approach. We build a load testing service that uses real web browsers to drive load. Your scripts end up being essentially functional tests (specifically Selenium scripts). My background has been in Selenium for some time (I created Selenium RC and founded OpenQA.org), so as soon as cloud computing made it possible to rent the 5TB+ of RAM necessary to do this, I jumped on the idea :)

Speeding up an ASP.Net Web Site or Application

I have an Ajax.Net enabled ASP.Net 2.0 web site. Hosting for both the site and the database are out of my control as is the database's schema. In testing on hardware I do control the site performs well however on the client's hardware, there are noticeable delays when reloading or changing pages.
What I would like to do is make my application as compact and speedy as possible when I deliver it. One idea is to set expiration dates for all of the site's static resources so they aren't recalled on page loads. By resources I mean images, linked style sheets and JavaScript source files. Is there an easy way to do this?
What other ways are there to optimize a .Net web site?
UPDATE:
I've run YSlow on the site and the areas where I am getting hit the hardest are in the number of JavaScript and Style Sheets being loaded (23 JS files and 5 style sheets). All but one (the main style sheet) has been inserted by Ajax.net and Asp. Why so many?
Script Combining in .net 3.5 SP1
Best Practices for fast websites
HTTP Compression (gzip)
Compress JS / CSS (different than http compression, minify javascript)
YUI Compressor
.NET YUI Compressor
My best advice is to check out the YUI content. They have some great articles that talk about things like CSS sprites and have some nice javascript libraries to help reduce the number of requests the browser is making.
If you are using Firefox to test your website, you might want to try a nifty Firefox extension from Yahoo! called YSlow.
It analyzes your web pages and provides grades from A-F (A being the Best and F being the worst) for each of the best practices, for high performance websites. It will help you to track down the elements of your website which you could optimize to gain speedups.
UPDATE
Now YSlow extension is compatible with all modern browsers such as Firefox, Chrome, Opera, Safari and others, read more here.
Turn viewstate off by default, it will be a night and day difference on even the most simple pages.
I wrote a blog post about improving ASP.NET page performance this a couple months back. Here are some quick & easy ways -
Turn off view state
Turn off event validation
Implement HTTP gzip/deflate compression to reduce the response size (number of bytes the server has to send back to the client)
Try to optimize/minimize your database calls for each request
I think you really need to be able to get some actual PerfMon data/telemetry from the app whilst running in production to be able to make an enlightened decision about what to optimise.
As a throw away tip I'd make sure your app is deployed as a Release build and set debug="false" in the 'compilation' section of your web.config.
You seem to be starting by assuming that your problem is download size - that may not necessarily be the case. You should do some experimentation with your ASP.NET site to determine if there are areas in your code which are causing undue delays. If it turns out that download size is not your problem, you'll need to find ways to cache your results (look into output caching, which is an ASP.NET feature) or optimize your code.
In any case - the first step when looking at a performance issue is always to verify your assumptions first, then decide on a course of action.
Have you tried these tips?
http://weblogs.asp.net/haroonwaheed/archive/2008/06/30/ASP.NET-Performance-Tips.aspx
You could start looking at caching strategies. Static files like CSS (even compressed ones) and images (even optimized ones) should only need to be downloaded once by the browser for a period of time.
Scirpt combining for AJAX has already been mentioned, but I didn't notice reference to the ScriptReferenceProfiler MS has released on codeplex to help figure out what to combine. Mike Ormond has a good start point on this.
Another tip if you're doing a lot of INSERTs to your database is to double check your server's disk caching is switched on. Case in point, I had an data importer doing 1.2 million inserts during a run. Took 4 hours and change without caching on. Took 16 minutes with it on.
A general thing when using ASP.NET and Ajax (any Ajax library) together is to avoid elephanting your Page_Load and Page_Init (and their method counterparts) things since these will be executing on every Ajax Request.
When that is said I would seriously ditch ASP.NET AJAX and use anything else...
Anthem.NET, AjaxPRO.NET, jQuery or whatever else than ASP.NET AJAX...
Of course I would use Ra-Ajax myself since that's my project. But then again I am biased...
You could turn on compression based on your client supporting it. See this article: link text
Static resources shouldn't be resent unless changed. IIS will send a response code which tells the browser to use the cached version.
You could also look at ASP.NET output caching, which can be applied fairly granularly to different portions of your page:
http://msdn.microsoft.com/en-us/library/xsbfdd8c(VS.71).aspx

Resources