Skip to content

SignalR redis perf : consider sharded pub/sub when available #54344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
mgravell opened this issue Mar 4, 2024 · 2 comments
Open
1 task done

SignalR redis perf : consider sharded pub/sub when available #54344

mgravell opened this issue Mar 4, 2024 · 2 comments
Labels
area-signalr Includes: SignalR clients and servers
Milestone

Comments

@mgravell
Copy link
Member

mgravell commented Mar 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Short version: consider integrating with StackExchange/StackExchange.Redis#2498 (when deployed) to exploit SSUBSCRIBE/SPUBLISH when appropriate

Justification: overall system performance by reducing overheads in redis-cluster (no client-specific performance impact, but the reduced server load should measurably improve overall system throughput - especially in large clusters and where multiple channels are in use, since the number of server-to-server connections is super-linear vs node count)


SignalR on redis makes extensive use of SUBSCRIBE / PUBLISH; on redis vanilla, that is simple, but in "cluster" mode (for highly scalable or redundant environments), these operate in a simple scatter/web mode - which is to say: a subscriber can connect to any server, and a publisher can publish on any server - the server will use inter-node gossip to route the messages everywhere. This is simple and easy, but has additional overheads:

  • lots of inter-server communication to get data everywhere
  • possible unnecessary delays and ordering concerns

These overheads seem directly relevant to high throughput SignalR scenarios.

To reduce these overheads, Redis 7 adds SSUBSCRIBE and SPUBLISH - the sharded variant of pub/sub - without chaos mode. This means that clients need to subscribe and publish using standard routing. Because of the risk of undelivered messages, and the fact that it is Redis 7 only: even though SE.Redis already routes using the channel, we do not default to SSUBSCRIBE / SPUBLISH.

Support for this feature is added in StackExchange/StackExchange.Redis#2498 ; note that you should ideally use configuration and/or feature detection (it has been added to the features API) and switch between RedisChannel.Literal and RedisChannel.Sharded.

Note also that there is a migration caveat: if migrating to enable the use of sharded, then in a hybrid app-cluster (i.e. some nodes updated, some not), the nodes using shaded vs vanilla usage might not cooperate nicely

Describe the solution you'd like

consider using the new API when available

Additional context

  1. note that pattern (glob, wildcard, etc) channel subscriptions cannot be sharded; they must use the web/chaos mode
  2. note that SPUBLISH/SSUBSCRIBE require either a server capability test or an enable/disable toggle (either server-version based, or by attempting SPUBLISH {random guid} {whatever} and observing -ERR unknown command 'spublish')
  3. note that SPUBLISH/SSUBSCRIBE are fine to use on standalone (non-cluster) redis
  4. note that SPUBLISH and PUBLISH are effectively isolated; a client connecting via SUBSCRIBE foo will not get a message published via SPUBLISH foo bar, etc; this means that nodes in an application must agree on the strategy being used

Side note: since this requires a lib bump, you might also want to consider whether enabling RESP3 is appropriate; RESP3 halves the number of sockets required for pub/sub environments; see RESP3 and StackExchange.Redis for more info including necessary considerations

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-signalr Includes: SignalR clients and servers label Mar 4, 2024
@mgravell
Copy link
Member Author

mgravell commented Mar 5, 2024

@davidfowl for curiosity ^^^

@BrennanConroy
Copy link
Member

Any ETA on the feature being added since the PR has been open for almost a year?

@BrennanConroy BrennanConroy added this to the Backlog milestone May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

No branches or pull requests

2 participants