-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[QUESTION] How to migrate a Master/Worker App #3934
Comments
You can simply start your run.js with pm2. But I think it has 2 drawbacks :
So what you should do :
|
@wallet77 thanks a lot for your suggestion. I think I should use the second approach you mention, because my application loads several frameworks that need data to be loaded once into memory so I cannot have one instance for each worker. That is why I have used the master to serve these frameworks and data loaded into memory once and the workers all the other apis.
In that case how pm2 will handle the incoming / outgoing requests from worker app to master app? |
It really depends on what you want to achieve. With PM2 you don't have the same flexibility as with cluster module, because pm2 act as the master and your apps is a worker. |
@wallet77 thank you 👍 , I think a have the big picture now. Considering that I load resources into the master in memory and listening on port 3001 here, while the workers exposes endpoint to the rest of the world and do queries to the master from port 3000, I could run two pm2 instance anyways for each of them I assume i.e. the two pm2 services will run on different ports (3000 & 3001) and communicate via |
closing because it's almost clear how it should work. To recap I would have two different app, one for the master and one for the worker, on different ports, both of them wrapped into PM2. |
My app has a master/worker Node.js clustering architecture.
Basically my run script
run.js
is likeI'm starting both on the master and the workers node a HTTP server. While the workers are listening on port 3000, the master is listening on port 3001, that will be mapped to 8080 on a docker container instance:
Thus, a dispatcher API listening on WORKER at PORT 3001 will forward requests to the port 3000 on the MASTER when needed (e.g. for services running on the master instance only).
All MASTER / WORKER nodes shares the same codebase, but some modules are loaded once on the MASTER, while other modules duplicated on all the WORKER modules, hence I have something like:
How to migrate this architecture to PM2? Shall I change it? May I bypass the
run.js
above, or can I just use as-it-is and passing therun.js
to PM2 as a service?The text was updated successfully, but these errors were encountered: