php fpm pool options (must understand this part)
Php fpm pool manager Static vs dynamic vs ondemand
upload_max_size = 8M
post_max_size = 8M
upload_max_filesize = 8M
max_execution_time = 180
max_input_time = 500
Deciding max Children Limit
; static –
; dynamic –
ondemand –
php fpm calculator / calculation process
php fpm Static pool manager
php – fpm pool manager Dynamic
php fpm pool ondemand settings best for beginners low memory consumption;
fixing php-fpm pool high cpu usage
available memory in LEMP stack
4GB
1GB for MySQL, 512MB for linux, 1GB for nginx
2.5GB (1.5GB,
php max memory limit (128MB or 256MB)
max execution time 60s or 300s 1 minute or 5 minutes
slow query log threshold 1s.
static: pool manager
php fpm max requests
Determining Average memory usage per process
root@instance-1:~# ps –no-headers -o “rss,cmd” -C php-fpm7.4 | awk ‘{ sum+=$1 } END { printf (“%d%s\n”, sum/NR/1024,”M”) }’
283M
root@instance-1:~# systemctl restart php7.4-fpm
root@instance-1:~# ps –no-headers -o “rss,cmd” -C php-fpm7.4 | awk ‘{ sum+=$1 } END { printf (“%d%s\n”, sum/NR/1024,”M”) }’
29M
root@instance-1:~# ps –no-headers -o “rss,cmd” -C php-fpm7.4 | awk ‘{ sum+=$1 } END { printf (“%d%s\n”, sum/NR/1024,”M”) }’
96M
root@instance-1:~# ps -ef | grep ‘[f]’pm
root 216323 1 0 15:48 ? 00:00:00 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
www-data 216333 216323 0 15:48 ? 00:00:01 php-fpm: pool www
www-data 216334 216323 0 15:48 ? 00:00:02 php-fpm: pool www
www-data 216335 216323 0 15:48 ? 00:00:01 php-fpm: pool www
www-data 216336 216323 0 15:48 ? 00:00:00 php-fpm: pool www
www-data 216337 216323 0 15:48 ? 00:00:00 php-fpm: pool www
www-data 216338 216323 0 15:48 ? 00:00:02 php-fpm: pool www
www-data 216339 216323 0 15:48 ? 00:00:00 php-fpm: pool www
www-data 216340 216323 0 15:48 ? 00:00:00 php-fpm: pool www
RSS contains the average memory usage in kilobytes per process.
S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD
S 0 24439 1 0 80 0 6364 57236 – ? 00:00:00 php-fpm
S 33 24701 24439 2 80 0 61588 63335 – ? 00:04:07 php-fpm
S 33 25319 24439 2 80 0 61620 63314 – ? 00:02:35 php-fpm
enable php fpm slow query log
slowlog = /var/log/php-slow.log
request_slowlog_timeout = 10s
or
slowlog = /var/log/$pool.log.slow (no need to worry about wordpress plugin update requests)
equest_slowlog_timeout = 10s
uncomment the lines in /etc/php/7.3/fpm/pool.d/www.conf
Deciding the Slow query threshold if you updates wordpress plugins it takes times,
if you upload 8MB files its takes time.
Best php query time for wordpress is ….? (wordpress load in 1-3 secs) (php execution time time , request terminate timeout ).
restart or reload php fpm
enable php from status page to better understand
Monitoring Requests in with php fpm log
[16-Dec-2020 09:30:29] WARNING: [pool www] server reached pm.max_children setting (40), consider raising it
Php Fpm 7.3 On dynamic Settings
pm = dynamic
pm.max_children = 60 (max child process based on memory max memory if 128*60=7680MB in upper limit)
40*128=5120MB if every request uses 128MB memory.
max children value:
pm.start_servers value
; Default Value: min_spare_servers + (max_spare_servers – min_spare_servers) / 2
8+(10-6=4)/2 = 12/2=6
pm.start_servers = 8 (4*number of cores on server = 8)
pm.min_spare_servers = 6 (2*Cpu core =4
pm.max_spare_servers = 10 (4*Cpu cores =8) // Generally idea 2x memory required for cpu cores general tasks.
pm.max_requests = 5000
upgrading
pm.start_servers = 10
pm.min_spare_servers = 12
pm.max_spare_servers = 20
4+(20-4=16)/2=10 (pm.start_servers)
;pm.process_idle_timeout = 10s; //on demand only
check php fpm syntax errors without reload or restart
php fpm fool dynamic vs ondemand vs static
php.ini settings
php fpm pool high cpu wordpress cpu panel
this is due to long time running process, you can mitigate by php fpm status page
php memory limit for per process * number of process = memory & high cpu usage.
Average cpu memory usage by process
ps aux | grep php
Solution: increase workers or decrease php workers
or decrease process execution time based on environment
mitigate: ddos attacks install WAF firewall to protect layer 7,
php fpm status last request cpu time
1285.35
process is not in Idle state because CPU calculation is done when the request
processing has terminated)