php5-fpm最大化所有内核(nginx + php5fpm + wordpress)

我们有一个运行8个cpu内核的16个gode linode,我试图debugging一个问题,当我尝试一个负载testing时,服务器开始在一个非常基本的WordPress站点上发出大约250个请求。 我只打在网站的头版fyi。

当我login到服务器并查看Htop上的服务器统计数据时,我发现所有核心都被挂钩,并且php5-fpm进程的垃圾负载也是如此。 testing完成后,这些过程仍然存在,我最终必须重新启动php-fpm才能使服务器恢复正常运行。

我今天在做日志的时候看到了这个。

[23-Dec-2013 12:19:03] 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 27 total children [23-Dec-2013 12:19:04] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 35 total children [23-Dec-2013 12:19:05] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 45 total children [23-Dec-2013 12:19:06] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 55 total children [23-Dec-2013 12:19:07] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 65 total children [23-Dec-2013 12:19:08] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 75 total children [23-Dec-2013 12:19:19] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 5 idle, and 93 total children 

所以显然有一些是fubar,我只是没有专家来调整我们现有系统的这些设置。

这是我们的www.conf

 ; Start a new pool named 'www'. ; the variable $pool can we used in any directive and will be replaced by the ; pool name ('www' here) [www] ; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. user = www-data group = www-data ; The address on which to accept FastCGI requests. ; Valid syntaxes are: ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on ; a specific port; ; 'port' - to listen on a TCP socket to all addresses on a ; specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. listen = /var/run/php5-fpm.sock ; Set listen(2) backlog. A value of '-1' means unlimited. ; Default Value: 128 (-1 on FreeBSD and OpenBSD) listen.backlog = 65536 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 = 150 ; 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 = 20 ; 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 = 10 ; 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 = 35 ; The number of seconds after which an idle process will be killed. ; Note: Used only when pm is set to 'ondemand' ; Default Value: 10s ;pm.process_idle_timeout = 10s; ; The number of requests each child process should execute before respawning. ; This can be useful to work around memory leaks in 3rd party libraries. For ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. ; Default Value: 0 pm.max_requests = 500 pm.status_path = /status-www ; The log file for slow requests ; Default Value: not set ; Note: slowlog is mandatory if request_slowlog_timeout is set ;slowlog = log/$pool.log.slow slowlog = /var/log/php-fpm-slow.log ; The timeout for serving a single request after which a PHP backtrace will be ; dumped to the 'slowlog' file. A value of '0s' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 request_slowlog_timeout = 115s ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 request_terminate_timeout = 120s ; Set open file descriptor rlimit. ; Default Value: system defined value rlimit_files = 65536 ; Set max core size rlimit. ; Possible Values: 'unlimited' or an integer greater or equal to 0 ; Default Value: system defined value rlimit_core = 0 

任何build议或指出与www.conf?

首先,你真的应该问自己这个问题:你的网站真的应该能够处理250次/秒? 这是一个页面的请求很多。 坦率地说,我认为250req / s的最大CPU是正常的,因为你有什么 – 一个虚拟化的系统。

 pm.max_children = 150 

你可能不停地提出这个问题,因为你不停地接到错误,说你在孩子身上已经过时了。 但是当你提出这个超出你的系统可以处理的范围时,你实际上是在自我投射。 不接受下一个无法处理的请求比接受更好。 增加这个不仅会缩小你的系统,还会造成更多的资源需求以及更多的开销。 而当爆炸到一个规模的系统不能再处理,它会创造像冻结的迹象。 我不知道你的VPS究竟给你什么(你永远不会知道,因为它不是静态的,因为它取决于节点中的其他用户),但我个人认为,对于你指定的系统,任何超过20的是不是现实的设置。

你也应该相应地调整开始/最小/最大的备用,因为那时大于最大的孩子是没有意义的。 或者你可以不用担心,并设置为pm = static

将进程pipe理更改为ondemand

 pm = ondemand