All about process managers

Eddie Cheng
Feb 27, 2021

Pm2

Fork mode

  • A basic process spawning
  • Allows to change the exec_interpreter, so that you can run a php or a python server with pm2.
  • Multiple servers could be launched on pre-established ports which will then be load-balanced by HAProxy or Nginx.

exec_interpreter is the “command” used to start the child process.

By default, pm2 will use node so that pm2 start server.js will do something like:

require(‘child_process’).spawn(‘node’, [‘server.js’])

Cluster mode

  • only work with node as it’s exec_interpreter because it will access to the nodejs cluster module (eg: isMaster, fork methods etc.).
  • The process will automatically be forked in multiple instances (great for zero-configuration process management).
E.g.
pm2 start -i 4 server.js
// will launch 4 instances of server.js and let the cluster module handle load balancing.

reference

[1] Cluster and Fork mode difference in PM2 (2016)

--

--

Eddie Cheng

「0」が過去で「1」が未来「今」は何処にもない