Non-Sticky Session Support
Hi -
So I've been reading a lot about engine.io and the socket.io 1.0 release recently, and I am really excited to upgrade my production app to 1.0 instead of 0.9.17. However, I need non-sticky session support. We are using Heroku for our hosting, and they do not support sticky sessions which caused all sorts of 400 Bad Request errors when I attempted to upgrade at first.
I don't mean to come off accusatory, but is there a reason for requiring sticky sessions when not all load balancers will support them?
We currently run a server that uses both express and socket.io in each process, and in 0.9.17 it uses Redis to remove the need for sticky sessions. We find that this style works well, because the socket.io servers scale horizontally at the same rate that the node servers do.
From my understanding of sticky sessions, it seems that it essentially causes each users requests to hit a specific process/server for the entirety of the browsing session. This seems like it would counteract the idea behind horizontal scaling though, because the new server(s) brought in would not receive an equal load, and the previously initialized servers would stay at high capacity, potentially hindering performance because the sessions are stuck to that server.
Basically, I'm looking for input and options. The way I see it, we essentially have three options, none of which are ideal.
The first option is to remain on socket.io 0.9.17, which still does the websocket-first approach which is not ideal since a fair portion of our users are on networks that do not support websockets, and there appears to be a memory leak associated with < 1.0.
The second option is to abstract away the socket.io cluster and make an Amazon Elastic Beanstalk (EB) app for the socket servers because EB supports sticky sessions. This however drives up costs for us of course, and we have had bad luck with running Node.js on EB before.
The last option is to somehow convince you guys at Automattic to bake in some kind of support for non-sticky sessions that use Redis as an intermediary layer. This will probably be a hard argument to make, but the added operational complexity should be low if the non-sticky session support is added as a fallback option that requires passing in a Redis client.
So what do all of you think? Should we suck it up and stick with 0.9.17, abstract away to a new server cluster, or is there any chance of adding non-sticky session support to engine.i?
Several points:
- If you use SSL you will find that websockets pass on almost all networks (I have never seen them fail), including mobile. Thus I would strongly recommend to always use SSL with socket.io and engine.io
- If you insist on using Heroku, then you can use an external load balancer (e.g. haproxy) to effectively create sticky sessions to your Heroku servers.
- Frankly, using Redis for pub/sub on all messages in order to scale never made sense to me. As you scale your app, your back-end messages will increase exponentially (since you have more servers sending messages to more servers.... ouch......). So while this may seem a more "fair" way to scale, all you're doing is introducing more (unnecessary) load to your cluster. You will eventually reach a point where your entire cluster chokes on backend messages instead of serving clients.
- To add to the previous point - without sticky sessions you will need to load per-client session data on numerous servers - yet another ouch.
Bottom line: sticky sessions are a good thing. Strongly suggest you use them, not work against them.
SSL is a good thing, but there can still be server middleware that breaks the connection once it's decrypted.
It's also not a reasonable expectation for our users.
Agreed on sticky session being a good thing, but we need to figure out a solution for our heroku users. — Sent from Mailbox
On Thu, Jun 12, 2014 at 7:09 AM, mokesmokes [email protected] wrote:
Several points:
- If you use SSL you will find that websockets pass on almost all networks (I have never seen them fail), including mobile. Thus I would strongly recommend to always use SSL with socket.io and engine.io
- If you insist on using Heroku, then you can use an external load balancer (e.g. haproxy) to effectively create sticky sessions to your Heroku servers.
- Frankly, using Redis for pub/sub on all messages in order to scale never made sense to me. As you scale your app, your back-end messages will increase exponentially (since you have more servers sending messages to more servers.... ouch......). So while this may seem a more "fair" way to scale, all you're doing is introducing more (unnecessary) load to your cluster. You will eventually reach a point where your entire cluster chokes on backend messages instead of serving clients.
- To add to the previous point - without sticky sessions you will need to load per-client session data on numerous servers - yet another ouch.
Bottom line: sticky sessions are a good thing. Strongly suggest you use them, not work against them.
Reply to this email directly or view it on GitHub: https://github.com/Automattic/engine.io/issues/261#issuecomment-45895722
@guille external LB with stickiness based on client IP, for example, should do the trick. My provider (Modulus) does sticky sessions based on query param, for example (if I want to override the client IP stickiness).
For LBs that support TCP mode that should be fine, but the ones that don't understand the request will simply break it (Squid being a fairly common occurrence)— Sent from Mailbox
On Thu, Jun 12, 2014 at 7:20 AM, mokesmokes [email protected] wrote:
@guille external LB with stickiness based on client IP, for example, should do the trick.
Reply to this email directly or view it on GitHub: https://github.com/Automattic/engine.io/issues/261#issuecomment-45897201
I think supporting Redis flooding in engine.io is way too complex. It's not just the messages - but also heartbeats, etc - and all that complexity just to support a scaling architecture that is problematic to start with..... -1 from my point of view.
-1 from me as well, this should be solved in higher level abstractions such as https://github.com/topcloud/socketcluster
I don't intend to support it within the core codebase for sure— Sent from Mailbox
On Thu, Jun 12, 2014 at 7:31 AM, Arnout Kazemier [email protected] wrote:
-1 from me as well, this should be solved in higher level abstractions such as https://github.com/topcloud/socketcluster
Reply to this email directly or view it on GitHub: https://github.com/Automattic/engine.io/issues/261#issuecomment-45898774
@mokesmokes your points about flooding Redis are good points which i didn't address in my original post, but is why I expected the non-sticky sessions to not be supported by default in the core codebase.
Regarding your point about the external LB, that will not work with Heroku as far as I know. We are given a url (https://appname.herokuapp.com for example) to point to, and Heroku has a LB behind that that we cannot modify or bypass, so I think that breaks the HAproxy suggestion.
What I'm getting out of this conversation is that I essentially need to run socketcluster (or something like it) as a separate application on a service like Amazon EB that does support sticky sessions. Is that what the general consensus is?
I have a open ticket with Heroku support and am communicating with one of their engineers about this as well, and I hope between the Heroku team and the community here we can figure something out that will work for all Heroku users and can potentially be added to the readme or upgrade instructions.
It seems that Heroku is starting to support websockets: https://devcenter.heroku.com/articles/heroku-labs-websockets, however it's unclear to me if there will be sticky sessions for polling requests. Regarding using a LB: if you don't have a URL per server, you can try using a different app name per server. Or of course use a PAAS provider which supports sticky sessions and websockets - there's no lack of these.
Their websokects lab works perfectly, and we have been using it in conjunction with socket.io 0.9.17 for some time now. It's just the newly required stickiness that causes the problems.
As of right now, Heroku is not planning to add stickiness to their LB, as it has not really been an issue until now.
If you have a suggestion for another PAAS provider that bundles everything up nicely like Heroku does, I would welcome the suggestion, but no one else I have found integrates with 3rd party add ons and controls the app deployment process so well.
@guille any update on this? Sorry to be such a pain, but socket.io/engine.io is a critical part of my application and being able to upgrade to 1.0.x would be great.
Hi,
Me too it's a blocking issue, I talk with Heroku support that tell me engine.io will never support sticky less loadbalancer.
If engine.io is not compatible with heroku and not compatible with out of the box nodejs cluster mode it's a breaking bad news for nodejs community.
I think it's a major missing feature for the first worldwide socket framework!
What is the amount a work about support this feature? Can we help?
Le 21 juin 2014 à 23:42, TIm Costa [email protected] a écrit :
@guille any update on this? Sorry to be such a pain, but socket.io/engine.io is a critical part of my application and being able to upgrade to 1.0.x would be great.
— Reply to this email directly or view it on GitHub.
I still think you Heroku fans are trying to fit a square peg in a round hole. Socket.io, engine.io et. al exist in order to support long-lived, bi-directional communication. Heroku does not seem to want to support long-lived client-server connections (besides websockets), unlike many other vendors that do. Use the vendor that answers your overall needs best.
@mokesmokes, all due respect, but this is a real issue and if you have nothing meaningful to add to this conversation other than telling us to use other hosting providers or rewrite part of our servers, please stay out of it. This support used to exist, and all we are asking is that support for one of the leading Node.js hosting platforms be added back in.
On Jun 21, 2014, at 6:31 PM, mokesmokes [email protected] wrote:
I still think you Heroku fans are trying to fit a square peg in a round hole. Socket.io, engine.io et. al exist in order to support long-lived, bi-directional communication. Heroku does not seem to want to support long-lived client-server connections (besides websockets), unlike many other vendors that do. Use the vendor that answers your overall needs best.
— Reply to this email directly or view it on GitHub.
Support for this will not be added back in via redis (this adds more complexity to the app to maintain for those that do not have this problem).
One way to possibly solve this nicely is to provide a hook into the pre-handled but parsed request that allows the developer to bypass engine.io handling the message and maybe pass it off to some other engine instance. I am not familiar enough with the internals to know off the top of my head if such a hook is possible without a major re-organization.
Yes, deploying on heroku is popular but their lack of sticky support is also a choice. There are many tradeoffs in what platform you select and what you are able to accomplish with that platform. It is unreasonable to expect that a project support any arbitrary technology decision of another company (but certainly popular technologies do get more votes and eyeballs for support). I think the best course of action for you @tjsail33 is to create a PR (or several) that shows some possible ways your problem can be fixed. The reason you are not getting much love in this thread is because none of the maintainers or top contributors have this problem personally and thus will not likely set out to fix it (the code for it was removed because it caused other problems and it was decided that maintaining it was not worth it in the core).
I agree that lack of sticky support is a choice, but for some applications it makes sense. My application has about 9 peak hours during the day where there are frequent scaling operations, both up and down. During the scaling events during those 9 hours of peak usage, using sticky sessions has two main effects:
- During a scale down, any users logged in to the server being removed are suddenly cut off and forced to log back in to another server. Obviously this is not good UX, and needs to be avoided.
- During a scale up, load is not moved away from the servers that are experiencing high load. Scaling events are triggered when server response times increase above an "acceptable" value, and adding another server does absolutely nothing to relieve stress when sticky sessions are enabled, except for any new sessions may be created.
My application uses socket.io/engine.io for all of the real time functionality in it, which is every single part of the page. It would be nice to be able to continue supporting functional scaling that decreases load on existing servers, and be able to scale down without breaking off the sessions of some users. I understand that this is an implementation choice of the creator and collaborators if socket.io and engine.io, but I simply think that there should be some option, be it an adaptor, plugin, whatever you want to call it, that supports using Redis or something else as the back end because using sticky sessions simply isnt ideal for every single app. It doesn't even really have to do with hosting provider. It has to do with what configuration leads to the ideal responsiveness of the app being written.
I will look into a PR or adaptor or whatever, but personally I have very little experience dealing with this type of system and I do not know how "ideal" the code I could come up with would be, and I really think that some sort of native support would be great.
And yes, I understand that it is not all about my use case and my application. But I am not the only person who has a real time app behind a log in mechanism who would like to be able to scale servers freely without causing a poor experience for the end user.
We're looking into adding hooks to make it possible to retrieve and alter state outside-of-process. We'll need to see what sort of complexity it adds to the codebase.
@tjsail33 +1 on what @defunctzombie said: as a contributor to this project, and not just a user, I can rightfully feel concerned about what appears to me to be a major complication to the code base, if I believe there are better alternatives. As to the technical points you raise, those can be solved via other means, without shoehorning the project into stateless connections:
- On a scale down, your clients should just see a
closeevent (which can always happen for example due to a transport error), and they should perform a standard reconnect. I assume that this basic functionality should be done without a new login being forced on the user. Reconnection and client/server logic is outside the scope of engine.io. - During the scale-up, you're (wrongfully) assuming that connections will be randomly spread following the scale-up event. This is not necessarily the case. For example - some vendors allow you to specifically name the server you wish to target with new requests. Some will take server load (# connections) into account. Or you can construct such a policy by yourself using a LB. Or you can gradually close connections on the loaded server, which will cause a reconnect that may be spread to other servers, etc.
In general - it's certainly possible for disconnections and reconnections to be 100% transparent to your users, without modifying engine.io. This is what most of us are doing.
Yeah, I think the discussion is wrongfully getting diverted to UX manifestations that are not linked to the low level networking implications of sticky load balancing. For example, if a connection is very quickly re-established, you most likely don't want to bother the user by telling them the app is reconnecting. In the same vein, you don't want to block input by the user anyways, and you most likely want to render their interactions optimistically. I blogged about this here.
UX aside, we do need a solution for our Heroku users, and we do want to maintain a simple codebase. We're looking into trying to achieve both.
There are frameworks for pub/sub (such as Faye), which may be more suitable for a Heroku-like architecture. Engine.io shouldn't be all things to all people on all possible platforms, IMHO.