Fixing CPU spikes in Ubuntu 11.10

If you finding your CPU usage spiking in Ubuntu 11.10 it may very well be an issue caused by php5’s cron task.

To confirm, first use top to see if fuser is taking up the most amount of CPU and creating hundreds of zombie processes. If that’s the case, here’s the fix:

Open /etc/cron.d/php5 and you should see something like this:

09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete

Go ahead and comment that out and replace it with:

09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete

The difference being that the 11.10 version runs fuser for each PHP session file, thus using all the CPU when there are hundreds of sessions.

Save that and reboot the instance to regain normalcy.

All credit goes to grazer for suggesting this solution.

If you have any questions or comments, please post them below. If you liked this post, you can share it with your followers or follow me on Twitter!