Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR v2 with load balancer

I am pretty new to SignalR and have been going through some tutorials as I've been tasked with upgrading our current implementation.

We've got an ASP.NET MVC application which uses SignalR (version 1.x). The application is in our F5 load-balanced cloud environment. So we have multiple sites (for different customers) using the same load balancer. To make the SignalR calls servers-side, we use the HubConnection from the Microsoft.ASPNET.SignalR.Client namespace and create a proxy like this (full example here):

var hubConnection = new HubConnection("http://www.contoso.com/");
IHubProxy stockTickerHubProxy = hubConnection.CreateHubProxy("StockTickerHub");
stockTickerHubProxy.On<Stock>("UpdateStockPrice", stock => Console.WriteLine("Stock update for {0} new price {1}", stock.Symbol, stock.Price));
await hubConnection.Start();

Where http://contoso.com/ is the current customer's site URL.

We are looking to upgrade to the latest SignalR (version 2.x) and I am wondering if it is necessary to even use the HubConnection. Even though the article above specifies version 2, it does mention:

This document provides an introduction to using the Hubs API for SignalR version 2 in .NET clients, such as Windows Store (WinRT), WPF, Silverlight, and console applications.

This is a web application with a regular class library back-end for data access. Taking a look at this tutorial, I don't see anything about HubConnection (it also doesn't mention load balancing). Consider the following, from the Chat tutorial:

public class ChatHub : Hub
{
    public void Send(string name, string message)
    {
        // Call the addNewMessageToPage method to update clients.
        Clients.All.addNewMessageToPage(name, message);
    }
}

Then, in Statup.cs:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        // Any connection or hub wire up and configuration should go here
        app.MapSignalR();
    }
}

So my question is, are we using SignalR properly? If not, what considerations/modifications need to be made when running a load-balanced application which uses SignalR (v2.x)? I haven't been able to find much regarding load balancing, etc.

Or is this a job for Groups?

like image 574
lhan Avatar asked Oct 22 '14 19:10

lhan


1 Answers

You don't need to change anything structural. Have a look at the signalr redis scaleout, or any other scaleout option. Basically you need to install an additional package and ms opentech redis to do load balancing. So the scaleout will make sure that each request is sent over a message bus, making multiple servers possible.

like image 139
Elger Mensonides Avatar answered Oct 12 '22 18:10

Elger Mensonides