How do I troubleshoot Apache driving high CPU usage?

I'm confused by the high CPU usage from my Linodes right now. I have two of them and both are showing high CPU usage for the past two days, which you can see from the images below:
https://ibb.co/ZH8n7FL - Site 1

https://ibb.co/FD3d7sr - Site 2

For the first site, I ran top on the LISH console to see what was using all the CPU. From there, I can see that Apache is using up a lot of CPU.

https://ibb.co/qsFpNLL

The only problem is that I don't really know how to stop Apache using so much CPU. Can anyone help me troubleshoot the issue?

3 Replies

I have a few suggestions that could help, including some specific information about Apache, some general ideas about investigating CPU usage, and some possible alternatives if you're not able to resolve the issue.


Investigating Apache

First, I recommend taking a look at your logs to see if you can find more information about why it's using as much CPU as it is. You may want to turn on verbose logging for the most information. These resources can help with finding where to look:

Next, you can check out our guide to Tuning Your Apache Server. This offers some tools for maximizing resource utilization that could be helpful for you.

Finally, I found this ServerFault discussion that has some suggestions that seem to have helped others. This was one of many forums that suggested a php script could be the issue; however, these were all fairly old, so I'm not sure how useful this information is. It might be worth looking into your php scripts or updating the version of php your server is using.


General CPU Troubleshooting

I'd also recommend checking out this post about CPU usage. While you've identified Apache as what's using the most CPU, I think it can still be helpful for conceptualizing the reasons it might be doing that to figure out how to troubleshoot it.

For example, one of the causes mentioned in that post is Denial of Service attacks. To see if this is a possible reason, you might want to check the graphs in Cloud Manager or use an additional monitoring tool like Longview to see if traffic and CPU are both spiking together. If so, analyze the traffic to see if it's legitimate.

Since two servers are having the same issue and likely aren't on the same host, I don't think this is likely caused by CPU Steal. That said, if you're on a shared CPU plan, you can use the information in this post to look for CPU Steal if you want to be sure.


Alternatives to Apache

You may also want to switch to NGINX which is uses less memory and CPU. It's not the right choice for everyone, but we have a guide comparing the two to help you figure out if it might be worth the change.

If you're open to moving away from Apache and are running Wordpress, then you may want to look into our OpenLiteSpeed Marketplace App which may also increase performance.

While I think it's likely there are other things you can do first to resolve the issue, if you can't, you may just need more CPU. If that's the case, you can upgrade to a larger plan or change to a Dedicated CPU plan if you're not using one already.

Sounds good!
I started troubleshooting this by checking out the error logs for apache2 in /var/log/apache2/error.log. Here are the last 10 lines of the error:
https://ibb.co/n8Vh31N

Interestingly, these process IDs match with the processes taking up the most memory in Apache2. But what do these errors mean?
https://ibb.co/BZP37pc

Linode Staff

I wasn't able to find much on these exact errors on the internet. My suggestion would be to run through the Tuning your Apache Server guide that @CassandraD shared and see if the errors continue after that.

If so, you can share them on an Apache-specific site like apachelounge.com where folks who are more familiar with Apache2 itself may be able to help you out.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct