php-fpm配置笔记
Posted on 2013 年 2 月 27 日 3,070 Views
不得不說(shuō),英文不好弄linux服務(wù)器有時(shí)是挺痛苦的,苦逼的博主沒(méi)好好學(xué)習(xí)英文,導(dǎo)致被lnmp折騰的夠嗆.
?
php-fpm配置不當(dāng),導(dǎo)致服務(wù)器經(jīng)常出現(xiàn)502錯(cuò)誤,上個(gè)學(xué)期多次調(diào)整都沒(méi)有解決,網(wǎng)上找來(lái)資料,大都是增加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沒(méi)多久,容不得松口氣,就看到負(fù)載飆到20多,一開(kāi)網(wǎng)站,又特么502了。
硬著頭皮看默認(rèn)配置里面的英文注釋,才發(fā)現(xiàn)自己的三個(gè)參數(shù)配置貌似有相當(dāng)大的問(wèn)題:
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
?
注釋上貌似是說(shuō),static模式時(shí),只有pm.max_children生效,dynamic模式時(shí),pm.max_children依然生效,另外:
pm.start_server #控制服務(wù)啟動(dòng)時(shí)創(chuàng)建的進(jìn)程數(shù),
pm.min_spare_servers #控制最小備用進(jìn)程數(shù)
pm.max_spare_servers #最大備用進(jìn)程數(shù)
spare_servers翻譯成備用進(jìn)程,不知道合適不適合,如果真這樣,那我之前的配置就讓人無(wú)奈了: pm.min_space_servers 20,pm.max_spare_servers 80,pm.max_children 80,會(huì)不會(huì)是因?yàn)閭溆玫奶嗖艑?dǎo)致502呢?
?
另外,下面的具體配置里面,注釋中給出了計(jì)算pm.start_servers默認(rèn)值的公式:
Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
按這個(gè)公式,我之前的pm.start_servers應(yīng)該是 20+(80-20)/2=50,可是我當(dāng)時(shí)設(shè)置的是20…
重新規(guī)劃如下:
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
?
轉(zhuǎn)載于:https://www.cnblogs.com/yangchunlong/p/8306148.html
總結(jié)
以上是生活随笔為你收集整理的php-fpm配置笔记的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 微信浏览器视频自动播放
- 下一篇: php判断当前浏览器是否微信浏览器