php-fpm crash every morning at 7pm (I don't have specific cron at this time), log say :
WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 39 idle, and 180 total children
Server hardware :
nproc : 40
RAM: 256Go
here is www.conf of php-fpm :
[www]
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 350
pm.start_servers = 40
pm.min_spare_servers = 40
pm.max_spare_servers = 70
pm.process_idle_timeout = 60s;
pm.max_requests = 500
request_terminate_timeout = 0
chdir = /
php_flag[display_errors] = off
php_admin_value[error_reporting] = 0
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 1024M
php_admin_value[session.save_path] = /tmp/
I already try to increase max_children value but it change nothing
Related
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.
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.
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?
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
When my server receives many requests php-fpm records (php5-fpm.log) the following:
WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 6 total children
My php-fpm.conf is:
...
pm = dynamic
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 200
...
It seems that you need to change your php-fpm.conf.
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
As php-fpm.log shows,[pool www] seems busy.There are 6 total children and php-fpm will spawn 8 more.It means that there are not enough php-fpm processes. I suggest you increase pm.start_servers,pm.min_spare_servers and pm.min_spare_servers based on your server performance.