简体   繁体   English

php-fpm如何使用动态流程管理器管理工作人员?

[英]How php-fpm manages workers with dynamic process manager?

I would like to clarify how php-fpm manages workers with dynamic process manager. 我想澄清php-fpm如何使用动态流程管理器管理工作人员。

Let's assume we have following config: 我们假设我们有以下配置:

pm = dynamic
pm.max_children = 100
pm.start_servers = 30
pm.min_spare_servers = 20
pm.max_spare_servers = 60
  1. when php-fpm starts, it spawns 30 processes 当php-fpm启动时,它会产生30个进程
  2. there are no connections. 没有联系。 Will the php-fpm shut down 10 workers according to min_spare_servers setting? 根据min_spare_servers设置,php-fpm会关闭10名工作人员吗? If yes, after what time will it happen? 如果是,在什么时候会发生?
  3. There are 40 connections to nginx. 有4个与nginx的连接。 Will php-fpm serve each connection with separate worker, and immediately spawn additional workers to satisfy remaining connections? php-fpm会与单独的worker一起服务每个连接,并立即产生额外的worker来满足剩余的连接吗?
  4. There are 80 connections to nginx. 有8个连接到nginx。 How will php-fpm behave after it has launched 60 workers? php-fpm在推出60名工作人员之后会如何表现? The same as in (3)? 和(3)中的相同?
  5. There are 120 connections to nginx. 有120个与nginx的连接。 What happens after assigning 100 workers to 100 connections? 将100名工人分配到100个连接后会发生什么? Does php-fpm use some queue for the connections? php-fpm是否使用某些队列进行连接? Will it limit nginx? 它会限制nginx吗? Will php-fpm start dropping connections with message " server reached pm.max_children setting "? php-fpm会开始删除与“ 服务器达到pm.max_children设置 ”消息的连接吗?
    1. There are 50 connections to nginx. 有0个与nginx的连接。 Will nginx go back to 60 connections from 100? nginx会从100回到60个连接吗? Or to 50? 还是50? Will it immediately kill 40 workers or will it wait some time? 它会立即杀死40名工人还是会等待一段时间?

As you see, this is rather a generalized question about how php-fpm manages processes. 如你所见,这是关于php-fpm如何管理进程的一个普遍问题。 More specifically, I would like to understand the difference between pm.max_children and pm.max_spare_servers in php-fpm. 更具体地说,我想了解php-fpm中pm.max_childrenpm.max_spare_servers之间的区别。

First of all, let's assume that instead of nginx connection we speak about connection/request to upstream, that php-fpm serves. 首先,让我们假设我们谈到上游的连接/请求,而不是nginx连接,php-fpm服务。

  1. there are no connections. 没有联系。 Will the php-fpm shut down 10 workers according to min_spare_servers setting? 根据min_spare_servers设置,php-fpm会关闭10名工作人员吗? If yes, after what time will it happen? 如果是,在什么时候会发生?

No, according to my test, master process does not terminate extra workers according to min_spare_servers number. 不,根据我的测试,主进程不会根据min_spare_servers数终止额外的工作。 Probably, it is good practice to specify start_servers equal to min_spare_servers . 可能最好将start_servers指定为min_spare_servers

  1. There are 40 connections to nginx. 有4个与nginx的连接。 Will php-fpm serve each connection with separate worker, and immediately spawn additional workers to satisfy remaining connections? php-fpm会与单独的worker一起服务每个连接,并立即产生额外的worker来满足剩余的连接吗?

Correct, simultaneous connections to php-fpm will be served with separate worker. 与php-fpm的正确,同时连接将与单独的工作人员一起提供。 If number of requests is more than start_servers master process will fork additional workers ( fpm_children_make call), up to max_spare_servers . 如果请求数超过start_servers主进程将分叉额外的worker( fpm_children_make调用),最多为max_spare_servers

  1. There are 80 connections to nginx. 有8个连接到nginx。 How will php-fpm behave after it has launched 60 workers? php-fpm在推出60名工作人员之后会如何表现? The same as in (3)? 和(3)中的相同?

It will fork as many workers as necessary to process all requests simultaneously, until it will reach max_children number; 它将根据需要分配尽可能多的工作人员以同时处理所有请求,直到它达到max_children数; fpm master process performs maintenance every second ( fpm_pctl_perform_idle_server_maintenance call): if number of spawned workers are more than max_spare_servers , workers in idle state will send SIGCHLD signal to master process ( fpm_got_signal and fpm_children_bury calls). fpm主进程每秒执行一次维护( fpm_pctl_perform_idle_server_maintenance调用):如果生成的worker的数量超过max_spare_servers ,处于空闲状态的fpm_got_signal fpm_children_bury主进程发送SIGCHLD信号( fpm_got_signalfpm_children_bury调用)。

  1. There are 120 connections to nginx. 有120个与nginx的连接。 What happens after assigning 100 workers to 100 connections? 将100名工人分配到100个连接后会发生什么? Does php-fpm use some queue for the connections? php-fpm是否使用某些队列进行连接? Will it limit nginx? 它会限制nginx吗? Will php-fpm start dropping connections with message "server reached pm.max_children setting"? php-fpm会开始删除与“服务器达到pm.max_children设置”消息的连接吗?

Correct, you will follow message in debug mode: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers 更正,您将在调试模式下关注消息: seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers

  1. There are 50 connections to nginx. 有0个与nginx的连接。 Will nginx go back to 60 connections from 100? nginx会从100回到60个连接吗? Or to 50? 还是50? Will it immediately kill 40 workers or will it wait some time? 它会立即杀死40名工人还是会等待一段时间?

All workers in idle state will be terminated, and master process will stop termination after number max_spare_servers is reached. 处于空闲状态的所有工作程序将被终止,并且在达到max_spare_servers数量后,主进程将停止终止。
Parameters min_spare_servers and max_spare_servers are responsible for min and max numbers of workers that can be alive in idle state at the same time. 参数min_spare_serversmax_spare_servers负责同时处于空闲状态的工作的最小和最大数量。


In order to understand dipper, try to turn on debug logging in php-fpm.conf : ... error_log = /var/log/php5-fpm/fpm-daemon.log ... log_level = debug ... Follow log file: tail -f /var/log/php5-fpm/fpm-daemon.log and use Apache benchmark tool ab to understand behavior. 为了理解dipper,尝试打开php-fpm.conf调试日志: ... error_log = /var/log/php5-fpm/fpm-daemon.log ... log_level = debug ...关注日志文件: tail -f /var/log/php5-fpm/fpm-daemon.log并使用Apache基准工具ab来理解行为。

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

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