php-fpm Troubleshooting

PHP Optimierungen für Nextcloud

Das Fehlerbild im PHP Logfile (/var/log/php8.0-fpm.log):

[05-Mar-2020 05:10:04] WARNING: [pool www] server reached pm.max_children setting (35), consider raising it
[05-Mar-2020 06:04:52] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers)

Feststellen, ob das „max_children limit“ schon des Öfteren erreicht wurde:

(1)
grep max_children /var/log/php8.0fpm.log.1 /var/log/php8.0-fpm.log

Feststellen, wie groß der verfügbare RAM (2) und der durchschnittliche verbrauchte „pool size“ Speicher (4) ist:

(2)
free -h | awk '/Mem/{print $2}'

Anzeige aller FPM-Prozesse:

(3)
ps -ylC php-fpm8.0 --sort:rss

Durchschnittlicher und einzeln verbrauchter Prozess-Speicher:

(4)
ps --no-headers -o "rss,cmd" -C php-fpm8.0 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
(5)
ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep php-fpm

Berechnung des Wertes für die max_children basierend auf RAM

pm.max_children = Gesamter RAM des Servers / Durchschnittliche „child process“ Größe aus (4)

Annahme:
RAM aus (2): 8GB abzgl. 1GB „Puffer“ für das Restsystem = 7168MB
Durchschnittlicher Wert aus (4): 75 MB

(6)
pm.max_children = 7168MB / 75MB  = 95

Wir reduzieren den Wert (6) von 95 auf 90, um Reserven für das System zu belassen. Darauf basierend optimieren wir die PHP-Konfiguration:

exemplarische Optimierung/Konfiguration:

sudo vi /etc/php/8.0/fpm/pool.d/www.conf
; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives:
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;
;             pm.start_servers     - the number of children created on startup.
;                                    this value must not be less than min_spare_servers 
;                                    and not greater than max_spare_servers.
;
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
; Note: This value is mandatory.
pm = dynamic
pm.max_children = 90
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 30
pm.max_requests = 1000

Nextcloud empfiehlt:

pm = dynamic
pm.max_children = 120
pm.start_servers = 12
pm.min_spare_servers = 6
pm.max_spare_servers = 18

Starten Sie PHP neu

systemctl restart php8.0-fpm.service

und genießen Ihre sichere Nextcloud und ihr optimiertes PHP 8.0. Eine Liste aller von mir empfohlenen PHP-Optimierungen finden Sie hier.

Über Ihre Unterstützung (diese wird ordnungsgemäß versteuert!) würden sich meine Frau, meine Zwillinge und ich sehr freuen!