locked
SignalR client methods limit RRS feed

  • Question

  • User-1013488000 posted

    Hello,

    We plan to have several client methods in a SPA with one hub. Is there a max number of client methods to have as listeners?

    They will be triggered by the hub.

    Regards

    Tuesday, February 19, 2019 4:50 PM

Answers

  • User61956409 posted

    Hi rvidaurri,

    1 client connected to a hub = 1 connection, right? Regardless of the number of client methods to be invoked from the server using that opened websocket channel.

    If the "client" here is a connection object that you create and use to establish the connection by calling start method, the answer would be YES.

    On the other hand, in a browser client, if you connect from multiple browser windows or tabs, multiple connections would be established.

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 21, 2019 9:02 AM
  • User475983607 posted

    There is one connection per client regardless of the number of methods.  The linked documentation and my first post explains that the methods are invoked by sending the function name (string) to the client over the connection.  

    More importantly to understand is the server cannot open a connection with a client.  Every client would need a static IP, DNS, firewall rules etc for this to work.  SignalR (Web Sockets) solves this exact problem by creating persistent connection between the client and server application.

    This concept is covered quite extensively in the linked documentation.  If you have not read the docs, then this is a good time to do so.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 21, 2019 3:41 PM

All replies

  • User475983607 posted

    We plan to have several client methods in a SPA with one hub. Is there a max number of client methods to have as listeners?

    They will be triggered by the hub.

    The SignalR docs cover the technical details for the version you are using.  The default is 5000 concurrent connections for ASP.NET 4.0.

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/introduction-to-signalr

    https://docs.microsoft.com/en-us/aspnet/signalr/overview/performance/signalr-performance

    https://github.com/SignalR/SignalR/wiki/Performance

    ASP.NET Core

    https://docs.microsoft.com/en-us/aspnet/core/signalr/scale?view=aspnetcore-2.2

    https://docs.microsoft.com/en-us/aspnet/core/signalr/scale?view=aspnetcore-2.2

    Tuesday, February 19, 2019 5:05 PM
  • User-1013488000 posted

    I meant the JavaScript functions (client methods).

    E.G.: I load a page and connect to a hub, and host 50 client methods. API will trigger any of those 50 client methods from the server.

    Is there a limit for those client methods?

    In my example, I established one connection only to the hub, correct? or every client method is also a connection?

    Tuesday, February 19, 2019 7:53 PM
  • User475983607 posted

    I meant the JavaScript functions (client methods).

    E.G.: I load a page and connect to a hub, and host 50 client methods. API will trigger any of those 50 client methods from the server.

    Is there a limit for those client methods?

    In my example, I established one connection only to the hub, correct? or every client method is also a connection?

    SignalR uses the web socket browser API to persist a connection between the browser and the server (Hub).  Messages flows between the browser and Hub through the web socket connection.  

    Example code and explaination from the docs.

    https://docs.microsoft.com/en-us/aspnet/core/signalr/javascript-client?view=aspnetcore-2.2

    public async Task SendMessage(string user, string message)
    {
        await Clients.All.SendAsync("ReceiveMessage", user, message);
    }

    SignalR determines which client method to call by matching the method name and arguments defined in SendAsync and connection.on.

    Tuesday, February 19, 2019 8:13 PM
  • User-1013488000 posted

    "SignalR uses the web socket browser API to persist a connection between the browser and the server (Hub).  Messages flows between the browser and Hub through the web socket connection."

    So, 1 client connected to a hub = 1 connection, right? Regardless of the number of client methods to be invoked from the server using that opened websocket channel.

    Regards

    Wednesday, February 20, 2019 12:13 AM
  • User475983607 posted

    So, 1 client connected to a hub = 1 connection, right? Regardless of the number of client methods to be invoked from the server using that opened websocket channel.

    Please re-read my previous post and the link.  The method name is sends messages RPC style to the client which invokes the method.

    SignalR determines which client method to call by matching the method name and arguments defined in SendAsync and connection.on.

    I recommend building a demo.

    Wednesday, February 20, 2019 1:25 AM
  • User61956409 posted

    Hi rvidaurri,

    1 client connected to a hub = 1 connection, right? Regardless of the number of client methods to be invoked from the server using that opened websocket channel.

    If the "client" here is a connection object that you create and use to establish the connection by calling start method, the answer would be YES.

    On the other hand, in a browser client, if you connect from multiple browser windows or tabs, multiple connections would be established.

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 21, 2019 9:02 AM
  • User-1013488000 posted

    correct, that's what I meant

    for example, a client connects to the hub via one Chrome tab:

    JavaScript:

    $.connection.hub.start()
       .done(function () {
          conn.server.join({ Group: groupId }).done();
       });

    and has 2 client methods:

    conn.client.getMessage = function (response) {
       DoSomething(response);
    };

    conn.client.getReminder = function (response) {
       More(response);
    };

    that's still one connection, and not 3 because of the 2 client methods, correct?

    if our server invokes getMessage() and getReminder() simultaneously every minute, that's still one connection?

    I hope I was clear enough.

    Thanks

    Thursday, February 21, 2019 2:20 PM
  • User475983607 posted

    There is one connection per client regardless of the number of methods.  The linked documentation and my first post explains that the methods are invoked by sending the function name (string) to the client over the connection.  

    More importantly to understand is the server cannot open a connection with a client.  Every client would need a static IP, DNS, firewall rules etc for this to work.  SignalR (Web Sockets) solves this exact problem by creating persistent connection between the client and server application.

    This concept is covered quite extensively in the linked documentation.  If you have not read the docs, then this is a good time to do so.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 21, 2019 3:41 PM
  • User-1013488000 posted

    More importantly to understand is the server cannot open a connection with a client.  Every client would need a static IP, DNS, firewall rules etc for this to work.  SignalR (Web Sockets) solves this exact problem by creating persistent connection between the client and server application.

    Thank you both.

    I am aware of that. I've seen and mantained implementations of SignalR in live sites since its version 1.1.2. Scaled out with a SQL database. However, regretfully, I had never taken the time to fully understand how connections were counted. 

    My confusion began when I reviewed Azure SignalR Service pricing. It was confusing for me: 1 unit = 1000 concurrent connections, 1 million messages per day. 

    Now I understand that they mean 1000 connected clients regardless of client methods which could receive up to 1 million messages per day, for that pricing. 

    Thursday, February 21, 2019 6:31 PM