Open Bubuioc opened 1 week ago
I hope it doesn't sound offensive to you, but if you are using the node:cluster not for an experiment, but for a production app, that means you are doing something wrong. You should have scaling outside of an app, with Kubernetes for example. Node:cluster uses the Round Robin algorithm to balance the load between child processes, and it cannot implement something like sticky sessions
I hope it doesn't sound offensive to you, but if you are using the node:cluster not for an experiment, but for a production app, that means you are doing something wrong. You should have scaling outside of an app, with Kubernetes for example. Node:cluster uses the Round Robin algorithm to balance the load between child processes, and it cannot implement something like sticky sessions
I am not a devops and have just some basic skills and knowledge about this(little of docker, github actions and some core priciples of kubernetes).But i have a personal server and i want my node app to run into cluster mode, because it is more efficient and I think is better than running multiple container or pods of same app on one server. PS:About your struggling of offensive thing: I created this issue to get help from people that are better than me, so any idea or any help is welcome, so, thanks a lot for your implication!
Okay, look, the scaling of your app should be done outside of it, if we are talking about real world production scenarios. By outside, I mean by increasing the number of Docker containers with your app. Cluster mode is scaling inside the app which is wrong in most scenarios, because:
But if you still decide to go with the cluster approach, instead of the containers approach, I recommend you to get familiar with PM2, but I'm not sure if it has the sticky sessions functionality. BTW why do you need the sticky sessions?
I have been using PM2 for a very long time (even before docker) and it does work with sticky sessions under nginx, which are useful for websocket connections.
That being said I do acknowledge that docker clustering is the best way.
I have been using PM2 for a very long time (even before docker) and it does work with sticky sessions under nginx, which are useful for websocket connections.
That being said I do acknowledge that docker clustering is the best way.
Do you listen for each process to a new port?
No, this is the advantage of node cluster, it's all in one port, so the nginx configuration is quite simple.
No, this is the advantage of node cluster, it's all in one port, so the nginx configuration is quite simple.
Can you provide nginx configuration for cluster mode?
Something like
location ~ ^/socket.io/ {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
I mean, since there is no real clustering, there is only one port, and NodeJS does the "clustering" internally.
I mean, since there
I tried this, isn't working as you said here is one port.
Something like
location ~ ^/socket.io/ { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache_bypass $http_upgrade; }
I mean, since there is no real clustering, there is only one port, and NodeJS does the "clustering" internally.
But I resolved it with pm2, I assign for each thread a new port ex:3000-3011 and setup sticky with nginx.
Is there an existing issue for this?
Current behavior
Please someone. How can i implement sticky session for a Nest app running in cluster mode.The Nest docs have no info about this and Socketio have no docs for nest(.I have posted a question on Socketio github discussions and Nest discord but nothing.I already implemented adapter but the sticky sessions from @socket.io/sticky i can't setup.Maybe someone did this.
Minimum reproduction code
a
Steps to reproduce
No response
Expected behavior
This is main.ts
and this is redis streams adatper
Package
Other package
No response
NestJS version
No response
Packages versions
Node.js version
No response
In which operating systems have you tested?
Other
No response