https://gist.github.com/holmberd/44fa5c2555139a1a46e01434d3aaa512?permalink_comment_id=3143513

Диагностика и настройка параметров php-fpm в связке с nginx

Текущие значения можно увидеть так:

php-fpm -tt

Определяем - не упирамся ли мы в лимит max_children ??

  sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log

Определяем - не упирамся ли мы в память:

  free -h

Для всех процессов php:

ps -ylC php-fpm7.0 --sort:rss

Средняя загрузка:

ps --no-headers -o "rss,cmd" -C php-fpm7.0 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'

Суммарная загрузка памяти процессами php:

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

Вычисляем оптимальный размер max_children Based on RAM

  pm.max_children = Total RAM dedicated to the web server / Max child process size
  System RAM: 2GB
  Average Pool size: 85Mb
  pm.max_children = 1500MB / 85MB = 17

Based on average script execution time

  max_children = (average PHP script execution time) * (PHP requests per second)
  visitors = max_children * (seconds between page views) / (avg. execution time)

Configure

sudo vim /etc/php/7.0/fpm/pool.d/www.conf

pm.max_children = 17
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_request = 1000

; 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.
Enter your comment. Wiki syntax is allowed:
 
  • devops/php-fmp-nginx-performance-diags.txt
  • Last modified: 2023/07/21 10:46
  • by admin