php 警告:[pool www] 似乎很忙(您可能需要增加 pm.start_servers 或 pm.min/max_spare_servers),正在生成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25097179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning
提问by ?a?r? Can Bozkurt
I have a CentOS server. System is nginx/php-fpm. It has 16GB RAM. CPUs : 8
我有一个 CentOS 服务器。系统是nginx/php-fpm。它有 16GB 内存。CPU : 8
CPU Frequency: 2660.203 MHz
CPU频率:2660.203 MHz
Why am I getting this error in my error log?
为什么我的错误日志中会出现此错误?
php-fpm/error.log:
php-fpm/error.log:
[02-Aug-2014 17:14:04] 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 21 total children
[02-Aug-2014 17:14:04] 警告:[pool www] 似乎很忙(您可能需要增加 pm.start_servers 或 pm.min/max_spare_servers),生成 8 个子项,有 0 个空闲,总共 21 个孩子们
This is my php-fpm configuration for the www pool:
这是我的 www 池的 php-fpm 配置:
php-fpm/www.conf:
php-fpm/www.conf:
pm = dynamic
pm.max_children = 32768
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 10
pm.max_requests = 5000
pm = 动态
pm.max_children = 32768
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 10
pm.max_requests = 5000
How to fix the problem?
如何解决问题?
回答by Rijndael
It is a tough cookie because there could be numerous factors involved. The first problem with your config is the max_children
is ridiculously high. If each child process is using 50MBthen 50 x 32768would easily deplete 16GB.
这是一个艰难的饼干,因为可能涉及很多因素。你的配置的第一个问题max_children
是高得离谱。如果每个子进程使用50MB,那么50 x 32768将很容易耗尽16GB。
A better way to determine max_children
is to find out how much each child process uses, then factor in the maximum RAM you would like php-fpm to use and then divide the values. E.g. If I have a 16GB server, I can run the following command to determine how much ram each php-fpm child consumes:
确定的更好方法max_children
是找出每个子进程使用多少,然后考虑您希望 php-fpm 使用的最大 RAM,然后将这些值相除。例如,如果我有一个 16GB 的服务器,我可以运行以下命令来确定每个 php-fpm 子进程消耗多少内存:
ps -ylC php-fpm --sort:rss
Note!It may be required to explicitly specify user if php-fpmis running under the different one.
ps -ylC php-fpm --sort:rss -u www-data
where www-datais the user under which php-fpm is being run.
笔记!如果php-fpm在不同的用户下运行,则可能需要明确指定用户。
ps -ylC php-fpm --sort:rss -u www-data
其中www-data是运行 php-fpm 的用户。
You are on the lookout for the RSS column; it states resident memory and is measured in KB. If I have an average of 50MB per process and I want to use a maximum of 10GB for php-fpm processes, then all I do is 10000MB \ 50MB = 200. So, on that basis, I can use 200children for my stated memory consumption.
您正在寻找 RSS 专栏;它表示常驻内存并以 KB 为单位。如果我每个进程平均有 50MB 并且我想为 php-fpm 进程使用最大 10GB,那么我所做的就是10000MB \ 50MB = 200。因此,在此基础上,我可以使用200 个孩子来满足我声明的内存消耗。
Now, with regards to the servers, you will want to set the max_spare_servers
to x2 or x4 the number of cores. So if you have an 8 core CPU then you can start off with a value of 16for max_spare_servers
and go up to 32.
现在,关于服务器,您需要将max_spare_servers
核心数设置为 x2 或 x4。所以,如果你有一个8核CPU,那么你可以用一个价值开始16对max_spare_servers
,并上升到32。
The start_servers
value should be around half of the max_spare_servers
value.
该start_servers
值应为该max_spare_servers
值的一半左右。
You should also consider dropping the max_requests
to around 500.
您还应该考虑将 降低max_requests
到500左右。
Also, in addition to dynamic
, the pm
value can also be set to static
or ondemand
.
此外,除了dynamic
,该pm
值还可以设置为static
或ondemand
。
static
will always have a fixed number of servers running at any given time. This is good if you have a consistent amount of users or you want to guarantee you don't breach the max memory.ondemand
will only start processes when there is a need for them. The downside is obviously having to constantly start/kill processes which will usually translate into a very slight delay in request handling. The upside, you only use resources when you need them.dynamic
always starts X amount of servers specified in thestart_servers
option and creates additional processes on an as-need basis.
static
在任何给定时间都会有固定数量的服务器在运行。如果您拥有一致数量的用户或者您想保证您不会违反最大内存,这很好。ondemand
只会在需要时启动进程。缺点显然是必须不断启动/终止进程,这通常会导致请求处理的延迟非常轻微。好处是,您仅在需要时才使用资源。dynamic
始终启动start_servers
选项中指定的 X 台服务器,并根据需要创建其他进程。
If you are still experiencing issues with memory then consider changing pm
to ondemand
.
如果您仍然遇到内存问题,请考虑更改pm
为ondemand
.
This is a general guideline, your settings may need further tweaking. It is really a case of playing with the settings and running benchmarks for maximum performance and optimal resource usage. It is somewhat tedious but it is the best way to determine these types of settings because each setup is different.
这是一般准则,您的设置可能需要进一步调整。这确实是一个玩设置和运行基准测试以获得最大性能和最佳资源使用的案例。这有点乏味,但这是确定这些类型设置的最佳方法,因为每个设置都不同。