我有nginx和php-fpm的问题,我已经在这个表单中搜索了但是我找不到解决方案。
服务器: 32核心 64gb内存
设定:
nginx.conf:
worker_processes 32;
events {
worker_connections 2048;
}
在php-fpm配置
中pm.max_children = 1500
pm.start_servers = 500
pm.min_spare_servers = 500
pm.max_spare_servers = 500
它可以工作几分钟,但如果我们在服务器上有更多用户,我会收到关注错误消息:
[06-Oct-2014 15:23:20]警告:[池www]似乎很忙(你可能需要增加pm.start_servers,或pm.min / max_spare_servers),产生8个孩子,有483个空闲,和1068名儿童
页面非常慢,很多用户都有502坏网关消息
负载平均值约为20 20 20
我尝试了很多不同的设置,但我不知道是什么原因,我希望sombody可以提供帮助。
祝你好运
答案 0 :(得分:1)
你的" net.core.somaxconn"值? 可以通过执行" cat / proc / sys / net / core / somaxconn"找到它。它应该足够大,可以处理大量的请求。默认值为128,在您的情况下非常少。如果它更少,请将它设为2048。
" listen.backlog" php-fpm中的指令应该足够大以排队请求。 somaxconn值应大于积压值。
答案 1 :(得分:0)
您有32个工作进程,最多可接受2048个连接 (yes, each)。
这意味着您的nginx最多可同时接受65536个连接。
但是你的PHP-FPM最多可以有1500个实例来处理PHP请求。
现在,根据PHP与静态文件请求的比例,您缺少可用的PHP-FPM流程。
假设您的典型网页上的平均PHP /静态比率为1:5,您(理论上)可以提供多达7,500个并行请求。所有其他人都会遇到错误的网关错误。
这只是一个理论数字,有许多因素需要考虑(保持活动,缓存,内核TCP设置等)以确定实际最大值,但这应该可以让您了解问题所在。
答案 2 :(得分:0)
感谢您的回答,我现在使用的是unix socket而不是TCP / IP
我现在改为: somaxconn:2048 和listen.backlog:1024
两人都在128岁。这里再次提供错误日志的示例(这是在我更改之前)
[07-Oct-2014 11:54:32] NOTICE: [pool www] child 23114 exited with code 0 after 234.275112 seconds from start
[07-Oct-2014 11:54:32] NOTICE: [pool www] child 25056 started
[07-Oct-2014 11:54:45] 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 108 total children
[07-Oct-2014 11:54:46] 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 116 total children
[07-Oct-2014 11:54:47] 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 132 total children
[07-Oct-2014 11:54:48] 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 164 total children
[07-Oct-2014 11:54:49] 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 196 total children
[07-Oct-2014 11:54:50] 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 228 total children
[07-Oct-2014 11:54:51] 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 260 total children
[07-Oct-2014 11:54:52] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 11 idle, and 292 total children
[07-Oct-2014 11:54:53] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 5 idle, and 324 total children
[07-Oct-2014 11:54:54] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 36 idle, and 356 total children
[07-Oct-2014 11:55:02] WARNING: [pool www] child 25306, script '/srv/www/examplepage.com/public/index.php' (request: "GET /index.php") executing too slow (13.037138 sec), logging
[07-Oct-2014 11:55:02] WARNING: [pool www] child 24865, script '/srv/www/examplepage.com/public/index.php' (request: "GET /index.php") executing too slow (12.989517 sec), logging
这发生在10秒内,从10个激活的fpm进程到超过400个。
答案 3 :(得分:0)
问题很遗憾没有解决,我现在安装了新的遗物,这里举例说明当php-fpm进程突然增加时会发生什么:
此时服务器尚未完全占用。
看起来像redis有问题(我没有安装memcached)。