What is the difference between pm2 restart and pm2 reload
Asked Answered
P

1

79

I have a nodejs app running on server.

When should I use pm2 restart,and when should pm2 reload be used?

Referred to the pm2 documention here,but couldn't figure out the difference in use case of the two.

Proprioceptor answered 3/7, 2017 at 10:27 Comment(0)
C
110

The difference is documented here:

As opposed to restart, which kills and restarts the process, reload achieves a 0-second-downtime reload.

The latter means (found here):

With reload, pm2 restarts all processes one by one, always keeping at least one process running.

It also states that:

If the reload system hasn’t managed to reload your application, a timeout will fallback to a classic restart.

Cath answered 3/7, 2017 at 10:54 Comment(8)
So restart first kills then starts whereas reload first starts then kills?Goosefish
@Cristy I'd think so, yes. I also assume that if it can't restart a worker, reload will keep the old worker running, so it wouldn't be noticable.Cath
@Cath So why should restart be used at all?Is there any use case where restart can be more beneficial than reload?Proprioceptor
@Proprioceptor perhaps restart is faster, and if you don't care about 0-second downtime it might be preferable.Cath
From the documentation, reload should be used always with stateless applications. It is also documented now that reload will fallback to restart after a timeout.Bingaman
Conclusion: always use reload!Femmine
The 2nd link has changed to pm2.io/docs/runtime/guide/load-balancingMedeiros
@JoãoPimentelFerreira not really: always use it if you are in cluster mode and your app is stateless. If you are not in cluster mode then both commands are the same, and if you are but your application is stateful then reload will break it so you must use restart.Immaculate

© 2022 - 2024 — McMap. All rights reserved.