Skip to content

Use pattern matching at the namespace level#217

Merged
darrachequesne merged 4 commits intosocketio:masterfrom
darrachequesne:perf/namespace-matching
May 10, 2017
Merged

Use pattern matching at the namespace level#217
darrachequesne merged 4 commits intosocketio:masterfrom
darrachequesne:perf/namespace-matching

Conversation

@darrachequesne
Copy link
Member

This follows #46. Each node will now listen to only three channels:

  • socket.io#<namespace>#*: used when broadcasting
  • socket.io-request#<namespace>#: used for requesting information (ex: get every room in the cluster)
  • socket.io-response#<namespace>#: used for responding to requests

We keep the benefits of #46 since:

  • messages from other namespaces are ignored
  • when emitting to a single room, the message is sent to
    socket.io#<namespace>#<my-room>, so listeners can check whether they
    have the room before unpacking the message (which is CPU consuming).

But there is no need to subscribe / unsubscribe every time a socket
joins or leaves a room (which is also CPU consuming when there are
thousands of subscriptions).

This follows socketio#46. Each node will now listen to only three channels:

- `socket.io#<namespace>#*`: used when broadcasting
- `socket.io-request#<namespace>#`: used for requesting information (ex: get every room in the cluster)
- `socket.io-response#<namespace>#`: used for responding to requests

We keep the benefits of socketio#46 since:

- messages from other namespaces are ignored
- when emitting to a single room, the message is sent to
  `socket.io#<namespace>#<my-room>`, so listeners can check whether they
  have the room before unpacking the message (which is CPU consuming).

But there is no need to subscribe / unsubscribe every time a socket
joins or leaves a room (which is also CPU consuming when there are
thousands of subscriptions).
@darrachequesne darrachequesne merged commit 05f926e into socketio:master May 10, 2017
@darrachequesne darrachequesne deleted the perf/namespace-matching branch May 10, 2017 23:28
@darrachequesne darrachequesne added this to the 5.0.0 milestone May 10, 2017
@ryan-arimus
Copy link

So, as a consequence of this change (not subscribing to specific rooms, but instead to generic namespaces). The result will be that EVERY client will get EVERY message correct? While, I see that you're checking before you unpack the message, there is no way to horizontally scale this at some point. The overhead of receiving/checking every message from every client on the entire system seems to be a big problem for apps with high workloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments