Skip to content

Latest commit

 

History

History
147 lines (83 loc) · 11.1 KB

using-signalr-performance-counters-in-an-azure-web-role.md

File metadata and controls

147 lines (83 loc) · 11.1 KB
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

Using SignalR performance counters in an Azure Web Role

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.

Prerequisites

Creating an Azure Web Role application that exposes SignalR performance counters

  1. Open Visual Studio.

  2. In Visual Studio, select File > New > Project.

  3. 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.

    New Cloud Application

    [!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.

    Azure development workload in Visual Studio Installer

  4. 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.

    Add ASP.NET Web Role

  5. In the New ASP.NET Web Application - WebRole1 dialog, select the MVC template, and then select OK.

    Add MVC and Web API

  6. In Solution Explorer, open the diagnostics.wadcfgx file under WebRole1.

    Solution Explorer diagnostics.wadcfgx

  7. Replace the contents of the file with the following configuration and save the file:

    [!code-xmlMain]

  8. 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]

  9. 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.

    Add Startup Folder

  10. 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.

  11. In Solution Explorer, right-click the Startup folder and select Add > Existing Item. In the dialog that appears, select signalr.exe and select Add.

    Add signalr.exe to project

  12. 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.

    Create SignalR performance counter installation batch file

  13. 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]

  14. Select the signalr.exe file in Solution Explorer. In the file's Properties, set Copy to Output Directory to Copy Always.

    Set Copy to Output Directory to Copy Always

  15. Repeat the previous step for the SignalRPerfCounterInstall.cmd file.

  16. Right-click on the SignalRPerfCounterInstall.cmd file and select Open With. In the dialog that appears, select Binary Editor and select OK.

    Open with Binary Editor

  17. In the binary editor, select any leading bytes in the file and delete them. Save and close the file.

    Delete leading bytes

  18. Open ServiceDefinition.csdef and add a startup task that executes the SignalrPerfCounterInstall.cmd file when the service starts up:

    [!code-xmlMain]

  19. Open Views/Shared/_Layout.cshtml and remove the jQuery bundle script from the end of the file.

    [!code-cshtmlMain]

  20. Add a JavaScript client that continuously calls the increment method on the server. Open Views/Home/Index.cshtml and replace the contents with the following code:

    [!code-cshtmlMain]

  21. 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.

    Adding SignalR Hub Class to the Hubs folder in the Add New Item dialog

  22. MyHub.cs will automatically open in the main window. Replace the contents with the following code, then save and close the file:

    [!code-csharpMain]

  23. 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.

  24. 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]

  25. 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. The Configuration method starts SignalR.

  26. 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]

  27. 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.

    Selecting the WAD Performance Counters Table in Visual Studio Cloud Explorer

    Showing the counters collected in the WAD Performance Counters Table

  28. 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]

  29. 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.

  30. 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.