Friday, May 22, 2009

How to use .NET profiler to troubleshoot ASP.NET page perfomance issues

How to use .NET profiler to troubleshoot slow ASP.NET page performance

 

I'm frequently tasked to figure out why certain pages or parts of websites are slow (assuming site is ASP.NET based). In this specific article I'll show how to use free .NET profiler from Equatec http://www.eqatec.com/tools/profiler to troubleshoot this issues.

 

My common troubleshooting steps (before diving into ASP.NET website performance troubleshooting are below).

 



  1. Use Fiddler tool (http://www.fiddler2.com/fiddler2/) to actually measure response time of web page. This works with AJAX based pages as well and will actually provide you information which you usually would not be able to see in browser window (simple GET/POST requests are so 90s in modern technologies).


  2. Once you get statistics and confirmed that you do in fact have backend problem other then networking issues I usually see if there are any known dependencies for the page (like SQL backend). This is pretty easy to figure out by looking through web.config file. I start SQL profiler on SQL server afterwards and resubmit request from browser again watching profiler statements coming through. Sometimes troubleshooting ends here (if you see that Execution time of stored procedure or ad-hoc query corresponds to total page response time.



  3. At this point if you ruled out backend slowness you are probably looking at some issues within ASP.NET website itself. I usually enable ASP.NET tracing at this point by going to web.config and adding following statement there
     

    <trace enabled="true" localOnly="false" pageOutput="true"/>). This will output tracing information (most importanly times to takes to execute specific methods in pipeline). Sometimes it's enough to to see which part of the page pipeline fails.

     



  4. Please note that page execution times listed trace output are not including times which are spends outside of the page (like authenticating request or processing events in global.asax). So you might see fast execution times in trace output but page will still be slow to render and hence we come to real purpose of this article, i.e. to use .NET profiler to see what is causing page to stall.

 

 

I wrote a sample website where I simulated different stalling conditions. Stalling in pre-page execution pipeline (in global.asax) and stalling inside page itself (SQL call or Web Services call or something of that nature). To simulate long running method I inserted following statement in relevant methods (System.Threading.Thread.Sleep(5000);). This makes current thread sleep for specified amount of time. I put Tracing statements through the code so you can actually see in screenshot below where latency are being introduced. Lines in red indicate Trace statements in the code. (First one in global.asax Application_BeginRequest event and second one inside Page_Load() statement of default.aspx page). In real life scenario you most likely would not have any Tracing statements in code you'll be troubleshooting though.

 

 

I compiled my test website and at this point all I have is what you probably would have in your case. You can download it here (ZIP). Once you installed it, navigate to default.aspx page and see how much it takes to load a page (shall be around 7s or so).

 

Next step is to install Equatec .NET profiler from here (Here).

 



  • On first run it'll display default screen below


 



  • Click browse button and navigate to installation directory of your website (BIN folder) and open precompiled binary for your application (profiler.dll in this case)



 



  • Click "Build" button on bottom. Profiler will inject profiling information into your assembly and output results to the "Bin-Profiled" folder under the same root where your original "Bin" folder is. You'll see that you original DLL file grew up in size because of that.


  • Copy all files from "Bin-Profiled" folder to "Bin" folder (replacing files)


  • Switch to "Run" tab and navigate to your problem page. You'll notice that Control area will be updated with information "Profiled app Profiler started"




  • Click on "Take snapshot" button. It'll generate report about execution time and put report under "View Snapshot reports" area.




  • Click "View" button now with latest report selected. Result below is exactly what you'd expect to see from test file. Which is first 5 seconds were spent in BeginRequest event and next 2 in Page_Load calling "DoSQLQuery" method.



 



  • Now since you know which specifics methods take that much time you need to take a look at what is being done inside those methods. In this case (and probably yours) you'll just have assembly (profile.dll). You need to use tool like .NET Reflector (Download here) to see contents in readable form.

 

Now we can see exactly why it took so long to execute this specific method. In your case it might be SQL call or web services or call or something of that nature.


Monday, April 06, 2009

Instructions how to enable SSTP VPN s...

Instructions how to enable SSTP VPN server in Windows 2008 simplified


In this brief 10 minutes procedure below you'll learn how to create VPN connection using SSTP (SSL tunnel) to your work/home location from anywhere where HTTPS is allowed.


Guide below assumes you don't want to use your VPN server as Internet Router and you have some other devices doing routing. Steps below will allow you to VPN in your remote location and route everything (including Internet traffic) through that VPN connection. 

Difference from other guides on Internet:


  • Don't need domain controller or certificate services for this to work
  • Don't need 2 network adapters on your server to work
  • Don't need to publish SSL CRL (certificate revocation list)

What is needed:


  • Server SSL certificate (self-signed)
  • Windows 2008 on your local network (single NIC)
  • Vista SP1 or later

Steps:  


  1. Create self-signed certificate and import it into certificate store on client and server

    • Create self-signed certificate with domain name which you'll be using for your VPN server. I used this excellent utility (http://www.pluralsight.com/community/blogs/keith/archive/2009/01/22/create-self-signed-x-509-certificates-in-a-flash-with-self-cert.aspx). What you want to do is to put CN name as external name which you'll be using for your VPN server (like sstp.mydomain.com) and choose to export as PFX file. This will create PFX file with your certificate and designated location. In steps below it would be imported into client and server as Trusted CA.

      • Import certificate on client computer by following this steps: Launch MMC and choose Add Snap-in, choose "Certificates", on next screen choose "Local Computer" and then choose "Trusted Root Certification Authorities" and import your certificate into that store.
      • Import certificate on server computer exactly the same ways it was done on client.

  2. Enabled RRAS role on Windows 2008 and configure SSTP.

    • Install RRAS service on your server

      • Add Server Role called "Network Policy and Access Services". Choose only "Remote Access Service" for service since we don't need routing. Go through installation process.
      • Once server is setup, launch Routing and Remote Access MMC and choose to "Configure Routing and Remote Access server".
      • Choose "Custom Configuration" and choose "VPN access".
      • For your user go to user property pages. Choose "Dial-in" tab and choose "Allow access" under "Network Access Permission".

    • Configure your external router to port forward TCP 443 to your internal IP of your VPN server.

  3. Configure your Vista VPN client.

    • Go to Network And Sharing Center/Setup Connection or network/Connect to a workplace. Choose "Use Internet Connection", put your hostname for connection and go through the rest of the steps. Use "skip" since connection will probably fail since we need to configure connection to use SSTP. Once connection is created, go to properties of connection/Networking and choose as type of VPN - SSTP, uncheck IpV6 since you don't need at this point.

 

At this point you shall be able to VPN into your remote home/office.