c# - Does broadcasting to a ASP.NET SignalR group that is empty waste resources? -


if have many client connections part of hub hub_x, not part of specific group group_y, bad practice broadcast() group_y? should keep track of whether or not inside group_y, , check accordingly before broadcasting it?

or signalr no work when detects there no 1 in group_y, , therefore use negligible amount of resources (compared say, having track who's in group myself). ?

broadcasting empty groups describe have overhead, negligible depending on use case.

let's have 100,000 messages process in queue. processing of messages may require send signalr message clients watching data, vast majority of messages have no watchers.

you use message/entity id name of group , execute code every 1 of 100,000 messages:

var hub = globalhost.connectionmanager.gethubcontext(hubname); var group = hub.clients.group(groupname) groupproxy; if (group != null) {     group.invoke(actionname, messagedata); } 

alternatively, if somehow able manage hashset of groups have clients (or have clients) modify code so:

var activegroups = new hashset<string>(); ... if (activegroups.contains(groupname)) {     var hub = globalhost.connectionmanager.gethubcontext(hubname);     var group = hub.clients.group(groupname) groupproxy;     if (group != null)     {         group.invoke(actionname, messagedata);     } } 

this second example seems overkill , introduces complexity of managing activegroups (which can done within custom subclass of hub). furthermore, have expected internally signalr doing this. however, when benchmark 100,000 messages , 0 clients (ie: every group empty) 2.5 seconds on first example , 0.006 seconds on second example. whatever signalr doing internally handle empty groups less efficient hashset lookup.

running first test (the slow one) in visual studio performance profiler confirms of work within internal signalr functions unexpectedly slow compared hashset:

profiler results


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -