74

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.

Ayan
  • 8,192
  • 4
  • 46
  • 51

1 Answers1

105

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.

robertklep
  • 198,204
  • 35
  • 394
  • 381
  • 2
    So restart first kills then starts whereas reload first starts then kills? – XCS Jul 03 '17 at 10:55
  • @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. – robertklep Jul 03 '17 at 10:57
  • @robertklep So why should restart be used at all?Is there any use case where restart can be more beneficial than reload? – Ayan Jul 03 '17 at 12:04
  • 1
    @Ayan perhaps `restart` is faster, and if you don't care about 0-second downtime it might be preferable. – robertklep Jul 03 '17 at 12:09
  • From the documentation, `reload` should be used always with [stateless applications](https://pm2.io/doc/en/runtime/guide/load-balancing/#stateless-application). It is also documented now that `reload` will fallback to `restart` after a timeout. – Javier Elices Feb 28 '19 at 11:04
  • Conclusion: always use `reload`! – João Pimentel Ferreira Mar 30 '20 at 14:07
  • 2
    The 2nd link has changed to https://pm2.io/docs/runtime/guide/load-balancing/ – Qiulang Apr 19 '22 at 03:04
  • @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`. – bfontaine Aug 11 '23 at 10:54