This is a little-known feature of Visual Studio 2010 Premium that I want to devote a little time to and introduce you to it. It is useful when you are trying to determine why your ASP.NET application does not work with such performance as it should, and how the application queries to the database are built, whether they improve performance or reduce.
For use in this publication, I downloaded a simple and unknown application “NerdDinner” written by Scott Guthrie
and friends. Download it from here
, install it and make sure that it works (if you have a working version of SQL Express, the application will simply make an attachment to the mdf file associated with the project. SQL Express is installed by default in all Visual Studio 2010 installations, but if you don’t instance when SQL Express is running, you need to play around with the connection string settings in the ConnectionStrings.config file. Refresh your knowledge of the connection string syntax here
.). When everything is working, register a user account to complete the steps described below.
Ok, now you have a working web application, let's run the profiler and see what we see.Starting the Performance Wizard
In Visual Studio, select Analyze (Analyze) and then “Launch Performance Wizard ...”.
Next you will be presented with the following dialog:
Simply select the default setting (which should be “CPU Sampling”) and click the “Next” button. After that the following will appear:
Notice “NerdDinner” is the only choice in this dialogue, which is good, as the only project that we want to profile at the moment! If you have a lot of projects that form executable files or web projects, they will also be shown.
Click “Next”, this will display a new wizard page:
Make sure that “Enable Tier Interaction Profiling” is checked, as this will enable features that I will discuss later in this publication. You can read the entire publication in order to understand what it is about, or simply click “Next”.
Leave marked “Launch profiling after the wizard finishes”.
Visual Studio will now launch the Cassini web server with the NerdDinner web application.Application launch
At this point, it’s a doc well, it’s currently underway:
From this point on, Visual Studio will begin a performance profiling session, load the .vsp file into the document area and display to you what profiling is going on:
Now do the following:
- Log into the account in the application
- Place an order for two dinners
Do this by clicking the “Host Dinner” tab and entering the dinner information on the page, click “Save”, and then repeat these steps one more time.
- Exit the application by closing IE
In a moment, Visual Studio will display something similar to the following illustration:Results analysis
One of the main functions of the profiling toolkit in Visual Studio is called the “Hot Path”. It quickly shows areas of code where there may be a loss of performance. At the very least, it becomes absolutely clear what the application spends most of the time on.
In the image below, it is immediately apparent that the GetMostPopularDinners method seems to take up most of the time in relation to the session just executed.
Let's click on this link (pointing to the method). You should see something like the one below:
A lot of things happen here. Notice that the “Current View” drop-down list is set to “Function Details”. This is important and also highlights the problem with the user experience of Visual Studio, how many users do not know that there is this drop-down list and miss an enviable share of the functionality! This is one of the main reasons why a lot of guys do not know about Tier Interaction Profiler, since this is just a different view of the performance session.
You can play around with the “big blue rectangles” by clicking on them, moving further and back by clicking on the left or right rectangles.
You also noticed that I highlighted a line of code that caught our attention when using the Hot Path function. You also noticed a 42.2% time characteristic in the left-hand corner of a text editor, with the actual string marked by default in a “reddish” color.
It seems that this is a string where time is wasted, since this is the place where a LINQ expression is actually constructed before calling it for a query (If you are not familiar with this concept, I highly recommend reading this publication
Let's take a look at the code, it looks as if in it we are accessing the database from the backend in this method:
public ActionResult GetMostPopularDinners( int ? limit)
var dinners = dinnerRepository.FindUpcomingDinners();
// Default the limit to 40, if not supplied.
limit = 40;
var mostPopularDinners = from dinner in dinners
orderby dinner.RSVPs.Count descending
var jsonDinners =
.Select(item => JsonDinnerFromDinner(item));
* This source code was highlighted with Source Code Highlighter .
How can I see the TSQL which is sent to the database? Let's go to Tier Interaction Profiler.Tier Interaction Profiler
You noted in the image above that the line we are exploring is currently part of our SearchController controller. Let's look at the code more closely, the GetMostPopularDinners method is actually an controller action and is called by the URL relative to the application. What does all this mean?
Well, all this shows that the NerdDinner application is an example of a set of technologies, primarily ASP.NET MVC 2. ASP.NET MVC 2 has a very powerful URL routing mechanism which is useful when you need to make more user-friendly URLs s, easier to maintain, etc. This becomes apparent when viewing data in Tier Interaction Profiling.
Click on the "Current View" drop-down list and select "Tier Interactions":
Now you should see something similar to the image in the top panel:
The “Name” column contains a list of various artifacts requested by the client (in this case, IE running the NerdDinner application) on the server. You will see how many requests for this element are recorded in the “Count” column, as well as how long the request was executed.
For example, you will notice /Content/Production.css
in the “Name” column. This css-file was requested 7 times, for a total of 38 milliseconds of delay. Thus, it is very convenient to receive information about the various requests that the application performs to the server.
And at the top of the list (and returning to our running example) you will notice an element / Search / GetMostPopularDinners
which runs most of the time. Usually you see addresses that end in aspx (pages) or css (documents), etc., but since this application takes advantage of ASP.NET MVC 2 routing, you see more friendly addresses that are requested from the server.
And what to do with database queries?
The TIP (Tire Interaction Profile) view associates requests to a server with database calls associated with those requests. So, if you expand the / Search / GetMostPopularDinners element
, you will see the following:
A return request to the server at / Search / GetMostPopularDinners
turns into two database requests that together take ~ 75 milliseconds. Not bad, but even better, you can see in the “Database connection details” panel you can see the TSQL itself being sent to the database. Double-click on the record to see the full SQL, similar to this:findings
Tier Interaction Profiler can make understanding queries from your client to the database very easy to understand. You will understand not only which SQL is transferred, but also be able to analyze the performance of the entire operation.
I hope this helps!