How can I track down CPU intensive requests in mod_perl?

Using Apache 2.2 and mod_perl on Ubuntu 8.04 I have several applications on a server. Using Apache in pre-forking mode. Usually things are working well but once in a while I see one of Apache processes using 100% of the CPU.

There are several web sites on the server with their own VirtualHosts and there are
is and SVN server running via Apache.

How could I track down which application and which calls in that application generate the high load?


3 Answers
answer

Devel::NYTProf is pretty much the premier profiler for Perl right now, with Devel::NYTProf::Apache for easily profiling mod_perl applications.

See Tim Bunce: NYTProf v2 – A major advance in perl profilers for a pretty overview with pictures.

Unfortunately, Devel::NYTProf isn’t pre-packaged in Ubuntu Hardy. (It is pre-packaged in Jaunty, Karmic, Lucid, and later.) You can either use some apt trickery to install packages from those distributions, install from CPAN, or just upgrade ;-)

answer

If you have a large subversion repository and path-based authorization enabled in your apache configuration you’re going to see some long-running, high CPU apache tasks. You’ll probably also have complaints from subversion users about slow commits and updates, along with 503 errors and subversion complaining about truncated SSL responses. If this is the case, I’d make subversion my prime suspect.

answer

Use a custom log format or a write a PerlLogHandler that records the request information along with the PID and resource use information. See, for instance, Randal’s Web Techniques Column 48.