php-fpm配置筆記

不得不說,英文很差弄linux服務器有時是挺痛苦的,苦逼沒好好學習英文,致使被lnmp折騰的夠嗆.
php-fpm[位置在:/usr/local/php/etc/php-fpm.ini]配置不當,致使服務器常常出現502錯誤,網上找來資料,大都是增長max_children,但是我都加到頂了,php-fpm.log[位置在:/usr/local/php/var/log/php-fpm.log]裏面仍是有大量的警告:php

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了。

硬着頭皮看默認配置裏面的英文註釋,才發現本身的三個參數配置貌似有至關大的問題:java

    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依然生效,另外:linux

    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…

從新規劃以下:less

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

貌似要好點了,內存使用不像以前那麼誇張了:
php-fpm

使用 top 查看內存
學習

相關文章
相關標籤/搜索