新虚拟机上的 PHP-FPM 启动缓慢

新虚拟机上的 PHP-FPM 启动缓慢

我有一个由 Azure VMSS 自动启动的 Ubuntu 18.04 虚拟机。

看来,当虚拟机开启时,PHP-FPM 需要 60 秒才能启动。我原以为 PHP-FPM 启动最多只需几秒。我遇到的一个问题是 Azure 正在交换虚拟机,前 30 秒我收到 502 Bad Gateway 错误,因为 Nginx 正在搜索,php8.1-fpm.sock但由于 FPM 仍在启动,套接字尚未创建。在此转换过程中,我丢失了很多请求。

我的NGINX设置如下:

user = www-data
group = www-data
listen = /run/php/php8.1-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = dynamic
pm.max_children = 35
pm.start_servers = 25
pm.min_spare_servers = 25
pm.max_spare_servers = 30

PHP-FPM 也已启用:

sudo apt-get update
sudo apt-get install -y --no-install-recommends php8.1
sudo apt-get install -y --no-install-recommends php8.1-fpm
sudo apt-get install -y --no-install-recommends php8.1-cli
sudo apt-get install -y --no-install-recommends php8.1-mysql
[...]
sudo systemctl enable php8.1-fpm

我遗漏了什么导致启动时间缓慢?

根据评论要求:PHP8.1-fpm.log

[24-Jan-2022 15:35:37] NOTICE: fpm is running, pid 12619
[24-Jan-2022 15:35:37] NOTICE: ready to handle connections
[24-Jan-2022 15:35:37] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:35:38] NOTICE: Terminating ...
[24-Jan-2022 15:35:38] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:35:38] NOTICE: fpm is running, pid 12719
[24-Jan-2022 15:35:38] NOTICE: ready to handle connections
[24-Jan-2022 15:35:38] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:35:46] NOTICE: Terminating ...
[24-Jan-2022 15:35:46] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:35:46] NOTICE: fpm is running, pid 13226
[24-Jan-2022 15:35:46] NOTICE: ready to handle connections
[24-Jan-2022 15:35:46] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:35:53] NOTICE: Terminating ...
[24-Jan-2022 15:35:53] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:35:54] NOTICE: fpm is running, pid 14275
[24-Jan-2022 15:35:54] NOTICE: ready to handle connections
[24-Jan-2022 15:35:54] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:36:02] NOTICE: Terminating ...
[24-Jan-2022 15:36:02] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:36:02] NOTICE: fpm is running, pid 15050
[24-Jan-2022 15:36:02] NOTICE: ready to handle connections
[24-Jan-2022 15:36:02] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:36:12] NOTICE: Terminating ...
[24-Jan-2022 15:36:12] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:36:12] NOTICE: fpm is running, pid 17053
[24-Jan-2022 15:36:12] NOTICE: ready to handle connections
[24-Jan-2022 15:36:12] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:36:19] NOTICE: Terminating ...
[24-Jan-2022 15:36:19] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:36:19] NOTICE: fpm is running, pid 17527
[24-Jan-2022 15:36:19] NOTICE: ready to handle connections
[24-Jan-2022 15:36:19] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:37:11] NOTICE: Terminating ...
[24-Jan-2022 15:37:11] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:37:11] NOTICE: fpm is running, pid 20214
[24-Jan-2022 15:37:11] NOTICE: ready to handle connections
[24-Jan-2022 15:37:11] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:37:19] NOTICE: Terminating ...
[24-Jan-2022 15:37:19] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:37:19] NOTICE: fpm is running, pid 20683
[24-Jan-2022 15:37:19] NOTICE: ready to handle connections
[24-Jan-2022 15:37:19] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:37:25] NOTICE: Terminating ...
[24-Jan-2022 15:37:25] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:37:25] NOTICE: fpm is running, pid 21229
[24-Jan-2022 15:37:25] NOTICE: ready to handle connections
[24-Jan-2022 15:37:25] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:37:35] NOTICE: Terminating ...
[24-Jan-2022 15:37:35] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:37:35] NOTICE: fpm is running, pid 21650
[24-Jan-2022 15:37:35] NOTICE: ready to handle connections
[24-Jan-2022 15:37:35] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:37:40] NOTICE: Terminating ...
[24-Jan-2022 15:37:40] NOTICE: exiting, bye-bye!
[24-Jan-2022 15:37:40] NOTICE: fpm is running, pid 22117
[24-Jan-2022 15:37:40] NOTICE: ready to handle connections
[24-Jan-2022 15:37:40] NOTICE: systemd monitor interval set to 10000ms
[24-Jan-2022 15:56:00] NOTICE: Terminating ...
[24-Jan-2022 15:56:00] NOTICE: exiting, bye-bye!
[24-Jan-2022 16:16:39] NOTICE: fpm is running, pid 1207
[24-Jan-2022 16:16:40] NOTICE: ready to handle connections
[24-Jan-2022 16:16:40] NOTICE: systemd monitor interval set to 10000ms

systemctl status php8.1-fpm

 php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor prese
   Active: active (running) since Mon 2022-01-24 16:16:41 UTC; 4h 42min ago
     Docs: man:php-fpm8.1(8)
  Process: 1846 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/ph
 Main PID: 1207 (php-fpm8.1)
   Status: "Processes active: 0, idle: 26, Requests: 123, slow: 0, Traffic: 0req
    Tasks: 131 (limit: 4915)
   CGroup: /system.slice/php8.1-fpm.service
           ├─1207 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
           ├─1821 php-fpm: pool www
           ├─1822 php-fpm: pool www
           ├─1823 php-fpm: pool www
           ├─1824 php-fpm: pool www
           ├─1825 php-fpm: pool www
           ├─1826 php-fpm: pool www
           ├─1827 php-fpm: pool www
           ├─1828 php-fpm: pool www
           ├─1829 php-fpm: pool www
           ├─1830 php-fpm: pool www
           ├─1831 php-fpm: pool www
           ├─1832 php-fpm: pool www
           ├─1833 php-fpm: pool www

相关内容