Sudden transient spike in Apache process CPU usage. How to track down

apache-2.2central-processing-unitvirtualization

I'm running Apache and every once in a while [once every other day it seems] the number of apache processes will jump considerably and each one takes up around 75% cpu usage.

I would love to be able to track down these processes to the actual virtual host that is getting the requests. Any suggestions?

Best Answer

Apache's logging has a lot of nifty options, and there are a couple of good options to try in order to figure out what is going on. I would start with %D or %T which logs the time it took Apache to complete the request, on the assumption that whatever is taking up all the CPU time is also taking more "real" time to do.

If you are using the Prefork MPM you can format your logs to include %P. This will log the process ID of the apache process actually handling the request so you can match the request to your top output. Process IDs will get reused pretty quickly (due to multiple requests per child) so you'll still need to check the timestamp on the log but you should be able to find the specific request that apache process was handling at that time.

If you're using Worker, then you can try %{tid}P and matching that to top -H which prints the thread ID in the PID column.