Check Application Performance Under Load Test Using Visual Studio

Background

Before starting work in performance optimization, first need to set performance benchmark for your site. As I mentioned in my previous article, if you need to improve your application performance then first check existing performance and then work on optimization to meet performance benchmark.

Introduction

Please read my first article Check .NET Application Performance Using Performance Optimization before, because it is their extension.

Before starting Load test, you should be aware about the difference between Load Test and Performance Test.

Performance testing is the testing, which is performed, to ascertain how the components of a system are performing, given a particular situation as I explained in my previous article. There I explained admin user login into site and created some records and then checked their performance against single user. Whereas Load test is a container of performance test and it run performance test under certain load till it reach their threshold limit. So in Load test same functionality (Admin user) will be run by multiple concurrent users.

Create Load test step by step and verify the results

We will use same project created in last article.

Step 1: Create Load Test: In Solution Explorer, right-click the existing Web Performance and Load Test project node, Add, and then choose Load Test.

 
 
Step 2: Load test wizard starts, provide Scenario name. A scenario consists of a set of multiple performance tests.

E.g. Scenario Name: Buy item
  • Test 1: Login into site, Search for item.
  • Test 2: Search Item, Add to cart and Place order.

Here you can set Think time (artificial human delay times between Web requests).

 

Step 3: Set Load Pattern setting, two type of patterns can be provided.

  1. Constant Load: Specify same number of user constantly hit your application for specified time. But at the beginning of the load test, it is not reasonable and realistic demand for any site. So use it carefully.

  2. Step Load: Specify a user load that increases with time up to a defined maximum user load. It is a good option to check, what maximum user load capacity that your application can handle at particular server configuration. As load increases, the server will eventually run out of resources.
 
Step 4: Set Test Mix Model for load test, here if your application have multiple work flows like Search Items, Add to Cart and Place Order, Upload Master Data. So you can define load according to your work flow means how many virtual users will use which functionality more. In general, Search Items is most widely used by customers in e-commerce site rather than Add to Cart and Upload Master Data.
 
 
 
There are four model types that you can provide.
  1. Based on the total number of tests: In this case, you can select which Web Performance Test will run more when a virtual user starts hitting your application. After load test execution, it match number of test run with assigned test distribution. You will see this below under result section. For example, I have the following 3 Test cases and during load test if there will be 1000 test cycles runs (i.e. same test case runs multiple times), then

    • 600 Search Item test cases should be executed
    • 300 Add to Cart and Place Order tests case should be executed
    • 100 Upload Master Data tests case should be executed

    This describe maximum iterations will occur for Search Item test case.

  2. Based on the number of virtual users: It provide % age of virtual user that will run particular test case. E.g. If there are 1000 active user on your site, then 600 users are using Search Item functionality. It means continually 60% of total user load will keep using Search Item module without keeping track that how many cycles has been completed for Search Item work flow.

  3. Based on user pace: it provide frequency for particular test that will run how much times against per user per hour.

  4. Based on sequential order: Here you can specify the sequence for test cases that need to execute in some order. During load test same order will follow in through multiple loop until load test complete.

Generally, we use only first two options to get more realistic results.

Step 5: Add Web Performance Test that need to be run under load test. Here you can add multiple Web Performance Test (created earlier in previous article). One work flow can be one performance test. 
 
 
 
You can also provide Load distribution, value for Test Mix Model selected in step 4, across multiple Web Performance test cases and can provide more realistic load distribution based upon application usage. In the following image, 71% application used by admin and 29% used by accountant.
 
 
 
So for any eCommerce Site, you can create the following type of Web Performance Test cases and distribute load accordingly. E.g.
  • Customer Search Items – 60%
  • Add items to Cart and Place Order – 25%
  • Customer Registration – 5%
  • Upload master data – 10% 
Step 6: Specify which type of Network connection will be used by client to connect your site.
 
 
 
Distribute load against different types of network connections e.g. LAN 60%, 3G 15%, CDMA 10% etc. Keep LAN 100% to test application hosted on your local machine.
 
 
 
Step 7: Specify which type of browser used by end user. Create a closer approximation of the Web browsers that will be used with your applications. A Web browser type is randomly associated with a virtual user, based on the browser mix.
 
 
 
Step 8: Specify Counter Set for resources against which you want to collect data from server where Load test will run. There are three counter categories: percentages, counts, and averages. E.g. % CPU usage, SQL Server lock counts, and IIS requests per second.
 
 
 
Click Add Computer and select resources against which you want to capture counter set. E.g. ASP.Net, IIS, SQL in above figure.
 
You can also specify remote server (web site host machine) and threshold rules that set on an individual performance counter to monitor system resource usage during a load test. It keeps monitor what is threshold value and what is current value for counter set. E.g. CPU % threshold value is 80%.
 
Step 9: Specify Run Settings determine such properties as the duration of the test, warm-up duration, sampling rate, connection model (Web performance tests only), results storage type, validation level and SQL tracing. 
 
There are two options
  1. Specify Load test duration,

    1. Specify the Warm-up duration (hh mm ss). Use the hour, minute and second spin controls.
    2. Specify the Run duration (hh mm ss). Use the hour, minute and second spin controls.

  2. Specify the number of times to run the test. Use the Test iterations spin control.

 
Apart from that you can also specify Sampling Rate and Validation level (validation that mentioned during web performance test like Response Goal should be 1 second).

Step 10: Double click .loadtest file and click Run test button run the load test.

 
 
Click Manage Test Controller, here you can also provide Database connection (Database name is LoadTest2010) where you want to store load test results.

 
 
NOTE: If you don’t have LoadTest2010 database on server. Then go to IDE folder on your machine where Visual Studio install and search for “loadtestresultsrepository.sql” file and run the same on server to create LoadTest2010 database. E.g. C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\loadtestresultsrepository.sql

Now you have done all the required setting for Load test, so let us run the Load test and verify the results step by step.

Run Load Test and analyze the results

Step 1: Click Run button, after Run successfully different type of result report available like Summary, Graphical, Table or Details. By default, Summary will open and here the following points to be noted down,
 
  • Top five slowest pages, here you can get list of pages which are taking more time for processing.

  • Total number of Web Performance Test cased execution distribution, as we specified distribution during load test creation admin 71% and accountant 29%.

Type of errors occurs, here ResponseGoal was set 1 second for all pages under admin web performance test but almost all the pages fail to achieve this target. On click of Error link, you can also get exact details.
 
 
Step 2: Click Graphs, here you can see multiple graphs at a time. On left hand side, Counter set values for all resources consumed. On right hand side, resources consumption details inform of Graphs and Range (Max, Min and Avg) values.
 
Under Counter Set panel, under Computer Name node all resources data is available. Some of them are highlighted below.
 
  • .NET CLR resources: It provide all resources consumption against load test like how much bytes from heap consumed by your application. On right hand side under Key Indicator graph, you can see .NET CLR memory from heap consumption is increasing during load. Here you can take decision if there is any memory leakage or not.
  • IIS (ASP.NET/ASP.Net Application): It provide resource consumption at IIS level like Request/Sec, Session Active, Request Rejected (due to security or any reason), Request Queued, Output Cache Hit Ratio (how much pages processed directly from cache), Cache Hit Ratio (how many times application cache used), etc.
  • Memory: It provide how much memory consumed during load test like % Committed Byte In Use, Available Mbytes (amount of physical memory, in MB, available to running processes).
  • Network Interface: It provide network resources consumption like Bytes sent/sec, Bytes received/sec, and Current Bandwidth. Here you can take decision if bandwidth consumption more, then try to make request/repose size optimize by taking the following action for the same.
  • Use Ajax calls (light weight requests)
  • Use JSON serialization instead of XML serialization (light weight response).
  • Use client side cache, if same static data need to process from server multiple times (make sure not to cache secure or unnecessary data on browser as it also has limited memory). 
  • Process: It provide what are processes that used by your application and what are their consumption like “% processor time”, Handle Count, Thread Count taken by sqlsever, devenv (visual studio).
  • SQL Server resources: It provide all consumption at SQL server level like Full scan/sec, Index search/sec, Transactions/sec, Lock Timeout/sec, Number of Deadlock/sec. Here you can see what issues occur at heavy load on database side (e.g. deadlock, timeout, table scan).

To see recourse usage details, double click on the same and their respective details will be available on right hand side in form of Graphs and Range value as in the above image.

In Graphs, horizontal axis represents time duration with fraction of 10 seconds. I run load test only for 3 minutes.

  • Key Indicator graph: I selected the following resources from Counter set
  • User Load: It increases every 10 sec, starts from 10 and reach up to 180 (in 3 min).
  • Transaction/sec: Transactions/sec increase with respect to user load.
  • Bytes in all Heap: It increase with user load. But if it sharply rise then there can be memory leakage problem like resources does not release properly after consumption.


  • Page Response Time: Click pages from Counter Scenario Web Performance Test Pages Page Name, against which you want to check performance across load test. On graph, you can see how it performs when load increase. As load increase, its performance go down. There are multiple properties that you can check against any page like Avg Page Time, Pages/Sec, etc. 
 
  • Controller and Agent: System resources like % CPU utilization, Memory utilization, Network I/O bytes sent and received per second, .NET CLR threads can be checked here. Here CPU % usage exceed threshold value 80%.

If you want to share your application results with pears then export test results to excel file. To export into excel format, click Create Excel Report icon under Load Test result toolbar. On click, it will open excel file with the following window and provide required input.

 
 
Note: Load Test Excel plug-in (as shown in above image) might not load properly. To correct this, in Microsoft Excel 2010 or later, follow these steps:
  1. In the Office ribbon, choose File.
  2. Choose Options and then choose Add-Ins.
  3. In the drop-down list under Manage, choose COM Add-Ins, and then select Go.
  4. Select the checkbox for Load Test Report Addin.

Once Excel plug-in loaded properly then perform the following steps.

  1. Select Create Report
  2. Select Trend
  3. Provide Report Name
  4. Select Load Test results that need to be provided in report (if same Load Test run multiple time)
  5. Select Resources name against which Counter value needs to be capture in excel report.

It will generate excel report that contains table of contents as first worksheet and remaining counter set values as per workbook as in the following,

 
 
If you compare results with previous article, where all the web pages are working fine (expect one stud_entry.aspx) but under load (where max user load is only 180 user) all the pages performance go down as you can see below.
 
 
Note: If you already write unit test cases for your application, then you can also run Load test against the same. No need to create Web Performance Test (UI steps recording). Please refer this link for more details: Creating and Running a Load Test Containing Unit Tests.
 
In last, Load test results also depends upon your current machine configuration and number of processes running over the same. So make sure whenever you run Load test on your local machine keep all the unnecessary process closed to get more corrective results.
 
After running load test you can get what are the pages that need improvements. Now need to identify which area of code that is taking more time to execute. You can use Stopwatch under System.Diagnostics.Stopwatch to get methods that take more execution time, as you can see below
  1. Stopwatch watch = new Stopwatch();  
  2. watch.Start();  
  3.     
  4. //Call your code here    
  5. watch.Stop();  
  6.   
  7. // you can capture execution time in logs to verify the results later  
  8. Console.WriteLine("Measured time: " + watch.Elapsed.TotalMilliseconds + " ms."); 
For more details about Stopwatch, you can refer here. 

By using all these steps, as developer you have scope and area of code that required manipulation from performance point of view. No need to wait for any performance testing team to achieve this results, it will take only 15-20 minutes for any developer to check their application performance.

Let’s summarize both the articles again steps by step through the following diagram. Now you can evaluate your work better than others. 
 
In my next article I will explain, performance optimization check points that need to be taken care in the following phases
  • Architect
  • Design
  • Implementation

References