我有一个运行PHP的ubuntu apache / PHP服务器执行appx 100次点击/秒和一个在后台运行的
PHP cron.
我偶尔会在其中一个Apache进程上出现高cpu负载,无论流量或cron活动如何,它都会保持高水平.在我看来,它停留在某种循环或其他东西.
您将在下面找到top和strace信息.
top - 14:45:24 up 3 days,3:38,1 user,load average: 5.10,5.88,5.85 Tasks: 163 total,5 running,158 sleeping,0 stopped,0 zombie cpu(s): 47.8%us,18.5%sy,0.0%ni,10.2%id,0.0%wa,0.0%hi,1.8%si,21.6%st Mem: 7885012k total,3858484k used,4026528k free,177444k buffers Swap: 0k total,0k used,0k free,1037868k cached PID USER PR NI VIRT RES SHR S %cpu %MEM TIME+ COMMAND 10736 www-data 20 0 769m 559m 478m R 69 7.3 29:08.30 apache2 10844 www-data 20 0 824m 601m 492m S 17 7.8 4:37.90 apache2 1016 root 20 0 242m 25m 4628 S 6 0.3 162:07.93 scalarizr 9030 www-data 20 0 879m 619m 492m S 4 8.0 5:06.82 apache2 20216 www-data 20 0 747m 228m 170m S 4 3.0 0:01.94 apache2 10807 www-data 20 0 814m 584m 492m S 3 7.6 4:54.10 apache2 10455 www-data 20 0 831m 574m 492m S 3 7.5 4:32.65 apache2 10495 www-data 20 0 849m 592m 492m S 3 7.7 4:41.10 apache2 10884 www-data 20 0 840m 581m 492m S 3 7.6 4:25.06 apache2 ^CProcess 10736 detached % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 74.55 0.148052 1 109755 gettimeofday 25.36 0.050370 0 164634 clock_gettime 0.09 0.000178 0 54878 poll ------ ----------- ----------- --------- --------- ---------------- 100.00 0.198600 329267 total root@ec2-67-202-54-36:~# ^C
我建议启用Apache
mod_status并打开ExtendedStatus. Slicehost有一个关于如何完成这个的
excellent article(我会使用“elinks”包与“lynx”但这是个人偏好).当您查看Apache服务器状态URL时,会有一个PID,VHost和Request列 – 它们应该大大指向正在调用的URI,您可以使用它来追溯到正在运行的特定代码.
以下是启用mod_status的Slicehost文章的自定义版本:
sudo apt-get install elinks sudo /usr/sbin/a2enmod status sudo sh -c "echo 'ExtendedStatus On' > /etc/apache2/conf.d/extendedstatus" sudo vi /etc/apache2/sites-available/server-status <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from localhost </Location> sudo /usr/sbin/a2ensite server-status sudo apachectl configtest sudo service apache2 reload
然后查看服务器状态:
elinks -dump -dump-width 256 http://localhost/server-status