1

In our application we need to to send push notifications to a random number of clients. We have no way to create static groups for these users until right before sending the message, since the data is classified and can only be seen by the specific user.

We are trying SignalR to provide the notifications but have some doubts what would be the best way to implement the "Send" method.

We would like to know which one of the following options is the most scalable and performant solution for sending around 20 messages/sec to up to 3000 users that are randomly grouped.

Use the Clients method?

The "Clients" method in the API accepts a list of connection ids

Clients.Clients(clientIds).NewMessage(message);

Send the to each client?

Clients.Client(clientId).NewMessage(message);

Dynamically creating Groups?

We can create groups immediately before we send.

var groupName = Guid.NewGuid().ToString();

foreach (var clientId in clientIds)
{
    await Groups.Add(clientId, groupName);
}

Clients.Group(groupName).NewMessage(message);
  • Is there a way to know if a message was delivered to all the clients that belong to the group? After sending a message to the group we would like/need to delete the group since it will be valid only one time.

Thank you.

Paulo
  • 609
  • 1
  • 11
  • 27

1 Answers1

2

I would go with the dynamically created groups for better performance, but would also look in scaling out. But you still have to keep track of the connections id to your hub.

According to the docs, a group exists only if it has any users:

In effect, a group is automatically created the first time you specify its name in a call to Groups.Add, and it is deleted when you remove the last connection from membership in it.

Unfortunately, SignalR does not guarantee the message delivery. You can implement something like this by yourself, but I would not recommand on waiting for the user to receive the message.


Later Edit

Since you are not going to reuse the groups, it would be an overhead to create them just to deliver one message. If you really have no criteria on how to send the message to the users, it's pointless to group them.

So, most basic thing you can do is a loop through each connection and randomly select the message to be send to that connection. This would also be easier to scale out.

Community
  • 1
  • 1
Florin Secal
  • 931
  • 5
  • 15
  • Thank you for your answer Florin. Regarding the groups, which strategy do you recommend for the deletion? There will be no reuse of groups and we will be creating around 20 groups per second so I think the performance impact of having so many groups in SignalR will be huge. – Paulo May 24 '16 at 07:03
  • Hi Paulo. Groups are deleted when there are no connection to it. – Florin Secal May 24 '16 at 07:59
  • Thanks again Florin. But if any of the users is always connected then I will have all the groups living forever. Don't you think this will cause a performance impact? – Paulo May 24 '16 at 08:26