uid | title | author | description | keywords | ms.author | ms.date | ms.assetid | msc.legacyurl | msc.type |
---|---|---|---|---|---|---|---|---|---|
signalr/overview/performance/using-signalr-performance-counters-in-an-azure-web-role |
Using SignalR performance counters in an Azure Web Role | Microsoft Docs |
guardrex |
How to install and use SignalR performance counters in an Azure Web Role. |
ASP.NET,signalr,performance counter,azure web role |
bradyg |
10/03/2018 |
2a127d3b-21ed-4cc9-bec0-cdab4e742a25 |
/signalr/overview/performance/using-signalr-performance-counters-in-an-azure-web-role |
authoredcontent |
By Luke Latham
[!INCLUDE Consider ASP.NET Core SignalR]
SignalR performance counters are used to monitor your app's performance in an Azure Web Role. The counters are captured by Microsoft Azure Diagnostics. You install SignalR performance counters on Azure with signalr.exe, the same tool used for standalone or on-premises apps. Since Azure roles are transient, you configure an app to install and register SignalR performance counters upon startup.
- Visual Studio 2015 or 2017
- Microsoft Azure SDK for Visual Studio Note: Restart your machine after installing the SDK.
- Microsoft Azure subscription: To sign up for a free Azure trial account, see Azure Free Trial.
-
Open Visual Studio.
-
In Visual Studio, select File > New > Project.
-
In the New Project dialog box, select the Visual C# > Cloud category on the left, and then select the Azure Cloud Service template. Name the app SignalRPerfCounters and select OK.
[!NOTE] If you don't see the Cloud template category or the Azure Cloud Service template, you need to install the Azure development workload for Visual Studio 2017. Choose the Open Visual Studio Installer link on the bottom-left side of the New Project dialog to open Visual Studio Installer. Select the Azure development workload, and then choose Modify to start installing the workload.
-
In the New Microsoft Azure Cloud Service dialog, select ASP.NET Web Role and select the > button to add the role to the project. Select OK.
-
In the New ASP.NET Web Application - WebRole1 dialog, select the MVC template, and then select OK.
-
In Solution Explorer, open the diagnostics.wadcfgx file under WebRole1.
-
Replace the contents of the file with the following configuration and save the file:
[!code-xmlMain]
-
Open the Package Manager Console from Tools > NuGet Package Manager. Enter the following commands to install the latest version of SignalR and the SignalR utilities package:
[!code-powershellMain]
-
Configure the app to install the SignalR performance counters into the role instance when it starts up or recycles. In Solution Explorer, right-click on the WebRole1 project and select Add > New Folder. Name the new folder Startup.
-
Copy the signalr.exe file (added with the Microsoft.AspNet.SignalR.Utils package) from <project folder>/SignalRPerfCounters/packages/Microsoft.AspNet.SignalR.Utils.<version>/tools to the Startup folder you created in the previous step.
-
In Solution Explorer, right-click the Startup folder and select Add > Existing Item. In the dialog that appears, select signalr.exe and select Add.
-
Right-click on the Startup folder you created. Select Add > New Item. Select the General node, select Text File, and name the new item SignalRPerfCounterInstall.cmd. This command file will install the SignalR performance counters into the web role.
-
When Visual Studio creates the SignalRPerfCounterInstall.cmd file, it will automatically open in the main window. Replace the contents of the file with the following script, then save and close the file. This script executes signalr.exe, which adds the SignalR performance counters to the role instance.
[!code-consoleMain]
-
Select the signalr.exe file in Solution Explorer. In the file's Properties, set Copy to Output Directory to Copy Always.
-
Repeat the previous step for the SignalRPerfCounterInstall.cmd file.
-
Right-click on the SignalRPerfCounterInstall.cmd file and select Open With. In the dialog that appears, select Binary Editor and select OK.
-
In the binary editor, select any leading bytes in the file and delete them. Save and close the file.
-
Open ServiceDefinition.csdef and add a startup task that executes the SignalrPerfCounterInstall.cmd file when the service starts up:
[!code-xmlMain]
-
Open
Views/Shared/_Layout.cshtml
and remove the jQuery bundle script from the end of the file.[!code-cshtmlMain]
-
Add a JavaScript client that continuously calls the
increment
method on the server. OpenViews/Home/Index.cshtml
and replace the contents with the following code:[!code-cshtmlMain]
-
Create a new folder in the WebRole1 project named Hubs. Right-click the Hubs folder in Solution Explorer and select Add > New Item. In the Add New Item dialog box, select the Web > SignalR category, and then select the SignalR Hub Class (v2) item template. Name the new hub MyHub.cs and select Add.
-
MyHub.cs will automatically open in the main window. Replace the contents with the following code, then save and close the file:
[!code-csharpMain]
-
Crank.exe is a connection density testing tool provided with the SignalR codebase. Since Crank requires a persistent connection, you add one to your site for use when testing. Add a new folder to the WebRole1 project called PersistentConnections. Right-click this folder and select Add > Class. Name the new class file MyPersistentConnections.cs and select Add.
-
Visual Studio will open the MyPersistentConnections.cs file in the main window. Replace the contents with the following code, then save and close the file:
[!code-csharpMain]
-
Using the
Startup
class, the SignalR objects start when OWIN starts up. Open or create Startup.cs and replace the contents with the following code:[!code-csharpMain]
In the code above, the
OwinStartup
attribute marks this class to start OWIN. TheConfiguration
method starts SignalR. -
Test your application in the Microsoft Azure Emulator by pressing F5.
[!NOTE] If you encounter a FileLoadException at MapSignalR, change the binding redirects in web.config to the following:
[!code-xmlMain]
-
Wait about one minute. Open the Cloud Explorer tool window in Visual Studio (View > Cloud Explorer) and expand the path
(Local)/Storage Accounts/(Development)/Tables
. Double-click WADPerformanceCountersTable. You should see SignalR counters in the table data. If you don't see the table, you may need to re-enter your Azure Storage credentials. You may need to select the Refresh button to see the table in Cloud Explorer or select the Refresh button in the open table window to see data in the table. -
To test your application in the cloud, update the ServiceConfiguration.Cloud.cscfg file and set the
Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString
to a valid Azure Storage account connection string.[!code-xmlMain]
-
Deploy the application to your Azure subscription. For details on how to deploy an application to Azure, see How to Create and Deploy a Cloud Service.
-
Wait a few minutes. In Cloud Explorer, locate the storage account you configured above and find the
WADPerformanceCountersTable
table in it. You should see SignalR counters in the table data. If you don't see the table, you may need to re-enter your Azure Storage credentials. You may need to select the Refresh button to see the table in Cloud Explorer or select the Refresh button in the open table window to see data in the table.
Special thanks to Martin Richard for the original content used in this tutorial.