My apache2 is using running slowly. A single PHP file is takes long time to process. The server is live. I dont want to restart it. So I thought I attach
strace to it and check whats happening.
So I run
strace -p `cat /var/run/apache2.pid `
After that I load some testing urls. Load then many times. But I didn’t see any output at the
Then I remember there are many child processes. So I checked them
$ ps ax | grep apache -i 1877 ? Ss 0:02 /usr/sbin/apache2 -k start 2006 ? S 0:00 /usr/sbin/apache2 -k start 2007 ? S 0:00 /usr/sbin/apache2 -k start 2008 ? S 0:00 /usr/sbin/apache2 -k start 2009 ? S 0:00 /usr/sbin/apache2 -k start 2010 ? S 0:00 /usr/sbin/apache2 -k start 9985 ? S 0:00 /usr/sbin/apache2 -k start 9988 ? S 0:00 /usr/sbin/apache2 -k start 9997 ? S 0:00 /usr/sbin/apache2 -k start 9998 ? S 0:00 /usr/sbin/apache2 -k start 9999 ? S 0:00 /usr/sbin/apache2 -k start
Now my question is how do I strace all of these child processes? How do I know which child process is handling the request right now?
The short answer: you cannot predict which apache process will handle a request.
The simplest way to solve this problem is to dedicate an xterm to every apache process and run
strace -p <pid> in it for each apache pid.
When I’m in this situation, I usually do this in my
httpd.conf (on a development box):
<IfModule prefork.c> StartServers 1 <-------- MinSpareServers 1 <-------- #StartServers 8 #MinSpareServers 5 MaxSpareServers 20 ServerLimit 256 MaxClients 256 MaxRequestsPerChild 4000 </IfModule>
This reduces the number of processes I need to monitor… obviously it’s not a good solution for a production environment.
No related posts.
Leave a comment
- Cron expression that runs every 5 minutes from 1:30 am – 6:00 am [duplicate]
- Understanding redundant power supplies
- Is there a way for administrators to disable users from installing Firefox extensions?
- Is there research material on NTP accuracy available?
- How to create a limited “domain admin” that does not have access to domain controllers?