Nginx和PHP-FPM用尽了连接


9

我一直遇到这样的错误,

[02-Jun-2012 01:52: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 19 idle, and 49 total children
[02-Jun-2012 01:52:05] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 19 idle, and 50 total children
[02-Jun-2012 01:52: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 19 idle, and 51 total children
[02-Jun-2012 03:10:51] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 18 idle, and 91 total children

我将php-fpm的设置更改为这些,

pm.max_children = 150 (It was at 100, i got a max_children reached and upped to 150)
pm.start_servers = 75
pm.min_spare_servers = 20
pm.max_spare_servers = 150

导致

[02-Jun-2012 01:39:19] WARNING: [pool www] server reached pm.max_children setting (150), consider raising it

我刚刚启动了一个新网站,该网站获得了可观的访问量。此流量是合法的,并且达到限制时,用户将收到504个网关超时。

我使用IPTABLES与服务器的连接受到限制,并且正在运行fail2ban并跟踪nginx访问日志。流量是合法的,我的用户空间不足。

我目前在使用ubuntu 64位的双核处理器上运行。

free
             total       used       free     shared    buffers     cached
Mem:       6114284    5726984     387300          0     141612    4985384
-/+ buffers/cache:     599988    5514296
Swap:       524284       5804     518480

我的php.ini max_input_time = 60

我的nginx配置是

worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 19000;
    # multi_accept on;
}
worker_rlimit_nofile    20000;  #each connection needs a filehandle (or 2 if you are proxying)

client_max_body_size 30M;
client_body_timeout   10;
client_header_timeout 10;
keepalive_timeout     5 5;
send_timeout          10;

    location ~ \.php$ {
    try_files $uri /er/error.php;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 16k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_max_temp_file_size 0;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/tmp/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

我该怎么做才能停止用尽连接?为什么这种情况不断发生?我正在实时监控Google Analytics(分析)上的流量,当用户数超过120时,我的php-fpm.log充满了这些警告。

Answers:


5

您是否考虑过按照日志消息中提供的建议,提高值pm.max_children?您有大量的可用RAM来容纳它们。

要回答您的问题:

  • 我该怎么做才能停止连接耗尽?供应更多的连接,或减少您收到的连接数。
  • 为什么这种情况不断发生?因为您一直用尽连接。

抱歉,该错误在我将其从100更新到150后被加了时间戳。是的,我有。我应该为我所有的ram设置什么设置?
E3pO 2012年

您应该将其提高到(free/mem_per_worker)+150,这free是在考虑到其他进程的需求之后其拥有的内存量,这些进程的内存需求将随着更多的负载而增加,并且mem_per_worker是您预见的每个PHP工作进程所需的最大内存量。
womble

4

我们的网络服务器上存在相同的问题。

您可以尝试在每个X请求中重新生成子进程,以避免内存泄漏。它在Apache和FPM上运行良好,并且也开始很好地运行。

 pm.max_requests = 50000

这将每50k个请求重新启动一个子进程

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.