Ubuntu – Howto Monitor, Identify and Debug slow requests in Apache2

apache-2.2performanceUbuntu

This is a question about the correct process for trouble shooting Apache performance problems.

Some context. I run an Ubuntu 8.04LTS Virtual Machine with 360MB RAM. This serves LAMP websites; mainly based on WordPress.

It doesn't get a lot of traffic (15k visits/month, 200k hits/month). But occasionally Apache goes beserk, consumes 100% CPU, thrashes the disks and generally causes the machine to grind to a halt (== doesn't serve webpages, won't respond to SSH commands etc)

So, my question is, how do I prepare to collect the correct information that will allow me to debug this kind of problem?

I'm as interested in the process as in the tools.

For example; the mysql slow query log seems like a reasonable way to debug slow SQL queries. Is there something similar for Apache? Is there some kind of logging tool that will show me which requests are the slowest / use the most CPU/memory? Or is this the wrong approach?

Thanks!

Best Answer

Boohbah's answer will get you what you're asking for, but I think you might be asking for the wrong thing.

Slow requests via Apache isn't the problem, it's the effect. It sounds as though you've allowed Apache to consume too much memory, which then your box starts swapping, thrashing the disks. Tuning Apache is an art, not a science, so there's no copy/paste config that works for everyone, but here's a good article to get you started: Tuning LAMP @ O'Reilly.

Once you're done with that, look at setting up Munin to monitor your memory and CPU load.