Wednesday, February 23, 2011

Performance Monitoring of individual Asp.net Application in Asp.net 4.0


DARE TO SHARE?
As you may know already, it is possible to monitor performance for Asp.net applications running within the Asp.net worker process (w3wp). It is as easy as adding some performance counters in the Performance Monitoring Administrative utility (Which ships with windows) and gathering some performance data for the running Asp.net applications.

However, before Asp.net 4.0, it wasn't possible to gather performance data for each individual asp.net application. So, if there were multiple Asp.net applications deployed within the same Asp.net worker process, and, if we needed performance data for a particular Asp.net application, we had no luck as we could only get consolidated performance counter data for all Asp.net applications running within the same Asp.net worker process. So, it wasn't possible to know how much memory or CPU was being consumed by a particular Asp.net application running within an Asp.net worker process.

Well, Asp.net 4.0 makes this possible. In Asp.net 4.0, the performance counters can gather data at AppDomain level (You may have to specify the following settings in the Aspnet.config file to enable this, in my case I edited the C:\Windows\Microsoft.NET\Framework\v4.0.30319\Aspnet.config file)

<?xml version="1.0" encoding="UTF-8" ?> 
<configuration> 
    <runtime> 
        <appDomainResourceMonitoring enabled="true"/> 
    </runtime>
</configuration> 

Assuming you have an Asp.net 4.0 application hosted in IIS, all you have to do is to follow these steps to gather performance data for an individual Asp.net application:

1. Browse or run the Asp.net application to make sure that the corresponding Application domain is loaded within the Asp.net worker process (This is required, otherwise, the corresponding Asp.net application won't show up in the performance counter selection window).

2. In the Run command, type perfmon and hit "OK" to launch the performance monitoring tool.


Figure : Run command to launch performance monitoring tool

3. Once the Performance Monitor tool is launched, select the "Performance Monitor" node in the left panel and click on the plus sign to add a performance counter.


Figure : Add Performance Counter

4. After the "Add Counter" window is launched, expand the "ASP.NET Applications" counter and select the counter "% Managed Processor Time (estimated)". Once selected, you will see the available list of Asp.net applications (And, a few other options) in the "Instances of selected object" box from where you need to select an object which represents the Asp.net application you want to monitor. In my case, I selected the object "LM_W3SVC_2_ROOT". Once selected, click on the "Add>>" button to show up the selected counter in the right panel.


Figure : Select Performance Counter and the corresponding Object

Note : How to understand which object name represents what Asp.net application?

There could be many Asp.net applications running under the same Asp.net worker process. The corresponding object names is be shown in the format

LM_W3SVC_APPLICATION_ID_IN_IIS_APPLICATION_NAME

The APPLICATION_ID_IN_IIS is the corresponding Application ID assigned by the IIS with some numeric values like 1, 2, 3 etc, and, the APPLICATION_NAME is usually set to "ROOT" in case the Asp.net application runs directly under a web site, or, the APPLIACTION_NAME is set to the corresponding application's name if the Asp.net application runs under a web site in IIS.

You can hit the following command to list the Asp.net application information in IIS and know the Application ID of your site:

appcmd list sites

It would show you an output like the following from where you can know the Site ID of your Asp.net application:


Figure : appcmd command to list site information in IIS

5. Add another counter "Managed Memory Used (estimated)"  for the same Asp.net application object, click on the "Add>>" button and then and, click on the "OK" button to confirm the counter selections.



Figure : Add Managed Memory Used (estimated) counter

The performance counter will immediately start collecting performance data and the performance graph will be shown using two different colored lines.


Figure : Performance Graph
6. Browse the Asp.net application and execute the target functionality you want to monitor performance for. The counter will keep gathering performance data.

Once you are convinced with gathering enough performance data by executing the specific functionality in your application, freeze the display by clicking on the "Freeze" button and then take a look at the graph to understand how much processing time (In terms of percentage) or Memory is being consumed by the Asp.net application.


Figure : Freeze performance counter display

Alternatively, you can switch the performance counter output to a "Report view" for a better understandability.


Figure : Switch to "Report" view to see performance data


Figure : View Report for performance data

Tracking the Memory and Processor usage at the application level gives you more granular look at resource consumption of each Asp.net application running within the same Asp.net worker process and this is really a cool feature offered by Asp.net 4.0.

0 comments:

Post a Comment