-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Research/Documentation: sails.sockets.* methods in a multi-node environment #6457
Comments
After many careful deliberations, we've come to the following conclusions:
The proposal we'll be moving forward with is to implement three new methods in the
These will be implemented using a refactored admin bus that communicates with Redis directly, rather than connecting via
to subscribe all sockets in room A to room B, regardless of what node the sockets are connected to. Of the methods currently in |
Well said 👏 |
@sgress454 re: join and leave, while the recommended usage should become the socket id (to encourage a purely multi-node API), I think we can safely leave support for passing in |
…methods Added code in admin bus handler to forward certain messages to those functions refs #19
The refactored admin bus has been published with v0.13.2. The new methods are:
All are documented in the 0.12 branch of sails-docs. In addition, I also refactored the The one caveat with all this is that in multi-server environments, you'll want to do a |
@sgress454 I'd rather we avoid recommending setTimeout, and instead explain the situation in notes (eg join/leave are not guaranteed to have taken effect- or are "volatile" in the same way as broadcast) |
You just need something to broker the messages. var io = require('socket.io-emitter')({ host: '127.0.0.1', port: 6379 });
setInterval(function(){
io.emit('time', new Date);
}, 5000); Sticky load balancing is of course required if you use long polling, which is up to you to support. If you want greater support of clients and networks, you use long polling, which requires that messages are "tied" in some way. |
Something important to mention: we're very interested in expanding the capabilities of the adapter so that subscriptions to rooms can also be managed "remotely" in the same way you can "emit" remotely. |
Thanks @rauchg! We've added basic mention of sticky load balancing to our docs since we upgraded to sio 1.0, but I think there's def room for more conceptual documentation on what that means in the context of socket.io. If you know any good tutorials you trust about setting up the lb ( nginx/haproxy or better yet for heroku/azure/AWS) I'd be down to put together a coalesced tutorial. I'd say it's the biggest source of confusion for folks when they're going to production, just because it's usually a new thing they haven't had to deal with before. |
@rauchg re: re: expanding the adapter capabilities--sounds great! FWIW, the solution we implemented would be easy to incorporate directly into |
@sgress454 reckon we're ready to upgrade internally and start trying this out in production in an rc? |
@mikermcneil sure! |
I'm currently experiencing this problem, or something pretty close to it, and am looking for a solution. All socket rooms are empty when using @sgress454 - Did I understood your comment above correctly, that this issue has been fixed in the latest v0.12 version? If so, then maybe I'm doing something wrong, because I'm still experiencing the problem in v0.12.0-rc8. |
@BigstickCarpet This issue was opened to explore the use of things like |
You can preview 0.12 docs here: http://next.sailsjs.org/documentation/reference/web-sockets/sails-sockets |
v0.12 of Sails has been released along with new docs, including a section on realtime programming with multi-server environments. I think we can put this one to bed! |
RE: deprecated http://sailsjs.org/documentation/reference/web-sockets/sails-sockets/sails-sockets-rooms |
@crobinson42 we recommend this because room crud is something that almost always includes a need to store additional info-- eg the timestamp when the room was created, when sockets joined it, etc. (Ends up being cleaner to implement with your models) |
To start with, we need to verify:
.emit()
in socket.io truly works in a multi-node environment (my understanding presently is that it works sometimes depending on server configuration (see http://socket.io/docs/using-multiple-nodes/#sticky-load-balancing).subscribers()
works in a multi-node environment (pretty sure this one is always a "no" because of how the socket.io redis adapter works)Originally posted in:
#3008 (comment)
The text was updated successfully, but these errors were encountered: