警告:[pool inter]似乎很忙(你可能需要增加pm.start_servers,或者pm.min / max_spare_servers),产生8个孩子,

时间:2016-12-15 08:27:45

标签: php nginx

我有nginx和php-fpm的问题,我已经在这个表单中搜索了但是我找不到它的解决方案。

服务器:16核10GB内存

  

警告:[pool inter]服务器达到pm.max_children设置(20),   考虑提高它

[i]
listen = /var/run/fastcgi/i.sock    
listen.allowed_clients = 127.0.0.1    
listen.group = i

user = i

group = inter
pm = dynamic

pm.max_children = 20    
pm.max_requests = 1000

pm.start_servers = 15    
pm.min_spare_servers = 15

pm.max_spare_servers = 15    
;request_terminate_timeout = 300

php_admin_value[error_log] = /var/log/php-fpm/i-error.log    
php_admin_flag[log_errors] = on

php_value[session.save_handler] = files    
php_value[session.save_path] = /var/lib/php/ = /

php_admin_value[open_basedir] = /www/public_html/:/tmp:/usr/share/php:/var/lib/php

strong textphp_admin_value[disable_functions] = dl,exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source

我尝试了很多不同的设置,但我不知道是什么原因,我希望sombody可以提供帮助。

祝你好运

3 个答案:

答案 0 :(得分:1)

您的问题的根本原因无法确定,因为我们不知道您的服务器运行的代码类型。

发生的事情是,PHP无法足够快地处理请求以跟上nginx。

增加子进程数量无济于事,您有16个核心和20个进程。这意味着您的操作系统将被迫安排流程并提高数量,不会让任何事情变得更快 - 您甚至不知道自己是CPU还是I / O.

要正确解决此问题,您需要确定为什么 PHP无法跟上。

您可以通过将PHP-FPM slow_log功能添加到池中来启用它:

slowlog = /var/log/php-fpm/slow.log
request_slowlog_timeout = 1s

这会将每1秒或更长时间的请求记录到文件/var/log/php-fpm/slow.log

检查日志文件并追溯代码的哪一部分导致PHP缓慢响应并修复真正的问题

为了让您的网站保持响应,直到您解决了真正的问题,您将获得另一台用于PHP处理的服务器。由于您使用nginxphp-fpm是您的后端,因此设置更多服务器来处理动态请求处理非常简单。随着您网站的增长和需求的增长,您可以通过向处理池添加php-fpm服务来轻松添加更多后端处理能力。

免责声明:我并不是说你应该,但知道你的选择是什么很好。

用于多个PHP后端的nginx的配置文件示例

    # Define servers in the cluster
    upstream phpcluster {
        server 10.0.0.1:9000;
        server 10.0.0.2:9000;
    }

    location ~ \.php$ {
        try_files                   $uri /index.php =404;
        fastcgi_split_path_info     ^(.+\.php)(/.+)$;
        fastcgi_pass                phpcluster; # Pass to phpcluster upstream. Additional load balancing rules can be defined in upstream block
        fastcgi_index               index.php;
        fastcgi_param               SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }  

答案 1 :(得分:0)

增加pm.max_children中的数字。 20太低了。

答案 2 :(得分:0)

问题发生在配置错误的fpm pool config。

从默认配置示例中删除注释时会发生这种混淆。


所以我正在用原始示例文件(www.conf)中的注释修复您的配置示例。


它应该是:

; 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.
pm = dynamic

; 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 = 1024    

; 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 = 16

; 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 = 64  

; 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 = 40

pm.max_requests = 32 ; to avoid memory leaks it's better respawn child after 32 request




我个人不喜欢闲置的过程。
我刚刚设定:

pm = ondemand
pm.max_children = 1024 
pm.process_idle_timeout = 10s




带有注释的完整示例文件
具体的param是什么意思
您可以在此处看到:http://num8er.me/num8er.conf.txt