-
-
Notifications
You must be signed in to change notification settings - Fork 757
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
Scaling Docs #327
Comments
|
AFAICT sticky sessions (on the application level) are required to support long-polling connections and the general Socket.io handshake when running the application with Node.js' cluster features. If I got this right, |
That can be solved with what is described how to use Socket.io in a Cluster though right? Feathers doesn't do anything that should interfere with that module. |
Yes, @daffl. However, using sticky-session is not recommended as per https://github.com/primus/primus#can-i-use-cluster I've ended up setting up a simple haproxy with sticky-sessions capabilities in front of my processes, and it is now working fine. Here is my simple config:
I've just tweaked the sample haproxy.cfg file to include what I needed. Mind the commented lines. Also, if you're using pm2 to manage your app in cluster mode (making the most out of your machine's cpu cores), make sure you're now launching it in N (N = cpu cores) different processes, each with its respective port, and all in 'fork' mode instead of 'cluster'. This clustered mode was what got me into problems in the first place... As for the time being, pm2 does not allow sticky-sessions at its application level: Unitech/pm2#389 Hoping someone finds this helpful... |
Using the fork mode is not always desirable. If used properly, the cluster mode will create the same number of processes as CPU cores, thus maximizing the resources utilization. This does not happen in fork mode! So, the cluster mode is the option to go for performance and the recommended configuration for production. |
Please have a look at: Unitech/pm2#1510 Some people are mentioning about changing the ports of each process created by pm2 cluster mode, which is wrong, we should not change the ports. pm2 is able to share the same port across multiple processes (thanks to Nodejs cluster mode). I'm still having issues with pm2 cluster mode and feathers-sync. |
@averri I have solved the PM2 + Feathers combination issue by disabling long-polling as a fallback when using socket.io. Documented here: The issue is that even if you can somehow configure IP-based sticky sessions in the pm2 cluster, it would only work if you are directly receiving HTTP requests on your server. As soon as you put your server behind a load balancer (e.g. in an autoscaling config) the IPs of all requests coming to your servers would have the load balancer's IP. So the only solution for now is to disable long-polling as the feathers docs suggest. |
Does a sticky session solution (let's say running in pm2 cluster mode) account for a single user being authenticated from multiple workstations? For instance a user logs in and is added to a channel Assuming the above is all working as I presume, does the redis implementation of feathers-sync successfully address this concern? TL;DR we run a very reactive app where there is an expectation that all changes are persisted to (n) environments in near realtime. We also run a high number of concurrent connections so the ability to scale the feathers server is highly desirable. Looking to test redis implementation soon. UPDATE: Just implemented feathers sync on a single dual core debian instance. Running my pm2 cluster has 2 instances (1 per core) and I've verified multiple tabs of my site connect on each of the 2 running instances. Events are all working as I would expect on a single instance setup of feathers/socket.io. So far no gotchas and was very easy to setup with a local redis instance. |
I already found a lot of hints about how to get a Feathers application scaled (e.g. in #157) but haven't had any luck yet getting it working with Socket.io (plain REST works smoothly). Am I right, that using
feathers-sync
does not circumvent the necessity of Sticky Sessions (on the LB & the node processes themselves) to enable Socket.io's handshakes? My current use case is usingpm2
to simply launch the application in cluster mode: e.g.pm2 start src/index.js -i 4 -f
.What additional steps are required to get Feathers with Socket.io working "seamlessly" across several processes or physical resources? Is there a reliable solution to make Session-Handling more stateless using a Redis-Adapter for both express' and Socket.io's sessions?
The text was updated successfully, but these errors were encountered: