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

I'm seeing a weird issue on our web servers where the Apache processes seem to be remaining in limbo with 1 or 2 threads. This is disconcerting for me since I was just thinking I wanted to impose a stricter ServerLimit so that I can more safely up my php memory_limit.

Would anyone know of a nice way to troubleshoot this? Figure out what the hell those processes are doing? What state they are in?

I'm not entirely sure, but I would assume that this is caused by the fact that we never restart the Apache service, and do execute 2-3 reloads a day for various reasons.

As an example, one of the Web Servers is sitting around bored while the other is fairly taxed :

  PID        PPID       RES        THREADS   
  *15608     1          29 MB      1         
  8880       1          2 MB       3         
  14989      1          0 MB       1         
  25029      1          0 MB       1         
  2115       15608      3 MB       2         
  13058      15608      361 MB     2         
  14556      15608      157 MB     27        
  19962      15608      23 MB      1         
  21219      15608      387 MB     3         
  21600      15608      3 MB       3         
  21828      15608      3 MB       2         
  30152      15608      3 MB       2     

In this example, there's 3 processes which I'm assuming were once the control process (pre reload), which are still running for whatever reason. And of the processes attached to the new control process, a bunch are still up with 2-3 threads each.

From 11 hours later, a lot of those same PIDs are still around with 1 thread. You'd think if MaxRequests had been reached the darned thing would have quit.

memory usage report for apache2
  pid count                     : 11                  
  thread count                  : 46                  
  shared mem usage              : 670 MB              
  total resident size           : 691 MB              
  total cpu usage               : 79 %                
  total memory usage            : 7 %                 
  average mem / pid             : 62 MB               

process breakdown
  PID        PPID       RES        THREADS   
  *15608     1          29 MB      1         
  8880       1          2 MB       3         
  14989      1          0 MB       1         
  25029      1          0 MB       1         
  2115       15608      3 MB       2         
  19962      15608      23 MB      1         
  21219      15608      387 MB     3         
  21600      15608      3 MB       3         
  21828      15608      3 MB       2         
  29239      15608      238 MB     27        
  30152      15608      3 MB       2         

process tree
     |-apache2-+-3*[apache2---{apache2}]
     |         |-apache2
     |         |-2*[apache2---2*[{apache2}]]
     |         `-apache2---26*[{apache2}]
     |-apache2---2*[{apache2}]
     |-2*[apache2]
share|improve this question

2 Answers 2

First thing to check is whether these have spawned any additional processes (have you got pstree available?). Are the php exec functions enabled?

Other things to look at at whether you've got keepalives enabled and whether maxRequests is set to a sensible value. Are the threads idle or processing stuff?

Is the PHP talking to a database backend? Once the thread of execution goes into the DB client lib, PHP constraints regarding memory usage and time limits are no longer applied until the thread goes back to PHP. Are you seeing slow queries on your database?

Other things worth checking are whether the MTA is configured correctly - e.g. if you are using sendmail with a smart relay and the address you've configured is wrong, then php's mail() function can block for long periods.

Rob Olmos's reply regarding Rasmus Lerdorf's comment was made 6 years ago while there may still be some truth in the statement, it's not likely to apply to the mainstream extensions.

You didn't say what OS you're using - IMHO the benefits of threading on Linux compared to pre-forking are barely detectable.

Certainly if you've exhausted the other avenues and you don't have a compelling reason to stick with the threaded apache, then its worth trying the pre-fork - but do have a look elsewhere first.

share|improve this answer
    
Thanks for the response. I'll edit the original response with pstree and a process list from 11 hours later. You'll notice that those top level processes ( Parent PID=1 ) are still there. –  delerious010 Sep 8 '10 at 12:25
    
(continued .. note to self enter is bad in comments -_-) are still there. I'm gathering information regarding all of the "quirks" this place has before I go about optimizing. First, you won't find PHP processes in place, since i'm using mod_php ( yes, with mpm_worker ) due to ram constraints. MaxRequests is set to 2000. How would I tell if the Process/thread is active ? Mysql has persistents on with the default 8 hours (...). I will look into the sendmail aspect, thnx ! –  delerious010 Sep 8 '10 at 12:31
    
"you won't find PHP processes" - I meant other programs started by PHP using exec(), system() et al (though no sign of them in the pstree above). "ram constraints" - whether threaded apache has a significanly smaller footprint has always been a bit suspect. Similarly - why the persistent mysql connections? There seems to be a lot of premature optimization going on here. –  symcbean Sep 9 '10 at 8:56
    
I've inherited admin duties on this hosting environment and have to make due / work around the main product which is ( imho ) a heavy poorly designed PHP ecommerce site. Currently, we have 300 ecommerce sites on two servers with "slow" load balancing / 20 minute server affinity since sessions are not stored within the database and are in php files. Every hour, on the hour, all 300 client virtual hosts are accessed. The ram constraint is specifically due to the fact that CGI would potentially kill the servers on those hourly updates. Of course the code is the first part needing fixing but ..... –  delerious010 Sep 9 '10 at 16:40

Is PHP running via mod_php? The PHP install docs give this:

Warning We do not recommend using a threaded MPM in production with Apache 2. Use the prefork MPM, which is the default MPM with Apache 2.0 and 2.2. For information on why, read the related FAQ entry on using Apache2 with a threaded MPM

http://www.php.net/manual/en/install.unix.apache2.php

So I suspect that's where the issue is.

share|improve this answer
    
Hi Rob, though you're correct that PHP should not be used with mpm_worker since it's not thread safe, this technically would cause other problems ( for instance PHP locale settings modified under 1 process, affect them all cringe ). But it would seem fairly strange to me if it prevented the Apache process from quitting at the end of it's lifetime. –  delerious010 Sep 8 '10 at 12:35

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.