WordPress & Out of control apache2 processes.

Do you use WordPress?  Do you love it as much as I do?  If you don’t…you should!  Even with the best software and servers sometimes not everything works perfectly.  I recently ran into an issue on a brand-spankin-new WordPress site where the entire server would come to a crawl and freeze up.  The only way to get the website back up was to hard power the server off.  TO THE COMMAND LINE!  If you are not familiar with top on Linux  you should become familiar.  Top is a fantastic tool that is included that allows you to watch the processes on your Linux system in real time.  To run top you just type…wait for it:  top

 

Then press enter.  You thought it would be more difficult than that?  When my server was on the verge of crashing this is what I saw in top:

top

That is just a clipping of the apache2 processes that I witnessed killing the server softly.  What you don’t see there is the other couple dozen apache2 processes chewing up the rest of my free resources.  See how long some of the processes had been running and how much memory they were taking up?  I had to dig a bit farther to find EXACTLY what was killing the sever, but using more of those cool Linux tools (did I mention they are free and included??) I am able to do this.

 

In this case I assumed that the same glitch or programming error was causing all the processes to go over the cliff, so I picked one at random and then ran a trace on it using this command line wizardry:

sudo strace -p 5041

Enter your password when prompted and a whole new world will open to you that will show you exactly what that process is doing on your system.  In this case, two plugins on the website were looping and not releasing the apache2 process even after the visitor had left our website.  I called one of the site administrators and asked for the two offending plugins to be disabled.  Once the plugins were disabled I killed ALL apache2 processes (using the kill -9 <pid> command) and restarted apache2 using:  service apache2 restart

 

I then started hammering the site with traffic.  Guess what?  No more zombie or out of control processes:

 

top2

 

What is next you ask?  Zip up the website, backup the SQL and ship it off to the developer to get the plugins fixed.  Once they have it fixed we will be able to re-enable the plugins and life should be normal again.  I hope if you are having problems with your site performance and run into a similar issue, that this was able to help you figure it out!