Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP-FPM をもっと理解しよう

98937658ef5be1bba2a9bff8d1026226?s=47 naoki85
December 15, 2018

PHP-FPM をもっと理解しよう

PHPアプリケーションが動いているサーバーがメモリ不足でアラートがあがる。どうやらphp-fpmがメモリを消費しているようだ。その時は付け焼き刃でphp-fpmの設定値を調整して対応したが、改めてちゃんと理解したいと思った。 そんな私とあなたに向けた内容(注:知識を整理したい方向けの予定です)

98937658ef5be1bba2a9bff8d1026226?s=128

naoki85

December 15, 2018
Tweet

Transcript

  1. PHP-FPM  2018 12 15 @PHP Conference 2018  Zaim

    naoki85
  2. naoki85 •  Zaim: 2017 10 •   naoki85_201612

    PHP Ruby 
  3. 800      

  4. Zaim     https://blog.zaim.co.jp

  5. 

  6. Zaim Zabbix  Slack    Slack  

    
  7. …  

  8.   PHP-FPM     FPM 

  9.  &"! $#'   PHP 7  $# 

      %
  10.      … …

  11. PHP     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 42 total children  
  12.   PHP-FPM    

  13.  http://php.net/manual/ja/install.fpm.php

  14.  % https://qiita.com/kotarella1110/items/634f6fafeb33ae0f51dc  $   ! #" 

    
  15. CGI _Common Gateway Interface` "#)&/(*-%,+IW03 PC B=8PV_$,! .'`ZJ A \[

     &/(*-%,+:3B= >9QOD $,! .'\5 1S4 &/(*-%,+2*-%,+ <7  6NTG$,! .'\5 FLUH  @M &/(*- %,+?^*-%,+]EL;K CGI  Wikipedia  PHP@XTGWeb&/(/[ $,! . 'YR 
  16. Fast CGI CGI27'7bV J-5)(XLZRa"! FfbV!> -5)(XLZRHN !  +,$7.6(KB^ 

    FastCGI-5)(#0148U]YdA  dA[: Og# @W \Q -5%3/A<eJD8&7*c`;9C_ P?-5)( Ha !Th-5)(0148G] ]SbVI -5)(Ha  Wikipedia  -5)(#014=M SEHaeJ#
  17. Web%%2ApacheNginx3 ❖Apache ❖Nginx l !"%#+  PHP,1 - */ 

    l Web%%)& $ PHP' 2CGI ,1(.3 l CGI  PHP $0' 
  18. ࣮ࡍʹࢼͤͳ͍ͩΖ͏͔ɻɻ!

  19. ϩʔΧϧͰ/HJOY 1)1'1. Λ;BCCJYͰ؂ࢹ͢Δαϯϓϧ https://github.com/naoki85/monitor_php_with_zabbix

  20. • docker • Zabbix Alpine Linux   • Nginx

    • PHP-FPM ϩʔΧϧͰ/HJOY 1)1'1. Λ;BCCJYͰ؂ࢹ͢Δαϯϓϧ
  21. 

  22. ςετʹ͸ "QBDIF#FODIΛ࢖༻ https://httpd.apache.org/docs/2.4/programs/ab.html ex) ab -n 1000 -c 10 http://127.0.0.1/

  23. ϩάͳͲͷઃఆ

  24. FPM  status_path pm.status_path = /fpm-status ex) http://localhost/fpm-status

  25.   ex) access.log = /var/log/php7/$pool.access.log   ex) php_admin_value[error_log]

    = /var/log/php7/$pool.error.log php_admin_flag[log_errors] = on   ex) slowlog = /var/log/php7/$pool.slow.log request_slowlog_timeout = 10s php_admin_value[error_l
  26.  ❖static ❖dynamic ❖ondemand

  27. static ❖  ❖pm.max_children  max_children 5 

  28. static active process idle process 5 1 4 0

  29. static ❖Active process  Idle process  max_children  

    
  30. dynamic ❖  ❖pm.max_children:  ❖pm.start_servers:   ❖pm.min_spare_servers: 

     ❖pm.max_spare_servers:  
  31. dynamic    ❖pm.max_children: 5 ❖pm.start_servers: 2 ❖pm.min_spare_servers: 1

    ❖pm.max_spare_servers: 3
  32. dynamic active process idle process 5 1 2 0

  33. dynamic total process Available Memory 5 2

  34. dynamic ❖   max_children  ❖Active process  

    Idle process 
  35. ondemand ❖$'% " ❖pm.max_children: & ❖pm.process_idle_timeout: !( )%+ ❖ pm.start_servers

    #  *
  36. ondemand active process idle process 5 1

  37. ondemand ❖ " !  ❖#  ❖%  $&

  38. dynamic  

  39. dynamic WARNING: [pool www] server reached pm.max_children setting (5), consider

    raising it max_children     max_children 100  
  40. dynamic 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 5 total children ❖ 8 ❖ 0 ❖ active 5
  41. dynamic ALERT: [pool www] pm.start_servers(10) must not be less than

    pm.min_spare_servers(1) and not greater than pm.max_spare_servers(3) ❖start_servers min_spare_servers  ❖start_servers max_spare_servers  min_spare_servers  max_spare_servers    
  42. dynamic ❖start_servers: 10 ❖min_spare_servers: 10 ❖max_spare_servers: 50 warning  total

    process
  43. dynamic accepted connection idle process

  44. dynamic ❖   => spare_servers   ❖ 

       Available memory
  45.   <p>The current time is <?= date('H:i:s', time()); ?>.</p>

     Chrome  Page Load Time  
  46.   ❖     ➢0.86 s ❖

       ➢1.18 s
  47.   ❖ $ (  $+&  ➢$ ➢"%$

    ➢$%$ ❖ %% !# * ,' ➢static ➢dynamic ➢ondemand ❖ )- 
  48. Ruby / PHP