我们可以在不打扰其他人的情况下重新加载 PHP-FPM 池之一吗

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16890855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:51:27  来源:igfitidea点击:

Can we reload one of the PHP-FPM pool without disturbing others

php

提问by kaychaks

I've multiple PHP-FPM UNIX socket pools for the same host to have logical separation of codebase / functionality & to address future scaling of the same. Nginx manages the routing to the right socket based on URI patterns. Deployment is working fine.

我有多个 PHP-FPM UNIX 套接字池用于同一主机,以实现代码库/功能的逻辑分离并解决未来的扩展问题。Nginx 基于 URI 模式管理到正确套接字的路由。部署工作正常。

Whenever I change pool configuration for any one, I am reloading / restarting the FPM process (by USR2 signal).

每当我更改任何一个的池配置时,我都会重新加载/重新启动 FPM 进程(通过 USR2 信号)。

I don't have any idea about how the internals of FPM work but I assume that as I restart the main process, all pools get restarted / reloaded. Please correct me if I'm wrong.

我不知道 FPM 的内部是如何工作的,但我假设当我重新启动主进程时,所有池都会重新启动/重新加载。如果我错了,请纠正我。

I want to know if I could reload / restart only one pool when others work as they were (no issues in the undergoing transactions on those pools).

我想知道我是否可以在其他池正常工作时重新加载/重新启动一个池(这些池上正在进行的事务没有问题)。

I would also appreciate any other configuration suggestions which could allow me to have desired pool management

我也很感激任何其他配置建议,这些建议可以让我拥有所需的池管理

回答by regilero

php-fpmallows for a graceful restart of childs, usually with the reloadkeyword instead of restarton the init script, sending USR2 signal.

php-fpm允许正常重启子进程,通常使用reload关键字而不是restart初始化脚本,发送 USR2 信号。

So by doing a graceful restartyou should not loose any running transaction. The children are killed after the end of the current request management for each of them. This should be enoughif you do not need a real restart. I made some tests and for example a reload is enough to :

因此,通过正常重启,您不应丢失任何正在运行的事务。在当前对每个孩子的请求管理结束后,孩子会被杀死。如果您不需要真正重新启动,这应该足够了。我做了一些测试,例如重新加载就足以:

  • empty the APC cache
  • alter log file path
  • alter min/max/start child settings
  • 清空 APC 缓存
  • 更改日志文件路径
  • 更改最小/最大/启动子设置

So I did not find a case where a need a real restart yet. Except that a reload cannot start a stopped service.

所以我还没有找到需要真正重启的情况。除了重新加载无法启动已停止的服务

If you want to ensure other pools will never be reloaded when you want to reload one of them you will have to manage several php-fpm daemons and one pool per daemon. This implies writing several init scripts and master configuration files.

如果您想确保在重新加载其中一个池时永远不会重新加载其他池,则必须管理多个 php-fpm 守护程序和每个守护程序一个池。这意味着编写几个初始化脚本和主配置文件。

Using the restart keyword is more dangerous, especially because the init script is maybe killing long running children in the stop step. And with several daemons managed with several PID and configuration files you could even get a start-stop-daemoncommand with --execoption (that's the case in debian) and this would kill all the daemons running the same php-fpm executable (effectively sending a kill -9 to all the other parallel php-fpm daemons after stopping the right one with the right PID if you run several php-fpm processes, which is very bad).

使用 restart 关键字更危险,尤其是因为 init 脚本可能会在停止步骤中杀死长时间运行的子进程。并且使用多个 PID 和配置文件管理多个守护进程,您甚至可以获得start-stop-daemon带有--exec选项的命令(在 debian 中就是这种情况),这将杀死所有运行相同 php-fpm 可执行文件的守护进程(有效地向所有进程发送 kill -9如果您运行多个 php-fpm 进程,则在使用正确的 PID 停止正确的守护进程后,其他并行 php-fpm 守护进程,这是非常糟糕的)。

So using the reload keyword (USR2 signal) is a must.

所以使用 reload 关键字(USR2 信号)是必须的。