Clustered nodeBB and rolling restarts
-
I'm running clustered nodebB and I noticed that a restart results in a lost connection on the browser. Is there a way to avoid this? My thinking is that a cluster should restart utilizing a "rolling restart" strategy to avoid client disconnects, or at least to minimize the time to reconnect. As it stands, a restart of a clustered instance results in a longer disconnect period than a stand-alone instance. I don't see anything in the docs that covers this, but is nodeBB using the nodejs cluster module?
I can try using PM2 but I suspect that will require modifying the core to use the socket.io aware version of PM2
Is there a way to enable rolling restarts or faster reconnects on clustered nodeBB?
-
The lost connection alert is shown when the socket.io connection is lost which happens when you restart. If you don't want your users to see that you can hide.
We don't use the nodejs cluster module. When you run multiple nodebb processes you need a load balancer like nginx to route traffic based on the clients IP address so socket.io doesn't fail during connection. The restart shouldn't take longer than a few seconds unless you are stopping nodebb running
./nodebb build
and then starting back again. -
@baris Thanks for the reply. The reason I brought up the nodejs cluster module was because it appears that socket.io supports clustering with a single ip address and multiple worker threads (ie Nodejs clustering)
The Cluster adapter allows to use Socket.IO within a Node.js cluster.
Every packet that is sent to multiple clients (e.g. io.to("room1").emit() or socket.broadcast.emit()) is also sent to other workers via the IPC channel.
They also appear to have a cluster adapter for PM2, or more specifically, a version of PM2 that is socket.io aware. I'll experiment with both as it would be really nice to be able to restart with no lost connections.