Hello,
I have moved all my sites from one server (Dual Core Dual Xeon / 1GB RAM) to another (Core2Duo / 2GB RAM). Of course I have tweaked apache (2.2.3) settings to fit new CPU, however strangely enough some time passed and (according to `top`) one of httpd processes was taking up 100% CPU usage. I monitored the server to see if it would drop, but not only it didn`t drop, but other httpd processes started taking up more and more of CPU time.
Every time after I restart apache it takes approx. 0 - 4 hours for httpd process to take up most of CPU time again.
I`ve fiddled with httpd.conf, these are 3 configurations I`ve tried, none of them had any positive results.
Code:
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
<IfModule worker.c>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 4000
</IfModule>
Code:
<IfModule prefork.c>
StartServers 5
MinSpareServers 32
MaxSpareServers 64
ServerLimit 512
MaxClients 512
MaxRequestsPerChild 512
</IfModule>
<IfModule worker.c>
StartServers 5
MinSpareThreads 32
MaxSpareThreads 64
ThreadsPerChild 512
MaxClients 512
</IfModule>
Code:
<IfModule prefork.c>
StartServers 10
MinSpareServers 5
MaxSpareServers 50
MaxClients 256
MaxRequestsPerChild 5000
</IfModule>
<IfModule worker.c>
StartServers 10
MinSpareServers 5
MaxSpareServers 50
MaxClients 256
MaxRequestsPerChild 5000
</IfModule>
Naturally I thought it was some specific URL that was causing trouble, so I wrote (not-so-accurate) bash script:
Code:
#!/bin/bash
log=/var/log/httpd/domlogs/example.com
log2=/var/log/httpd/access_log
cpu=50
stop=false
while [ "$stop" == false ]
do
load=`top -d 0 | head -8 | tail -1 | grep httpd | awk '{print $10}'`
load=${load%%.*}
if [ "$load" == "" ]
then
load="0"
fi
if [ "$load" -ge "$cpu" ]
then
tail $log
echo "-----------------"
tail $log2
stop=true
else
echo 'Reloading ('$load'<'$cpu')'
#sleep 1
fi
done
exit 0
Unfortunately neither `ps` nor `top` can display accurate CPU usage if it`s run for short period of time, so this script would approximately detect when httpd process jumped up, but not accurately enough to catch the culprit script.
But then both apache and php have timeout options, so if it were some script that was causing trouble, php would simply timeout it after a minute.
I`m not sure where to go from here. Any ideas?