Optimizing Performance of an ASP.Net Websites


Website performance has always been an important nonfunctional requirement for long. When a website does not load quickly, it affects visitors' behavior, which leads to decreases in sales conversions and revenue . I would be talking more about how we can improve performance of a website from asp.net perspective

Website performance has always been an important nonfunctional requirement for long. When a website does not load quickly, it affects visitors' behavior, which leads to decreases in sales conversions and revenue on the other hand a site with better performance directly translates with better user experience, repeated visits and hence increased revenues. It invariably provides edge over other competitors.

There could be numerous reasons for slow performance of a website including low server memory, competing resources or huge data inflow. If a web server is slow, it will hinder the website's performance. Likewise, a site receiving a great deal of traffic can also slow down load times or even disrupt a visitor's experience entirely.
There are lots of things we can do to optimize a website. First, you can run a web page analyzer to help you see what is actually being loaded and what is taking the most time — and clean up any problematic HTML, CSS and JavaScript code.

Two of the tools are Yslow which is a plugin for Firefox and other is PageSpeed provided by Google. These tools are very helpful in analyzing the reasons for slow performance of a website.

Website Performance is optimized over layers for example at hardware level, application level and the database level. I would be talking more about application level optimization and won't go into database level optimizations. Also would be listing some of the new features provided my visual studio framework 4.5

First let's walk through some of the things we should be doing to increase performance

Output caching
It is one of the very popular ways to increase the availability and responsiveness of your website. There are various levels it can be implemented. I will be discussing about server side output cache. There is an output cache directive at page level where we can set the duration and any dependency of cache. The prerequisite for running output cache is to disable set cookie header as part of response.

RAMMFAR (RunAllManagedModulesForAllRequests) to be turned Off

What it does is that this causes IIS and System.Web to have a handshake where IIS will run every single requests through asp.net pipeline even for requests for files like text file, images etc. RAMMFAR is primarily used to allow forms authentication to secure access to static files. If we want it to enable then we should move anonymously accessible static contents to another app pool.

Session State
Interesting thing about session state is that it is turned on by default. It has both pros and cons on one hand it adds into giving state to your resources so that user does not have to fill values on pages again and again. On the other hand these resources need to be stored somewhere. one of the interesting thing about session state is that session state requests needs to be serialized. If user is requesting for a same page from multiple tabs using a session resource each requests will be processed in entirety. The reason for that is asp.net does not want a shared resource to be changed by multiple requests at a time. Setting EnableSessionState to false at page level disables session at page level. We should be minimizing the use of session as much as possible.

App Suspension
This new feature is meant for hosters and it require windows server 2012 R2. What it does is that instead of terminating a idle worker process it suspends them. A suspended worker process remains alive but is paged out of disk reducing the system resources it consumes. When a user accesses the site again, the worker process wakes up from suspension and is quickly available.

Runtime caching (HttpRuntime.Cache)
This is the object cache In asp.net as opposed to output cache. The object cache is a way to say that this is an expensive piece of resource that I can always calculate but I want it to be stored in memory so that it can be pulled from there. Remove it only when you are low on memory. We can hook up dependency as well with it

Long running requests
We should be avoiding long running requests. asp.net 4.5 have been added with WebSockets and SignalR which takes lower per requests memory overhead than standard requests

ViewState
Avoid as much as possible using viewstate into pages as it increases the size of page.

Below are some other ways we should consider for optimizing site performance

-Avoid having one .aspx under one folder as it takes more processing time
-Consider precompilation to reduce startup time
-Avoid writes to files under c:\inetpub\wwwroot
-Remove empty methods is global.asax
-Use tracing,glimse,intellisense to find bottlenecks
-Use performance counters for diagnostics
-Consider enabling CDNs on scriptmanager
-Weigh 32bit vs 64 bit processes
-Don't be afraid to scale out


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: