Linux – Why is the apache2, mod_fcgid, php configuration causing 100% cpu usage

apache-2.2fastcgilinuxmod-fcgidPHP

Page load makes a quick initial connection, then hangs about 10 seconds before the page renders. When the server load goes up I start watching top & I see that both CPUs get pegged at times to 100% by between 4-8 processes of php-cgi. My theory is that since I never see RAM usage never go above 50%, that apache is able to handle the requests coming in, but is queueing them for PHP to process. What is wrong with my mod_fcgid/php configuration ?

RHEL 5.4
2 Xeon E5420s @ 2.50 Ghz
4 Gb RAM

Apache 2.2.3
Timeout 30
KeepAlive On
MaxKeepAliveRequests 0
KeepAliveTimeout 5
<IfModule worker.c>
StartServers 2
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

mod_fcgid 2.2.10
LoadModule fcgid_module modules/mod_fcgid.so
<IfModule !mod_fastcgi.c>
AddHandler fcgid-script fcg fcgi fpl php
</IfModule>
SocketPath run/mod_fcgid
SharememPath run/mod_fcgid/fcgid_shm
DefaultInitEnv PHPRC "/etc/"
FCGIWrapper /usr/bin/php-cgi .php
MaxRequestsPerProcess 1500
MaxProcessCount 20
IPCCommTimeout 240
IdleTimeout 240

APC 3.0.19
extension = apc.so
apc.enabled=1
apc.shm_segments=1
apc.optimization=0
apc.shm_size=32
apc.ttl=7200

APC cache is 43% used with a 99% hit rate

Best Answer

Couple of things I would check off the bat ...

First, do you have anything printing out to your Apache Error logs ? You may need to up the log level to "warn" so as to see output from your CGI processes. Though in this case bringing it up to debug may be more beneficial as apache will print out fcgi related logging info. Checking out the access logs might be helpful also to see whether apache's returning 403, or 500 codes.

Second, what PHP code are you attempting to execute and how are you testing it ? Though I would have expected to see more cgi processes, there might be something up on this end. Are you going with a heavy script or something simple like a phpinfo(); ?