I have been looking at various solutions around but when I put it all together, it looks very confusing.
I am trying to implement pm2 cluster mode for my application which has socket.io implementation. Now, I understand the concept that statelessness is required in order to make my app work properly in cluster mode. And socket.io is NOT stateless. The confusion is,
1) Our friend Cam says that just implementing socket.io-redis
would work fine when we'll spawn on the maximum number of CPUs.
2) While socket.io says and I quote,
Note: sticky-session is still needed when using the Redis adapter."
For 1), According to my research, Internet should disagree that it would work. Maybe Mr. Cam got lucky to have transport method as websocket
and might not had to deal with polling
. But at the same time I think it should work, since redis-adapter
is what we are using to make it stateless.
INFO: It worked for me with websocket
as transport method but I couldn't test it with polling
.
For 2), I think we can combine Mr. Joni's advice to run it with "pm2" IN "cluster" but on different ports. And then our beloved nginx
's upstream
group with ip_hash
would give us kind of same effect.
Additionally, I want to make my application elastic. NOT just on cluster level but both scale up and out. What are the best practices given that my application included socket.io implementation and session token management in redis
?
Am I missing something or am I totally wrong here? Which would be the best way to scale?
pm2 scale
and incrementing port number as perNODE_APP_INSTANCE
; using Redis, of course; listing all hosts and ports in nginx upstream; works well. – Bludgeon