Speeding up an ASP.Net Web Site or Application - asp.net

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

Related

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.

Yui files are too heavy and affect site's performance

I ve developed an asp.net web application with YUI as the javascript library... My site was very slow that it took three minutes to view my page on my first visit....
When inspected through firebug, My yui file was too heavy with size
278kb...
what can be done to improve performance?
278k is less than many images that appear on websites, and YUI is only as heavy as the component stack that you have requested. The common core package yahoo-dom-event.js is 37k (12k gzipped), so you are requesting at least a few other modules. That said, even across a slow connection, 278k should not cause a 3 minute delay. I suspect there is something else causing the performance issue.
There are many tactics for improving page performance. As MontyBongo suggests, use the Yahoo! CDN. If you are hosting the files yourself, make sure you have gzip enabled on your server. One benefit to using the CDN is the ability to use the Combo handler, which bundles all modules into a single script file. If self hosted, you should look into creating manual rollups of the files you are using to emulate this. Also, look into the YUI Loader to bring in module files asynchronously. http://developer.yahoo.com/yui/yuiloader/
Otherwise, look at http://developer.yahoo.com/performance/ and ask on yuilibrary.com/forum for advice. Please note that you should always supply some code for reference when asking for advice to improve it. Paste code snippets inline, link to larger snippets on http://pastie.org or http://gist.github.com, link to the page in question, or (best of all) link to a reduced page that illustrates in isolation the issue you want to address.
Try compressing the javascript with gzip, if possible use the Yahoo or Google CDN to deliver the files:
http://developer.yahoo.com/yui/articles/hosting/
Also try install YSlow, it can give you some good feedback on whats causing your page to load slowly, and provides some tips on optimizing the javascript delivery
http://developer.yahoo.com/yslow/
I agree that YUI is a bit too heavy for many sites.
In case it helps, you might want to have a look at my book for some ideas on how to make things run faster: Ultra-Fast ASP.NET: Build Ultra-Fast and Ultra-Scalable web sites using ASP.NET and SQL Server.

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

asp.net publish with whitespace removed

Obviously having whitespace in css, aspx and html pages is a great advantage at design time. But is there a way to (a tool that will) clear all the whitespace from all the files and possibly merge javascript and css files in a more optimal way.
I am using asp.net themes so there are quite a lot of separate css files that would be improved through some form of automated combining. I have seen a few http modules but that isn't quite what I want I just want to run something over the published project beofre sending it to the server.
EDIT: Compression at least in IIS is unfortunately not an option, we are currently running it on the same IIS server as a third party web based student management system. It doesn't like compression and the IIS options don't seem to be per application pool. I did apply asp.net compression but the bulk of my extra data seems to be the app_themes which I know would compress well I just don't want to have to manually go through compressing all the css separately.
An empirical study on the effect of removing white space from a not-untypical website (Drupal) showed minimal effects. (site also contains some links to non .net html white space removal tools)
I have gotten magical improvements in page size by aggressively managing viewstate size and using Blowery's http compression module.
Another strategy is to do minifiation (merging many css files into one). Telerik has such a component RadStyleSheetManager, it works only with style sheets embedded into assemblies.
There is another way
http://omari-o.blogspot.com/2009/09/aspnet-white-space-cleaning-with-no.html
I think one of the reasons that this was never included in .NET was because they expected you to turn on server compression in these scenarios. IMO I don't agree with this -- I think it's a shame that at least aspnet_compiler.exe can't do this optimization. It would be such a great performance boost on uncompressed connections. Anyway, you can enable compression on IIS 6:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx?mfr=true
And it's even easier and more flexible in IIS7 to do so. I hope someone has a better solution than I!
4 guys from Rolla just published an article on a http module that removes white space. You would need IIS 7 in integrated mode to make it work for css (or possibly IIS6 with wildcard mappings)
It looks more like a proof of concept, but the code is free.
i found this:
http://msdn.microsoft.com/en-us/library/aa719805(VS.71).aspx
greets!

ASP.NET compression

From an earlier post about trying to improve my sites performance I have been looking at HTTP compression. I have read about setting it up in IIS but it seems to be a global thing for all IIS application pools I may not be allowed to do this as there is another site running on it as well. I then saw some code to put in global.asax to achieve the same thing on a per website basis.
See Here http://www.stardeveloper.com/articles/display.html?article=2007110401&page=1]1
Is this as good as the setup in IIS? How dramatic is the effect? Any known issues?
If you move forward with this, I'd suggest implementing a HttpModule versus global.asax. The HttpModule allows you to disable compression with a config change versus rebuilding and allows you to monkey with your compression Assembly separate from your web app.
Rich Crane has a pretty nice 2.0 module here: http://www.codeplex.com/httpcompression/ if you want to get up and running fast.
The blowery project Steven Rogers mentioned is a HttpModule as well.
Otherwise, writing your own is pretty straightforward. A HttpModule gives you the same events as global.asax - BeginRequest, EndRequest, and finer grained events like PostReleaseRequestState and PreSendRequestHeaders which you may need to iron out all the wrinkles.
As far as IIS compression verus HttpModule, IIS is definitely easier since you don't have to fuss with yet another Assembly. I've used both methods with business apps and both perform about equally under load testing. If IIS is available, I'd say use it.
Between 60 and 80% compression for HTML, JS, CSS, and XML files is common with gzip. Keep in mind a lot of your payload may be images and multimedia objects which are much harder to compress.
http://blowery.org/httpcompress/
We've used this compression utility at my job for a while. Pretty good.
I think the Global.asax option will be a good if you are in a shared hosting environment for example, where you don't have access to IIS configuration.
IIS 6 provides basic compression support, but if you're already in IIS 7, it provides you great HTTP compression support, you can define which files get compressed based on their MIME type in your configuration files...
It achieves essentially the same thing as IIS compression - both end up sending the response with gzip compression. I've recently implemented this method, and it consistently reduces response size by 60% with no performance impact worth worrying about.
There are a few possible issues. Firstly, you need to be careful about output caching. You need to use a custom VaryBy to make sure that different versions are cached for requests with different Accept-Encoding headers. Otherwise, if the compressed version is cached then all users will receive it, whether or not their browser can accept it.
Secondly, GZipStream will sometimes truncate the last few characters from the response if you use Response.End or Response.Flush, because the stream isn't closed until too late. I'm not aware of any nice solution to this.
Finally, this will only compress your HTML. Any CSS or Javascript files will be served normally. You'd need to, for example, serve those files via a custom IHttpHandler to compress them.
There are issues with JavaScript and VBScript. The JavaScript problem has been confirmed in a comment by xxldaniel on a codinghorror article, and I had issues with VBScript (for M$ Office automation) using a JSON-like "Scripting.Dictionary" with "Microsoft.XMLHTTP" request.
You may try mod_gzip modules. It uses managed ZLib version and allows highly adjustable configuration. Syntax is compatible with the same named Apache module and even extended. So for example you could set different compression level for different mime types and so on.

Resources