Nginx和PHP-FPM没有连接

我不断遇到像这样的错误,

[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 

我刚刚推出了一个新的网站,获得可量的stream量。 这个stream量是合法的,当达到限制时,用户正在获得504个网关超时。

我有限的连接到我的服务器与IPTABLES,我正在运行fail2ban和跟踪nginx访问日志。 stream量是合法的,我只是用完了空间。

我目前正在使用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

我的nginxconfiguration是

 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上的stream量,当用户数超过120时,我的php-fpm.log中充满了这些警告。

你有没有考虑遵循日志消息中提供的好build议,提高pm.max_children的价值? 你有一大堆免费的RAM来容纳它们。

回答你的问题:

  • 我能做些什么来阻止连接失效? 提供更多连接,或减less您接收的连接数量。
  • 为什么这一直在发生? 因为你连接不足。

我们在web服务器上遇到同样的问题。

您可以尝试重新生成每个X请求的subprocess,以避免内存泄漏。 它在Apache和FPM中运行良好,它也开始运行良好。

  pm.max_requests = 50000 

这将每5万次请求重新启动一个subprocess