Software Architecture – Web Application optimization without code changes

November 11, 2011

Objective: Web Application optimization without code changes.
Strategy: Read all the references below and apply them in test lab. After clear understanding of domain, have access to Client machine and apply this checklist on client machine. Make sure to have backup strategy for client environment.
Guideline Points:
1. Log only essential information or completely disable IIS logging
2. Disable IIS ASP debugging in production environments
3. Tune the value of the ASP Threads Per Processor Limit property
4. Tune the value of the ASP Queue Length property
5. Tune the MaxPoolThreads registry entry
6. Disable WCF services tracing
7. Configure ASP.NET MaxConcurrentRequests for IIS 7.0 Integrated mode
8. Enable IIS HTTP compression
For point 1-8 see below reference)
(Reference: http://msdn.microsoft.com/en-us/library/ee377050(v=bts.10).aspx )

9. Configuring HTTP Compression in IIS 7
(Reference: http://technet.microsoft.com/en-us/library/cc771003(WS.10).aspx )

10. Configuring Output Caching in IIS 7
(Reference: http://technet.microsoft.com/en-us/library/cc732475(WS.10).aspx )

11. Follow this link:
http://learn.iis.net/page.aspx/93/optimizing-performance/

12. For web Pages add following tag.

Reference: http://msdn.microsoft.com/en-us/library/h30h475z(v=VS.100).aspx

13. Optimizing WCF Web Service Performance
http://msdn.microsoft.com/en-us/library/ee377061(v=bts.10).aspx

14. Few tips related to ASP .Net
http://madskristensen.net/post/Performance-tuning-tricks-for-ASPNET-and-IIS-7-part-1.aspx
http://madskristensen.net/post/Performance-tuning-tricks-for-ASPNET-and-IIS-7-e28093-part-2.aspx

15. Few tips related to ASP .Net
http://wiki.asp.net/page.aspx/31/performance/

16. For better performance, you should remove any HTTP Modules that you are not using.
Reference: http://aspadvice.com/blogs/ssmith/archive/2007/08/03/Real-World-ASP.NET-Performance-Tuning-Experience.aspx

17. Performance Tuning for Active Directory Servers (Important)
http://msdn.microsoft.com/en-us/windows/hardware/gg463394
[In this white paper, read Active Directory section.]

18. AD performance Tuning
http://blogs.technet.com/b/exchange/archive/2010/02/03/3409281.aspx
http://www.markwilson.co.uk/blog/2006/04/maximising-active-directory-performance.htm
http://technet.microsoft.com/en-us/library/bb123771(EXCHG.65).aspx


Software Architecture-Strategy for Performance tuning a .Net application

September 10, 2011

Strategy for Performance tuning a .Net application:
There are two parts to work in terms of performance tuning.
First part, is application specific optimization which refer to things required in terms of product under development. It requires deep product knowledge and code level awareness of product.
Second part, is technology specific optimization which refer to things provide by technology as tip to improve the performance.
For second part, following is list of acts to be taken.

1. Allocate a senior resource to act as PIG in SCRUM theory for this task.
2. Analyze the technologies used in application like c#, .Net, ASP .Net, WCF, MVC, IIS. Identify set of checklist which needs attention to be verified in application.
3. First step would be to review code in application. Second step would be to apply the checklist identified in step 2.
4. Bench mark the effect of each change in application (checklist) to analyze the performance.
5. QA team member can really help in it.

Online References for implementing checklist:

C# Performance:
Microsoft:
http://msdn.microsoft.com/en-us/magazine/cc500561.aspx
http://msdn.microsoft.com/en-us/library/ff647813.aspx
http://msdn.microsoft.com/en-us/library/ms973839.aspx
http://msdn.microsoft.com/en-us/library/ms973839
http://msdn.microsoft.com/en-us/library/ms973852
http://msdn.microsoft.com/en-us/magazine/cc163510.aspx
http://msdn.microsoft.com/library/ms973837.aspx
http://msdn.microsoft.com/library/ms973858.aspx

Others:
http://www.techgalaxy.net/Docs/Dev/5ways.htm
http://www.codeproject.com/KB/cs/effective1.aspx

Blogs:
http://blogs.msdn.com/b/ricom/

ASP .Net Performance:
http://msdn.microsoft.com/en-us/magazine/cc163854.aspx
http://msdn.microsoft.com/en-us/library/ff647787.aspx
http://www.codeproject.com/KB/aspnet/10ASPNetPerformance.aspx
http://www.realsoftwaredevelopment.com/20-tips-to-improve-aspnet-application-performance/
http://wiki.asp.net/page.aspx/31/performance/

WCF Performance:
http://support.microsoft.com/kb/982897
http://msdn.microsoft.com/en-us/library/ee377061(v=bts.10).aspx
http://msdn.microsoft.com/en-us/library/ms735098.aspx

Blogs:
http://www.askives.com/wcf-performance.html
http://blog.thekieners.com/2010/05/04/optimize-data-contracts-for-better-wcf-performance/
http://merill.net/2008/10/wcf-performance-optimization-tips/
http://weblogs.asp.net/sweinstein/archive/2009/01/03/creating-high-performance-wcf-services.aspx
http://metallemon.hubpages.com/hub/WCF-Service-Performance
http://www.aspnet101.com/2010/08/wcf-performance-best-practices/
http://blogs.msdn.com/b/stcheng/archive/2011/01/05/wcf-wcf-performance-testing-information-share.aspx
http://webservices20.blogspot.com/2009/01/wcf-performance-gearing-up-your-service.html
http://blogs.msdn.com/b/wenlong/archive/2007/10/27/performance-improvement-of-wcf-client-proxy-creation-and-best-practices.aspx

MVC Performance:
http://www.codeproject.com/KB/aspnet/How_to_improve_performanc.aspx
http://weblogs.asp.net/gunnarpeipman/archive/2010/02/07/asp-net-mvc-performance-ii-optimizing-resources.aspx
http://www.slideshare.net/rudib/aspnet-mvc-performance
http://msmvps.com/blogs/kenlin/archive/2010/05/14/mvc-performance-in-iis-part-ii.aspx
http://blogs.msdn.com/b/marcinon/archive/2011/02/07/mvc-performance-tips.aspx


Software Architecture-Page Methods of ASP .Net/AjAX with DataTable control-Yahoo UI library

February 16, 2011

Objective:To use Page Methods of ASP .Net/AjAX with Yahoo UI library.

Explanation:
There are three approaches to Programming in ASP.NET AJAX.
1. UpdatePanel: Contains a group of server controls and monitors their postbacks and rendering process. Any requests for postback that originate from the contained controls are hijacked and served via script. Changes to the page are applied using DHTML.
2. Remote method calls: Blanket term for asynchronous calls to page methods and local and external Web services. Calls move input arguments and receive return values via JSON streams in a type-independent manner. Strongly typed JavaScript code is required to trigger the call and apply changes back on the client.
3. Client-side data binding: Two client-side controls written entirely in AJAX JavaScript to implement template-based binding. They are ListView, for multiple-records view, and ItemView, for single-record view. These two controls are combined together with client data source and filtering components.
In this Post, we will use Page Methods with Yahoo UI Library.
Page Method is a public static method defined in the codebehind class and decorated with the same WebMethod attribute used for Web service methods.
Yahoo UI Lib is really power full client side UI library.
For details about it, please visit at:
http://developer.yahoo.com/yui/For details about DataTable control, visit:
http://developer.yahoo.com/yui/datatable/
DataTable control major features includes sortable columns, pagination, scrolling, row selection, resizeable columns, and inline cell editing.
Steps:
1. Consider a entity class for showing History Items:

// Sample Object to be returned to client end via Page Method.
    public class HistoryItem{
        public Int32 ID { get; set; }
        public String Name { get; set;}
        public String Desc { get; set; }
        public DateTime Date { get; set;}
    }

2. Define a Page Method as below:

/// <summary>
        ///  Page Method for client side data return
        /// </summary>
        /// <returns> List of HistoryItem object to be returned... </returns>
        [System.Web.Services.WebMethod]
        public static List<HistoryItem> GetPageMethod()
        {
            // Prepare Sample Data
            List<HistoryItem> lst = new List<HistoryItem>
                        { 
                        new HistoryItem { ID = 1, Name = "Created 1" , Desc= "Description 1......Description.....Description....." , Date =  DateTime.Now} ,  new HistoryItem { ID=2 , Desc= "Description 2......Description.....Description.....", Date =  DateTime.Now , Name = "Updated 2" } ,
                        new HistoryItem { ID = 3, Name = "Created 3"  , Desc= "Description 3......Description.....Description.....",Date =  DateTime.Now} ,  new HistoryItem { ID=4 , Desc= "Description 4......Description.....Description.....", Date =  DateTime.Now , Name = "Updated 4 " } ,
                        new HistoryItem { ID = 5, Name = "Created 5"  , Desc= "Description 5......Description.....Description.....",Date =  DateTime.Now} ,  new HistoryItem { ID=6 , Desc= "Description 6......Description.....Description.....", Date =  DateTime.Now , Name = "Updated 6" },
                        new HistoryItem { ID = 7, Name = "Created 7" , Desc= "Description 7......Description.....Description....." , Date =  DateTime.Now} ,  new HistoryItem { ID=8 , Desc= "Description 8......Description.....Description.....", Date =  DateTime.Now , Name = "Updated 8" } ,
                        new HistoryItem { ID = 9, Name = "Created 9"  , Desc= "Description 9......Description.....Description.....",Date =  DateTime.Now} ,  new HistoryItem { ID=10 , Desc= "Description 10......Description.....Description.....", Date =  DateTime.Now , Name = "Updated 10 " }                         
                        };
            // Return Sample Data
            return lst;
        }

3. In ASP .Net page define some includes related to Yahoo UI Library as:

<!--CSS file (default YUI Sam Skin) -->
<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.8.2r1/build/datatable/assets/skins/sam/datatable.css">
 
<!-- Dependencies -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="http://yui.yahooapis.com/2.8.2r1/build/element/element-min.js"></script>
<script src="http://yui.yahooapis.com/2.8.2r1/build/datasource/datasource-min.js"></script>
 
<!-- OPTIONAL: JSON Utility (for DataSource) -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/json/json-min.js"></script>
 
<!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/connection/connection-min.js"></script>
 
<!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/get/get-min.js"></script>
 
<!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/dragdrop/dragdrop-min.js"></script>
 
<!-- OPTIONAL: Calendar (enables calendar editors) -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/calendar/calendar-min.js"></script>
 
<!-- Source files -->
<script src="http://yui.yahooapis.com/2.8.2r1/build/datatable/datatable-min.js"></script>

4. Define some ASP .Net tags as:

    <asp:ScriptManager ID="ScriptManager1" runat="server"   
      EnablePageMethods="True">
</asp:ScriptManager>
    <input id="Button1" type="button" value="Get History data........." onclick='return getData();' /><br /><br />
    <div id="myContainer"></div>

5. Call to Page Method is done via Javascript as below:

<script language="javascript" >
    function getData() {        
        PageMethods.GetPageMethod(onSucceed, onError);
        return false;
    }
    function onSucceed(result) {            
    
       // DataSource for a JavaScript function that returns data
        var dsLocalArray = new YAHOO.util.LocalDataSource(result);
        
       // DataTable columns defination
        var myColumnDefs = [{ key: "ID", label: "ID" }, { key: "Name", label: "Name" }, { key: "Desc", label: "Desc" }, { key: "Date", label: "Date"}];
       
       // DataTable constructor syntax
        var myDataTable = new YAHOO.widget.DataTable("myContainer", myColumnDefs, dsLocalArray, { sortedBy: { colKey: "Name", dir: "desc" }, rowSingleSelect: true });               
    }
    function onError(result) {
        // Perform Error handling logic here.....
        alert('There is some thing wrong, Check again  .......');
    }

So we are done with sample for fetching data via Javascript via Page methods.

The output will look like as:

Sample code can be downloaded from here. Rename file to pagemethodapp.zip, then extract to get code files
Reference:
http://msdn.microsoft.com/en-us/magazine/cc163480.aspx


Software Architecture – ASP .Net 4.0 -For data bound control – EnablePersistedSelection

November 27, 2010

While exploring ASP .Net 4.0,I discovered that Microsoft has introduced a new property in ASP .Net 4.0 for data bound control like GridView,ListView named as EnablePersistedSelection.

In Asp .Net versions before 4.0, if a row is selected in Gridview then the same row number on all pages was get selected automatically. This was because of row selection on basis on index value.
But with ASP .Net 4.0, data Key based row selection is also supported. So now by enabling data key based row selection (by making EnablePersistedSelection=”True”), if a row is selected on page 1, later you move to next page 2, and so no row is selected on page 2, on returning to page 1 again, old row is still selected.

Keep enjoying coding in ASP .Net 4.0

MSDN Reference:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.enablepersistedselection.aspx

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.enablepersistedselection.aspx


Software Architecture – Difference between id, name and clientid – For WPF/Silverlight/Window Forms/ASP .Net?

August 14, 2010

Lets focus on id and name first.

For WPF/Silverlight/Window Forms:
There is no concept of “id” in WPF, Silverlight and Windows Forms. But “name” is used to identify a control uniquely. So if you create a Textbox with “name” as “myTextBox”, then a variable will be created in code behind to access its properties.

For ASP .Net
In ASP .Net, “id” is used to uniquely identify a control in a page.

In ASP .Net, if you create a TextBox control as:

<asp:TextBox  ID="TextBox1" runat="server"></asp:TextBox>

Then in code behind file, a variable will be created as “TextBox1”, so in ASP .Net “ID” is used to uniquely identify a control.

So if you create a ASP .Net page with controls as:

<asp:TextBox  ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox  ID="TextBox1" runat="server"></asp:TextBox>

It will give a compile time error that two controls with same “ID” can’t co-exist in the same ASP .Net form.

If you will put control as below:

<asp:TextBox  name="TextBox1Name" ID="TextBox1" runat="server"></asp:TextBox>

A message will be shown as below:

Validation (ASP.Net): Attribute 'name' is not a valid attribute of element 'TextBox'.	

So in Asp .Net “name” is not allowed in server side control.

In ASP .Net, against following ASP .Net control

<asp:TextBox   ID="TextBox1" runat="server"></asp:TextBox>

Will transform in html as:

<input name="ctl00$MainContent$TextBox1" type="text" id="MainContent_TextBox1" />

Means that a “name” attribute is automatically created by concatenating the control hierarchy with “$” character and ” ID” values modified by concatenating with “_” character.
It is because in HTML ID and Name co-exist side by side.

id attribute was introduced only in DOM .ID supposed to be unique for the given document, while name can be the same for many elements (think of radio buttons group for instance).

According to http://solidlystated.com, best comparison can be done as:

Id Attribute
• Valid on any element
• Each Id should be unique
• Can be used as anchor reference in URL
• Is referenced in CSS or URL with # sign
• Is referenced in JS with getElementById()
• Shares same name space as name attribute
• Must begin with a letter
• Is case sensitive

Name Attribute
• Valid only on a, form, iframe, img, map, input, select, textarea
• Name does not have to be unique
• Can not be referenced in CSS or URL
• Is referenced in JS with getElementsByName()
• Shares same name space as id attribute
• Must begin with a letter
• Is case sensitive
• Used on form elements to submit information

Reference:
http://solidlystated.com/scripting/html-difference-between-id-and-name/

According to w3, following are main usage of ID attribute in HTML:

• As a style sheet selector.
• As a target anchor for hypertext links.
• As a means to reference a particular element from a script.
• As the name of a declared OBJECT element.
• For general purpose processing by user agents (e.g. for identifying fields when extracting data from HTML pages into a database, translating HTML documents into other formats, etc.).

What is clientid?
There is no concept of ClientID in Windows forms, Silverlight and WPF. It is only related to ASP .Net.
Clientid is used to give a systemically created id attribute to HTML control generated by running a ASP .Net control.

<script type="text/javascript">
    function DoSomething(){
        alert('<%= TextBox1.ClientID %>');
    }
</script>

The above code will give “MainContent_TextBox1” showing the id of control.


Software Architecture -Error – IIS running for ASP .Net 2.0 and ASP .Net 4.0

August 10, 2010

Environment: IIS + ASP .Net 2.0 / 4.0

Problem Definition:
Suppose you have IIS running for ASP .Net 2.0 and ASP .Net4.0 , some application are running on ASP .Net 2.0 , so when a new application is deployed on ASP .Net 4.0, Application based on ASP .Net 2.0 will close with following message.

Server Application Unavailable

Windows Event log will show details as:

It is not possible to run two different versions of ASP.NET in the same IIS process. Please use the IIS Administration Tool to reconfigure your server to run the application in a separate process.

Solution:
When you run IIS 6.0 in worker process isolation mode, you can separate different Web applications and Web sites into groups known as application pools. An application pool is a group of one or more URLs that are served by a worker process or set of worker processes. Any Web directory or virtual directory can be assigned to an application pool.

So solution is to create separate application pool for each version of ASP .Net .
Secondly, select separate application pool in each web directory / web application configuration. This will solve the above issues.

References:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/67e39bd8-317e-4cf6-b675-6431d4425248.mspx?mfr=true
http://technet.microsoft.com/en-us/library/cc757073(WS.10).aspx