Can "active processes" be larger than "max_children" for PHP-FPM - php

Having set the pool to static with max_children to 5 I would expect the metric "active processes" to be 5 or below. Sending 10 concurrent requests will have "active processes" report more than 5 (e.g. 10, 12, 25, ...).
Is this valid behaviour?
Pool configuration:
# grep -v ";" /usr/local/etc/php-fpm.d/www.conf | grep -Ev "^$"
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
pm = static
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.process_idle_timeout = 10s
pm.max_requests = 500
pm.status_path = /status
ping.response = pong
slowlog = log/$pool.log.slow
request_slowlog_timeout = 0
request_terminate_timeout = 0
Expected result:
Metric "active processes" from /status should be below 5.
Actual result:
Metric "active processes" from /status is above 5.

According to the PHP FPM documentation when pm is set to static the only setting that determines the number of child processes is pm.max_children. As you expect, that should determine the start and max number.
A couple things to consider:
After changing the configuration did you restart both PHP-FPM and NGINX ? Something like:
sudo service php-fpm5 restart
sudo service nginx restart
Is it possible you are altering the wrong config file (perhaps one that is in the wrong path?). You might try changing some other value and confirm that it is affecting the web server as intended.
Is it possible that you have multiple pools configured and that the /status page is giving you a report for multiple pools.

Related

Website with php 7.3 fpm running into 503 Service Unavailable after 24h

We are currently working on a small web app and we ran into an issue. The error keeps occuring and we got kind of stuck.
503 service Unavailable
No server is available to handle this request.
What we use:
PHP 7.3 fpm mode
apache2
VMWare, Machine with debian 9, 2cpu/2cores and 16gb RAM
We currently have about 70 users on the website. After about 24h the server keeps crashing.
after restarting the php service the website works again. So I'm guessing the issue has something to do with php and not with apache.
according to other sources this issue might be caused because of opcache or max sessions / max child config.
www.conf:
[www]
user = www-data
group = www-data
listen = /run/php/php7.3-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 50
pm.start_servers = 12
pm.min_spare_servers = 8
pm.max_spare_servers = 24
pm.max_requests = 1000
php.ini: https://pastebin.com/JanEHinF
any ideas what could cause the error?

PHP-FPM child processes eating RAM

I have a relative busy web server with Nginx and PHP-FPM, and after a upgrade to PHP 7.2 I have noticed PHP-FPM processes are eating all my RAM after some time.
The server is a KVM machine (Centos 7) with 32Gb of RAM and 8Gb swap:
[root#www ~]# free
total used free shared buff/cache available
Mem: 32779736 18397204 239372 1508476 14143160 12417824
Swap: 8257532 167680 8089852
Here you can see the memory consumption:
https://justpaste.it/2vaqy
(I tried to paste it here, but Stackoverflow says my post looks spam)
As you can see in RSS colum, in 4th March each php-fpm process is using about ~1Gb of RAM, that makes a total memory comsuption (22 processes) of 22Gb.
Each PHP-FPM process ram usage is incrementing about ~300Mb per day.
This is my configuration:
[root#www ~]# cat /etc/php-fpm.conf | sed '/^;/d' | sed '/^$/d'
include=/etc/php-fpm.d/*.conf
[global]
pid = /run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm/error.log
daemonize = yes
[root#www ~]# cat /etc/php-fpm.d/www.conf | sed '/^;/d' | sed '/^$/d'
[www]
user = www
group = www
listen = xxxxx/php-fpm.sock
listen.mode = 0666
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 200
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.status_path = /xxxx-fpm
slowlog = /var/log/php-fpm/www-slow.log
request_terminate_timeout = 5h
php_flag[display_errors] = off
php_admin_value[error_log] = xxxx/php-fpm-error.log
php_admin_flag[log_errors] = on
This is my phpinfo:
https://justpaste.it/50zin
Any idea on whats going on?
Thank you in advance. Regards.
This looks simple, if you have memory leaks, you must re-spawn php worker as many as possible, this can be configured with pm.max_requests option.
Start with 500, the more is the best performance you have but the more leak as well.

PHP-FPM processes not dying after reaching process_idle_timeout

I have a setup of nginx + php-fpm on my server.
FPM's pool configuration looks like this:
[www]
user = root
group = root
listen = /run/php-fpm.sock
listen.owner = root
listen.group = root
pm = ondemand
pm.max_children = 50
pm.process_idle_timeout = 10s
pm.max_requests = 500
pm.status_path = /server-status
catch_workers_output = yes
My first expectation is, that no child php-fpm processes are started unless there's an incoming request. Unfortunately, when I start php-fpm I promptly see 2 processes:
10 ? S 0:00 php-fpm: master process (/etc/php/7.1/fpm/php-fpm.conf)
37 ? S 0:00 php-fpm: pool www
So, one process is pre-forked for some reason.
My second expectation is that all processes idling for more than 10s will be killed. I run a test which results in the creation of 13 processes. After 1 minute or so (no more requests performed) around 5 processes are idling. Why is it so?

PHP5-FPM goes to 100% cpu usage and doesn't go down

Please check the following image:
Output of: htop -u www-data
My current configuration of pool.d/www.conf is:
pm = ondemand
pm.max_children = 4
pm.process_idle_timeout = 10s;
pm.max_requests = 50
It's a 4 core cpu with 8gb ram. Ram usage is considerably less. If I have set max_children = 4, does that mean it there can be only 4 processes? (In screenshot, there are more than 8 php-fpm processes)
And sometimes, it just stays at 100% in all 4 cores and website gives a 502 error till I restart php5-fpm.

PHP-FPM: don't process multiple requests in one moment

I had VPS with CentOS 6.4 64bit. There is running Nginx 1.4.4 and PHP-FPM 5.5.6. I'm trying to make long-polling requests. However, if server is already processing one request, he doesn't respond to other. This mean, that if I have script with:
sleep(60);
PHP doesn't process other request. I must wait for 60 seconds. PHP status page is:
pool: www
process manager: dynamic
start time: 26/Nov/2013:22:02:00 +0100
start since: 148
accepted conn: 170
listen queue: 0
max listen queue: 0
listen queue len: 128
idle processes: 1
active processes: 49
total processes: 50
max active processes: 49
max children reached: 1
slow requests: 0
And je conf.d/www.conf:
[www]
listen.allowed_clients = 127.0.0.1
user = apache
group = apache
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
pm.status_path = /status
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache

Categories