Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have Apache on a Linux server, and a Python script inside it (Trac, to be more specific). With a minimum traffic it consumes 99% of CPU and load average is above 3.00. Is it possible to understand somehow what it's doing there - disc, network, which files, etc.? Are the some tools to analyze what a particular process is busy with?

Edit: strace apache2 -X showed me a lot of lines with similar content:

stat("/home/foo/apache/conf.d/trac-XXX.conf", {st_mode=S_IFREG|0644, st_size=1014, ...}) = 0
open("/home/foo/apache/conf.d/trac-XXX.conf", O_RDONLY|O_CLOEXEC) = 6
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6a93021000
fstat(6, {st_mode=S_IFREG|0644, st_size=1014, ...}) = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f6a9301e000
read(6, "contents of my trac-XXX.conf"..., 4096) = 1014
read(6, "", 4096)                       = 0
close(6)               

And the same lines for every file in /home/foo/apache/conf.d/ directory (I have hundreds of them). Do you know how to interpret this information and fix the problem? Looks like Apache is reloading all config files on every HTTP request.

share|improve this question
2  
top, iotop and iftop are good places to start. Are you running reasonable updated versions of Apache and Trac? –  Chris S Apr 8 '13 at 19:12

1 Answer 1

up vote 3 down vote accepted

You can use strace (man strace). As root try

strace `ps -e | grep apache2 | awk '{ print "-p"$1 }'`

or similar with trac instead of apache2. You might also want to configure LogLevel to debug.

The following edit is a wild shot in the dark, not being familiar with Trac.

In the comments following Trac ticket 3833 osimons states:

If you for instance don't use mod_python, but use a simple CGI setup instead, the Environment gets completely reloaded for each request. Such a request essentially have no history - a Python process is started, modules loaded, Trac processing started, and when request is done the whole Python process dies.

The reason this also works is because request specific information (like your preview example) gets passed around as arguments to the request object - available inside the req context.

So the question is, are you using mod_python or plain CGI to run Trac? If you are using plain CGI, then it is clear why the Trac configuration files get read on each request.

share|improve this answer
    
+1 please, read the update to the question –  yegor256 Apr 9 '13 at 7:43
    
@yegor256: Added comment regarding mod_python or CGI config. –  Jonathan Ben-Avraham Apr 9 '13 at 8:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.