Add Native Node.js Cluster Mode Support #9679
Replies: 1 comment
-
After a deeper analysis of the problem, it has become clear that my initial assumption in the feature request was incorrect. It appears the true cause of the EADDRINUSE error is not the lack of a native Node.js cluster module in the Keystone code. Instead, the problem seems to be related to the use of the npm start command as the entry point for PM2. PM2's clustering mechanism cannot properly manage the application processes when the script is launched via npm. This additional layer of abstraction prevents PM2 from correctly passing sockets, which prevents the application from being clustered, even though PM2 has built-in cluster support. Since adding the cluster module to Keystone is not necessary, I would like to ask for your advice regarding the best solution. Could you please suggest how to create a proper entry point for Keystone that can be used directly with PM2? What is the recommended approach to bypass the npm start command and ensure seamless scaling of the application in PM2's cluster mode? I would be grateful for any recommendations. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
When running a Keystone application with process managers like PM2 in
cluster
mode, the application fails to start multiple instances due to a port conflict. The errorEADDRINUSE: address already in use
occurs because thekeystone start
command does not utilize the native Node.jscluster
module to handle multiple workers listening on the same port.This forces developers to use more complex workarounds, such as running the application in PM2's
fork
mode with a reverse proxy like Nginx to handle load balancing.Describe the solution you'd like
I propose modifying the
keystone start
command to automatically detect if it is running in a cluster environment. If so, it should use the Node.jscluster
module to manage multiple worker processes.This would allow multiple Keystone instances to run on a single machine, sharing the same port, and taking full advantage of all available CPU cores.
Describe alternatives you've considered
Currently, the only viable solution for scaling Keystone on a single machine is to use a reverse proxy (e.g., Nginx) in conjunction with PM2's
fork
mode, with each process assigned a unique, hard-coded port. This workaround is functional but adds unnecessary complexity and setup overhead.Beta Was this translation helpful? Give feedback.
All reactions