DotNetCurry Logo

Monitoring performance of SignalR Applications

Posted by: Suprotim Agarwal , on 7/9/2013, in Category ASP.NET
Views: 85760
Abstract: Measure a SignalR application’s performance using some monitoring tools when hosted on IIS/IIS Express

We have in the past seen how to use the persistent connection framework – SignalR from the ASP.NET team. SignalR is one rare framework that actually lights your eyes up once you start getting the hang of what it can do. But after you are done with the ‘oh wow that is cool!’ phase, you (or your boss) usually asks the question, how does it perform? Well the correct answer for that is ‘it depends’! As much as we hate that phrase, performance is something that you simply don’t have a formula for. You can determine performance ONLY via performance testing and measurement against a given baseline. And again, you have to set your own baseline.

The question is how? How do we instrument and test our SignalR application?

 

Today we will see how to setup the required instrumentation and run some of the samples that the SignalR team provides to see how we can baseline a SignalR app. In future, we will explore how to use this instrumentation in our own app.

Setting up the SignalR Sample

Given the recent release of Visual Studio 2013 and Visual Studio 2012 Update 3, there maybe a little confusion as to the target environment, so my setup is Window 8 Pro, Visual Studio Express for Web 2012 Update 3.

The SignalR Code

The test code that we are going to use is a part of the SignalR repository on Github. You can download the zip here, or clone the repository from here.

Once you have the code downloaded, open the Microsoft.AspNet.Signalr.sln. Instead of double clicking on the solution, it is a good idea to open Visual Studio as Administrator and then open the project by browsing to the location. Depending on additional frameworks installed, you may get load failure notifications for a few projects from Visual Studio. If you are using web developer express edition, you will certainly not be able to load the WinRT and the Windows phone projects. Ignore the errors and exclude the projects with errors.

Build the project to ensure all dependencies are in place. Nuget Package Restore is setup with the solution, so it will get the required dependencies from Nuget if required. Once the build is successful, we are ready to begin exploring.

What do we test – Number of Clients + Number of Messages Sent?

Before we get started with our ,we need to decide on the parameters for testing. First parameter we would like to test is number of clients that can connect to our SignalR App. This implies the number of concurrent users. Next thing we would like to test is how many messages per second can SignalR handle. For this, we need to be able to broadcast certain number of messages to all the clients we have.

Step 1: In the solution expand the samples folder and setup the Microsoft.AspNet.SignalR.LoadTestHarness as the startup project.

Step 2: Run the solution to bring up the test harness project

test-harness-server-ui

The Test Harness project shows parameters for the SignalR application and can fire up clients using the Load Generator link. The UI can also setup the SignalR Hub to broadcast messages at the specified rate (msg/sec). Clicking on the Start Broadcast starts broadcasting to all clients registered.

Opening a ‘Load Generator’ in a new browser gives us a SignalR client like the following. As we can see, the client can be setup to send messages to the server even in n milliseconds.

signalr-harness-client

With the Server and the clients’ setup, we can look into monitoring the interactions.

Getting Started with Performance Monitor Perfmon.exe

Perfmon is an executable that usually accompanies Windows Professional versions and above. You can set it up to hook in and listen for performance counters in various applications. Today we will set it up to listen to ASP.NET requests and later install some SignalR performance counters to view SignalR statistics.

Step 1: tap the windows key and type Perfmon.exe (in Windows 7 or 8). For the shortcut that comes up, right click and select ‘Run as Administrator’.

performance-monitor

Step 2: Select Monitoring tools > Performance Monitor. Now in the right pane, click on the highlighted button twice. You will see the default performance counter, the %Processor Time as you can see above.

Step 3: if you had started the Visual Studio in Administrator mode you are good, else now is a good time to do it and run the test harness project.

Step 4: Click on the green [+] button to bring up the Add performance Counters dialog. Scroll till you find ‘ASP.NET Applications’.

select-asp-net-object

When you select the ‘ASP.NET Applications’ you’ll see your App in the ‘Instances of selected object’ List. As seen above, its identified as _LM_W3SVC_152_ROOT. Select the object.

Step 5: Expand the ‘ASP.NET Applications’ and select Requests Executing, Requests Executing (Web Sockets) and Requests/Sec from the list. Click Add to add the selected counters to the ‘Added Counters’ list.

asp-net-performance-counters

Monitoring Performance

To start monitoring performance, restart the Test Harness application and Click OK in the Add Counters window.

Step 1: Initial statistics would be something similar to the screenshot below:

monitoring-basic-perf-counters

Since only the Server UI is running, the Number of Requests is 1, and as we can see, it is over WebSockets. There are no periodic requests because we haven’t started broadcasting yet.

Step 2: Set the Broadcast Rate to 10 messages/sec, Start two ‘Load Generator’ instances and click ‘Start Broadcast’. As shown in the image below, we have three Requests going, one for the Server UI and two for the load generation clients (marked 1, 2, 3). The server is broadcasting 10 messages per second and as a result, the Server FPS value in the Server UI has gone from 0 to 10 FPS. We are also seeing how the server is loaded via the %Processor Time. However we are not getting any traffic information. To monitor SignalR traffic, we need some additional Counters.

load-test-harness-3-clients

Step 3: Setting up SignalR performance counters.

- Open a command prompt and change directory to the folder where you downloaded SignalR code.

- Now go into src\Microsoft.AspNet.SignalR.Utils\bin\Debug folder

signalr-util-folder

- Note the bin\Debug folder will exist only after a successful build of the code. Alternately you can get it from Nuget. It’s in the package - Microsoft.AspNet.SignalR.Utils

- Run the command SignalR ipc

install-signalr-perf-counters

- This installs SignalR related performance counters.

- Switch back to PerfMon.exe and scroll down to select the new Counter in the Available Counters list ‘SignalR’

signalr-performance-counters

- You will see your app microsoft.aspnet.signalr.loadtestharness > select it and click Add to add all PerfCounters for SignalR.

Note: If you don’t see the testharness instance object, reload the solution and restart the application.

- Now start a set of SignalR Load Generator clients (you can see three below), set the server to send a high number of messages per second (I’ve set it to 40). Now look at the performance counters

- Broadcast Rate: As we can see highlighted in the Red boxes, the server is Broadcasting at 40 messages per second and our Perf-Counters on the UI and in PerfMon nearly match.

- Connection Messages/Sec: As we can see, we have three clients sending (1000/100)=10 messages/second each and as a result PerfMon is showing ~30 messages/second

- Requests Executing and %Processor Time: As seen earlier Requests Executing is 4 because 3 Clients and one Server browser open. The given load has resulted in loading the processor upto 65%.

- Next Steps: To increase load, we can increase the number of clients connected, but increasing the number of browsers is a little tedious. The SignalR team has a utility called CRANK that can be used to crank up the number of clients for your testing. In our next article we will review Crank.

monitoring-requests-exec-perf-counters

 

Conclusion

Today we saw how we could use PerfMon along with the SignalR performance counters to measure performance of a sample SignalR app. Next we will see how to do this for a custom SignalR app and crank it up using CRANK! Stay tuned!

Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+
Further Reading - Articles You May Like!
Author
Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of DotNetCurry, DNC Magazine for Developers, SQLServerCurry and DevCurry. He has also authored a couple of books 51 Recipes using jQuery with ASP.NET Controls and a new one recently at The Absolutely Awesome jQuery CookBook.

Suprotim has received the prestigious Microsoft MVP award for nine times in a row now. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that represents premium web sites and digital publications comprising of Professional web, windows, mobile and cloud developers, technical managers, and architects.

Get in touch with him on Twitter @suprotimagarwal, LinkedIn or befriend him on Facebook



Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by nick on Thursday, July 11, 2013 12:25 AM
I find this article very inspiring in building a case as to why to use a technology and knowing its implications on a system is of the utmost importance. Thank you for this.