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 notice Apache is running multiple processes on my LAMP server (ubuntu 10.10). I'm just running a Wordpress site with MySQL as a database. It seems like www-data is running apache2 more than it should (using too much memory too), am I correct:

ID      Owner       Size        Command   
31200   www-data    251236 kB   /usr/sbin/apache2 -k start
20678   www-data    250948 kB   /usr/sbin/apache2 -k start
25781   www-data    248888 kB   /usr/sbin/apache2 -k start
31045   www-data    248844 kB   /usr/sbin/apache2 -k start
19926   www-data    246480 kB   /usr/sbin/apache2 -k start
20749   www-data    239380 kB   /usr/sbin/apache2 -k start
32616   www-data    238632 kB   /usr/sbin/apache2 -k start
8846    mysql   238128 kB   /usr/sbin/mysqld
24178   www-data    234228 kB   /usr/sbin/apache2 -k start
32618   www-data    232344 kB   /usr/sbin/apache2 -k start
32615   www-data    232204 kB   /usr/sbin/apache2 -k start
19805   root    208156 kB   /usr/sbin/apache2 -k start
share|improve this question
    
This was the same case on my previous job too(CentOS). I just assumed they were all child processes apache starts for each request.We never faced performance/memory issues due to this though... –  Anand Jeyahar May 14 '11 at 5:33
    
Hmm. I'm just worried about running out of memory on this system since it's a VPS. –  Trent Scott May 14 '11 at 5:38

3 Answers 3

up vote 14 down vote accepted

Apache is running multiple processes to have them ready when a client request comes in. Spawning a server process is slow, so it's best to have one waiting for a client.

For memory usage, you should take into the account RES size (as displayed by top), which is the amount of physical memory used by the task.

Why do you think you have too many apache2 processes using too much memory? What do you expect? Why do you expect so?

share|improve this answer
    
This is on a Cloud-based image. It just seems like it's using more memory than it should for such a small site. Real memory: 496.36 MB total / 92.02 MB free Swap space: 1024 MB total / 975.93 MB free –  Trent Scott May 14 '11 at 5:36
1  
@Trenton: With pawel's answer that sounds fine. Unless you actually run into a mysql crash or something due to lack of memory, you should be fine. If it happens, then you should look for apache configurations to limit these spawned processes. –  Anand Jeyahar May 14 '11 at 5:45
    
Cool thank you :) –  Trent Scott May 14 '11 at 5:52
1  
Linux will try to keep most of the memory used. If there's nothing else to put in it, it will use RAM for cache and disk buffers. Empty memory is wasted memory (if you aren't running out of RAM). –  Paweł Brodacki May 14 '11 at 7:05

As the answer by Pawel explains, apache uses a process per request model with a process pool (or thread per request with mpm_worker).

You might be able to reduce the memory usage by using a web server based on non-blocking IO, such as nginx. That way the server doesn't need to dedicate a process/thread per connection.

share|improve this answer
    
Thanks, I'll look into it. –  Trent Scott May 16 '11 at 23:32

Apache will run as many processes as you configure it to. The configuration differs if you are using the prefork or worker multi-processing modules.

share|improve this answer

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.