description PM2-cluster Overview
PM2-cluster is an extension of PM2 designed specifically to utilize all available CPU cores for Node.js applications. It automatically manages worker processes, ensuring that if one worker crashes, the others continue serving traffic while the failed one is restarted. This is crucial for maximizing throughput and maintaining uptime under heavy load for JS backends.
help PM2-cluster FAQ
How do I enable PM2 cluster mode for my Node.js app?
Run pm2 start app.js -i max to spawn one worker per CPU core, or pass a specific number of instances instead of max. PM2 is the free, open-source Node process manager (from the company behind PM2.io) and cluster mode is its headline feature.
What's the difference between pm2 reload and pm2 restart in cluster mode?
pm2 reload performs a rolling restart that replaces workers one at a time for zero-downtime deploys, while pm2 restart takes the whole app down and back up at once. Always use reload in cluster mode when serving live traffic.
Does PM2 cluster mode work on Windows?
Not reliably — cluster mode relies on Node's cluster module and is effectively unsupported on native Windows, so the usual advice is to run PM2 under WSL2 or in a Linux Docker container. This is a common gotcha for developers on Windows laptops.
How do I add or remove workers later and see individual worker logs?
Use pm2 scale app +2 (or -2) to change worker count on the fly, and pm2 logs to stream merged output — each worker is tracked by its own process id and online status. pm2 monit gives a live CPU/memory view of every worker.
explore Explore More
Similar to PM2-cluster
ui.x_see_all arrow_forwardReviews & Comments
Write a Review
Be the first to review
Share your thoughts with the community and help others make better decisions.