php-fpm配置笔记
Posted on 2013 年 2 月 27 日 3,070 Views
不得不說,英文不好弄linux服務器有時是挺痛苦的,苦逼的博主沒好好學習英文,導致被lnmp折騰的夠嗆.
?
php-fpm配置不當,導致服務器經常出現502錯誤,上個學期多次調整都沒有解決,網上找來資料,大都是增加max_children,可是我都加到頂了,php-fpm log里面還是有大量的警告:
eems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 88 total children
不想看英文,一看就頭暈,但是502更頭暈,特別是昨天,剛重啟了lnmp沒多久,容不得松口氣,就看到負載飆到20多,一開網站,又特么502了。
硬著頭皮看默認配置里面的英文注釋,才發現自己的三個參數配置貌似有相當大的問題:
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. With this process management, there will be
; always at least 1 children.
; 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.
; 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.
; ondemand - no children are created at startup. Children will be forked when
; new requests will connect. The following parameter are used:
; pm.max_children - the maximum number of children that
; can be alive at the same time.
; pm.process_idle_timeout - The number of seconds after which
; an idle process will be killed.
; Note: This value is mandatory.
?
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 5
; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 2
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1
; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 3
?
注釋上貌似是說,static模式時,只有pm.max_children生效,dynamic模式時,pm.max_children依然生效,另外:
pm.start_server #控制服務啟動時創建的進程數,
pm.min_spare_servers #控制最小備用進程數
pm.max_spare_servers #最大備用進程數
spare_servers翻譯成備用進程,不知道合適不適合,如果真這樣,那我之前的配置就讓人無奈了: pm.min_space_servers 20,pm.max_spare_servers 80,pm.max_children 80,會不會是因為備用的太多才導致502呢?
?
另外,下面的具體配置里面,注釋中給出了計算pm.start_servers默認值的公式:
Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
按這個公式,我之前的pm.start_servers應該是 20+(80-20)/2=50,可是我當時設置的是20…
重新規劃如下:
pm = dynamic
pm.max_children =80
pm.start_servers = 12
pm.min_spare_servers = 4
pm.max_spare_servers = 20
rlimit_files = 65535
pm.max_requests = 102400
?
轉載于:https://www.cnblogs.com/yangchunlong/p/8306148.html
總結
以上是生活随笔為你收集整理的php-fpm配置笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信浏览器视频自动播放
- 下一篇: css scale 缩放基准点