PHP High Usage

Hello All,

I have just created a nice CMS for a client, since i used a lot of cache most of time the CPU usage is at 0.1% which is great.

We keep getting Spikes in CPU, this is irregular and im unsure what the problem is. (or how to detect it)

Any tips in finding run away php scripts, or identifying what the problem is.

top - 08:32:37 up 18 days, 18:34,  1 user,  load average: 1.97, 1.82, 1.51
Tasks:  62 total,   5 running,  56 sleeping,   1 stopped,   0 zombie
Cpu(s):  7.3%us,  1.7%sy,  0.0%ni, 91.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1572864k total,   336648k used,  1236216k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
30360 mainusr 15   0 30956  15m 6256 R  5.9  1.0   0:00.18 php
30359 mainusr 16   0 30956  15m 6252 R  5.6  1.0   0:00.17 php
20216 root      18   0 15352  13m 1504 R  0.0  0.8   0:00.51 lfd
26305 root      18   0  9932 2868 2308 R  0.0  0.2   0:00.03 sshd
28072 root      15   0  2200 1028  808 R  0.0  0.1   0:00.04 top

Sure its not some web spider?

http://blogs.perl.org/users/cpan_testers/2010/01/msnbot-must-die.html

Do you know when the spikes occur? You could check with the httpd accesslogs and see if there’s some unusual traffic around that time.

No, I only notice when the website goes awfully slow.

Its 8:40 now and Server Load: 9.81 (8 cpus)
Will check access logs now.

Was not able to find much, it all looks same apart from the annoying guy trying to attack the website 72.55.148.233

Well, does this coincide with when the server is under heavy load? I’m not really an expert on the sysadmin stuff, but perhaps you can log your servers performance over time, so you can go back and find out where the spikes are and compare them with the accesslogs?

You should stress test your application, it is quite likely you wrote something in such a way that causes excessive utilization. Is it using MySQL, are you accessing any remotely hosted data?

What type of cache are you using?