简体   繁体   English

了解node.js pm2启动选项

[英]understand node.js pm2 startup options

pm2 has the following command line options: pm2具有以下命令行选项:

  startOrRestart <json>
  startOrReload <json>
  startOrGracefulReload <json>

but what are the differences between them? 但是它们之间有什么区别?

As far as I understand all start the application(s) if they are not already started. 据我了解,所有尚未启动的应用程序都将启动。 So let's consider the application (an HTTP server) is curently running. 因此,让我们考虑一下应用程序(HTTP服务器)当前正在运行。

I assume restart forces an application to stop and restart it afterwards, and reload would stop accepting new connections, wait for all connections to be handled and then restarts the application. 我假设重新启动会强制应用程序停止并随后重新启动, 重新加载将停止接受新连接,等待所有连接被处理然后重新启动应用程序。 The difference would be that there is no downtime or aborted connections for reload, but apart from that it behaves just as restart (ie code changes are applied). 区别在于没有重新启动的停机时间或连接中断,但除此之外,它的行为就像重新启动 (即应用了代码更改)一样。

Is my assumption correct? 我的假设正确吗? How does startOrGracefulReload differ? startOrGracefulReload有何区别?

The three commands will start your application if it is not already running, so, let's concentrate what happen in the case that it is already running. 如果应用程序尚未运行,这三个命令将启动您的应用程序,因此,让我们集中讨论在其已经运行的情况下发生的情况。

startOrRestart : It will stop all your application in the JSON file and then all of them will be started again. startOrRestart :它将停止JSON文件中的所有应用程序,然后将再次启动它们。 You will have downtime. 您将有停机时间。

startOrReload : As you can read here : startOrReload :您可以在此处阅读:

As opposed to restart, which kills and restarts the process, reload achieves a 0-second-downtime reload. 与重新启动(终止并重新启动进程)相反,重新加载实现了0秒的停机时间重新加载。

So, the main difference is that you will have no downtime. 因此,主要区别在于您将不会停机。

startOrGracefulReload : Again, you can read more here : startOrGracefulReload :同样,您可以在这里阅读更多内容:

Sometimes you can experience a very long reload, or a reload that doesn't work (fallback to restart) meaning that your app still has open connections on exit. 有时,您可能会经历很长的重新加载,或重新加载不起作用(回退到重新启动),这意味着您的应用在退出时仍具有打开的连接。 Or you may need to close all databases connections, clear a data queue or whatever. 或者,您可能需要关闭所有数据库连接,清除数据队列或其他操作。

To work around this problem you have to use the graceful reload. 要变通解决此问题,您必须使用优雅的重新加载。

So, basically pm2 asks your application to exit before reloading it just in case you have dependencies like database connections or pending requests. 因此,基本上pm2要求您的应用程序在重新加载之前退出,以防万一您有数据库连接或未决请求之类的依赖性。 You will have to specify the time that your application needs in order to close all existing connections. 您必须指定应用程序需要的时间才能关闭所有现有连接。 Then, a new process will start and when this new process says " Hey! I am alive! ", then your old process will be ended. 然后,将开始一个新过程,当该新过程显示“ 嘿!我还活着! ”时,旧过程将结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM