我有一个configuration了MPM worker和php fast cgi的apache2服务器。 最近apache日志告诉我,MaxClients经常到达,即使它已经非常高。
我的服务器现在不断下降,我在日志中看到了一堆这样的行:
[Sun Mar 06 04:25:40 2011] [error] [client 50.16.83.115] FastCGI: comm with (dynamic) server "/var/local/fcgi/php-cgi-wrapper.fcgi" aborted: (first read) idle timeout (20 sec) [Sun Mar 06 04:25:40 2011] [error] [client 50.16.83.115] FastCGI: incomplete headers (0 bytes) received from server "/var/local/fcgi/php-cgi-wrapper.fcgi"
我可以看到我的php-cgi进程非常大(平均大约70mb)。
这里是我的MPM worker的apacheconfiguration:KeepAlive ON KeepAliveTimeout 2
<IfModule mpm_worker_module> StartServers 5 MinSpareThreads 10 MaxSpareThreads 10 ThreadLimit 64 ThreadsPerChild 10 MaxClients 20 MaxRequestsPerChild 2000 </IfModule>
下面是我的fastcgi apacheconfiguration:
<IfModule mod_fastcgi.c> # One shared PHP-managed fastcgi for all sites Alias /fcgi /var/local/fcgi # IMPORTANT: without this we get more than one instance # of our wrapper, which itself spawns 20 PHP processes, so # that would be Bad (tm) FastCgiConfig -idle-timeout 20 -maxClassProcesses 1 <Directory /var/local/fcgi> # Use the + so we don't clobber other options that # may be needed. You might want FollowSymLinks here Options +ExecCGI </Directory> AddType application/x-httpd-php5 .php AddHandler fastcgi-script .fcgi Action application/x-httpd-php5 /fcgi/php-cgi-wrapper.fcgi </IfModule>
这是我的fastcgi包装器:
#!/bin/sh PHPRC="/etc/php5/apache2" export PHPRC PHP_FCGI_CHILDREN=8 export PHP_FCGI_CHILDREN exec /usr/bin/php-cgi
任何帮助将非常非常感激!
我不认为你的服务器configuration与你的问题有关,但是我们首先解决这个问题:mod_fastcgi将负责产生PHP进程,并且只为每个进程提供一个请求(AFAIK,我是一个mod_fcgid用户)。 因此,要求PHP分叉其他进程是没有用的,您宁愿让PHP_FCGI_CHILDREN = 0来closures此function。
最近apache日志告诉我,MaxClients经常到达,即使它已经非常高。
你的MaxClients是20,在我的MPM工作人员的网站上,它是在5000-10,000球场! 这是非常低的。
请记住,MaxClients只调节Apache进程池,并且Apache可以很好地扩展到服务数千个并发连接。
您可以使用mod_fastcgi选项分别pipe理FastCGI进程池。 我只能在mod_fcgid方面有丰富的经验,对不起。 这个进程池的大部分时间是CPU内核数量的1倍到4倍之间。
[Sun Mar 06 04:25:40 2011] [error] [client 50.16.83.115] FastCGI:comm(dynamic)服务器“/var/local/fcgi/php-cgi-wrapper.fcgi”中止:(先读取)空闲超时(20秒)
你的应用程序不能在20秒内发送一个字节,这很慢。 你将不得不find瓶颈。 作为一个经验法则,如果平均负载很高,那么CPU或I / O限制会有一个很好的改变(然后继续检查CPU使用率)。 否则,如果负载较低,请检查远程资源(数据库服务器,第三方API等)上的等待情况。
你的脚本需要20秒以上的时间。 要么增加空闲超时值,要么调查他们为什么要花费所有时间(例如,等待数据库连接)。
据我所知,我已经安装了一个扩展的问题。
您可以通过增加PHP_FCGI_CHILDREN的数量来解决这个问题,直到它将吃掉所有的内存或者debugging问题,脚本为什么需要很长时间才能执行。 常见的问题是:数据库缓慢,外部请求缓慢(curl或打开)。